我已经建立了一个服务如下:如何使用起订量来模拟和测试IService
public interface IMyService
{
void AddCountry(string countryName);
}
public class MyService : IMyService
{
public void AddCountry(string countryName)
{
/* Code here that access repository and checks if country exists or not.
If exist, throw error or just execute. */
}
}
test.cs中
[TestFixture]
public class MyServiceTest
{
[Test]
public void Country_Can_Be_Added()
{ }
[Test]
public void Duplicate_Country_Can_Not_Be_Added()
{ }
}
如何测试AddCountry
和MOQ库或服务。我真的不确定在这里做什么或嘲笑什么。有人可以帮我吗?
框架我使用:
- NUnit的
- 起订量
- ASP.NET MVC
我想我不得不嘲笑仓库。 – 2010-12-17 18:02:50
@Shawn Mclean - 你也可以将它存根。我认为我已经看到了比嘲笑的库更为残酷的库测试。 – jfar 2010-12-17 18:15:24
我建议使用Assert.Throws而不是ExpectedException。 – TrueWill 2010-12-17 18:25:10