【发布时间】:2017-03-10 01:49:27
【问题描述】:
您好,我刚开始使用测试驱动开发。我有一个代码,其中有两个测试用例
[Test, Order(3)]
public void Should_Not_Create_ServiceAccountTaxCode_If_BillType_Is_Not_RateReady()
{
//ARRANGE
var customerDetailsViewForBillTYpeRateReady = new CustomerTaxDetailsView
{
BillType = (int)BillTypes.BillReady
};
_repository.Stub(x => x.GetCustomerDetailsForTaxes(Arg<int>.Is.Anything)).Return(dict.Dequeue());
//ACT
var result = _concern.PopulateServiceAccountWithTaxDetails(Arg<int>.Is.Anything);
[Test, Order(4)]
public void Should_Create_ServiceAccountTaxCode_If_BillType_Is_RateReady()
{
//ARRANGE
const int serviceAccountId = 1;
var customerDetailsView = new CustomerTaxDetailsView
{
BillType = (int)BillTypes.RateReady,
ServiceTypeId = (int)ServiceTypes.Electric
};
_repository.Stub(x => x.GetCustomerDetailsForTaxes(serviceAccountId))
.Return(customerDetailsView).Repeat.Once();
var result = _concern.PopulateServiceAccountWithTaxDetails(serviceAccountId);
我在
中使用以下语法生成模拟 [OneTimeSetUp]
public void Initialize()
{
_repository = MockRepository.GenerateMock<IServiceAccountTaxCodeRepository>();
唯一的问题是,在第二个测试用例中,我的结果对象也是来自第一个测试用例的 customerDetailsViewForBillTYpeRateReady。为什么会发生这种情况。如果我独立运行这些测试,那么一切都会通过。任何帮助将不胜感激..
【问题讨论】:
-
dict.dequeue 实际上将 customerDetailsViewForBillTYpeRateReady 对象出列。
标签: c# asp.net nunit moq rhino-mocks