Согласно моему предыдущему вопросу: Rhino Mocks - слой репозитория тестирования возвращает ошибку "объект не установлен в экземпляр" ошибка
У меня проблема при прохождении теста NUnit, когдаВыполните в сочетании с другими тестами в наборе.
Весь класс теста выглядит следующим образом:
using System;
using System.Linq;
using System.Linq.Expressions;
using NUnit.Framework;
using System.Collections.Generic;
using Rhino.Mocks;
using Assert = NUnit.Framework.Assert;
Tests.DAO
{
/// <summary>
/// Uses the 3A method of Unit Testing; Arrange, Act, Assert.
///
/// Tests the Billing DAO
/// </summary>
[TestFixture]
public class BillingTests
{
private IDataContextWrapper _dataContext;
private Repository _intRepository;
/// <summary>
/// Sets up the following constructs for testing.
///
/// - DataContext
/// - InternalRepository
/// - Billing
/// </summary>
[TestFixtureSetUp]
public void TestFixtureSetup()
{
_dataContext = MockRepository.GenerateMock<IDataContextWrapper>();
}
/// <summary>
///
/// </summary>
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
_dataContext.Dispose();
}
/// <summary>
/// Tests adding a Billing object to the Database.
/// </summary>
[Test]
public void Add()
{
// Arrange
var billing = new Billing();
_intRepository = new Repository(_dataContext);
// Act
_intRepository.AddRecord(billing);
// Assert
_dataContext.AssertWasCalled(x => x.InsertOnSubmit(billing));
_dataContext.AssertWasCalled(x => x.SubmitChanges());
}
/// <summary>
/// The test attempts to remove the Billing before asserting that it no-longer
/// exists in the database by attempting to delete it again.
/// </summary>
[Test]
public void Delete()
{
// Arrange
var billing = new Billing();
_intRepository = new Repository(_dataContext);
// Arrange
_intRepository.DeleteRecord(billing);
// Assert
_dataContext.AssertWasCalled(x => x.DeleteOnSubmit(billing));
_dataContext.AssertWasCalled(x => x.SubmitChanges());
}
/// <summary>
/// The test retrieves the Billing from
/// the database and asserts that
/// the original Billing and
/// the one retrieved are the same.
/// </summary>
[Test]
public void GetRecordWhere()
{
// Arrange
var list = new List<Billing> {new Billing {BillingId = 1}};
const int testId = 1;
_dataContext.Stub(x => x.GetTable<Billing>()).Return(list.AsQueryable());
_intRepository = new Repository(_dataContext);
// Act
var result = _intRepository.GetRecordWhere<Billing>(x => x.BillingId == testId);
// Assert
Assert.IsNotNull(result);
Assert.AreEqual(result.BillingId, testId);
_dataContext.AssertWasCalled(x => x.GetTable<Billing>());
}
/// <summary>
///
/// </summary>
[Test]
public void GetAllRecordsWhere()
{
}
/// <summary>
/// Retrieves the total number of Billings in the database
/// and compares it against how many were added by the testFixture.
/// </summary>
[Test]
public void GetAllBillings()
{
// Arrange
_dataContext.Stub(x => x.GetTable<Billing>()).Return(new List<Billing> { new Billing { BillingId = 1 } }.AsQueryable());
_intRepository = new Repository(_dataContext);
// Act
var result = _intRepository.GetAllRecords<Billing>();
// Assert
Assert.AreEqual(typeof(EnumerableQuery<Billing>), result.GetType());
_dataContext.AssertWasCalled(x => x.GetTable<Billing>());
}
/// <summary>
/// Tests find all Billings. Expects the return type to be of IQeryable
/// </summary>
[Test]
public void FindAllBillings()
{
// Arrange
_dataContext.Stub(x => x.GetTable<Billing>()).Return(new List<Billing>().AsQueryable());
_intRepository = new Repository(_dataContext);
// Act
var result = _intRepository.FindAll<Billing>();
// Assert
Assert.IsNotNull(result);
Assert.AreEqual(typeof(EnumerableQuery<Billing>), result.GetType());
}
}
}
Тест, который сейчас исправлен (или, скорее, мое понимание было исправлено)проходит, когда работает сам по себе.Но не когда тесты запускаются вместе?Я что-то упускаю в функциях SetUp / TearDown NUnit?Сохраняется ли dataContext или Repository там, где я хочу, чтобы этого не было?
Спасибо за любую помощь!