【发布时间】:2014-03-04 07:38:44
【问题描述】:
我正在为基于 mvc 的项目设计架构。为了更好的方法,我想使用 TDD(使用 NUnit 框架)模式。我在项目中有闲置层。
- MVC 项目
- 应用服务层。
- 域服务层
- 基础设施层
函数调用的执行方式与层编号相同。 我想使用来自“应用程序服务层”的 TDD 概念(不是来自 MVC 的控制器)。 首先告诉我从 MVC 以外的层使用 TDD 是正确的方法。其次我很困惑,如果我采用这种方式,我将如何调用应用层函数进行 crud 操作,因为应用层函数具有内部为 crud 操作调用域服务层函数。我尝试通过创建其类对象来直接调用应用程序层函数,但它给出了对象引用未设置为对象实例的错误。
我的代码是
using ApplicationServices.AppServiceInterfaces;
using ApplicationServices.AppServiceClasses;
using PeocitEntities.MasterEntities;
namespace MyUnitTest
{
[TestFixture]
public class Account_Group
{
AccountGroupApplnService accApplicationServiceObject;
[TestFixtureSetUp]
public void SetupTest()
{
accApplicationServiceObject = new AccountGroupApplnService();//Here iam getting error
}
[Test]
public void AddAccountGroup()
{
AccountGroup accountGroupObj = new AccountGroup();
accountGroupObj.strName = "Test TDD Group";
accountGroupObj.intGroupType = 10;
accountGroupObj.groupType_name = Enum.GetName(typeof(EnumTypelib.glAccountGroupTypes), accountGroupObj.intGroupType);
accountGroupObj.intPrimaryGroup = (int)EnumTypelib.PrimaryGroupType.as_liabilities;
bool IsGroupAccountCreated = accApplicationServiceObject.CreateAccountGroup(accountGroupObj);//Internally calls service & then infra layer.
Assert.True(IsGroupAccountCreated);
}
[TestFixtureTearDown]
public void TearDownTest()
{
accApplicationServiceObject = null;
}
}
}
我的问题是如何将 TDD(with Nunit) 用于具有多层的应用程序?
【问题讨论】:
标签: c# model-view-controller tdd nunit