我有这个方法:
Hi , I have this method :
public static IEnumerable<W_H59MpxSessionFrais> ListeSessionFrais(MpxFraisContext db, int siteID, int stval, string codeFrais) { var sessionfrais = (from D1 in db.H59_MpxSessionFrais where D1.CodeFrais == codeFrais && D1.SiteId == siteID && D1.StatusValidation == stval select new W_H59MpxSessionFrais { ID = D1.SessionFraisId, LibelleSession = D1.LibelleSession, DateDebutSession = D1.DateDebutSession, DateFinSession = D1.DateFinSession }); return sessionfrais.ToList(); }我想和Nunit一起测试,但我不知道如何在类测试中将值填充到MpxFraisContext,如果有人有想法请告诉我如何做测试类知道我正在使用asp MVC 4,Razor和linq到实体
and i want to do test with Nunit but i don't know how to fill values to MpxFraisContext in the class test , if someone have an idea please tell me how to do the test class knowing that i'm working with asp MVC 4 ,Razor and linq to entities
推荐答案您可以使用数据库数据和模拟数据编写Unittest。如果你想创建一个模拟层,我建议你实现存储库模式和依赖注入。 下面的例子我用基本的ASP.NET演示了一个基本的单元测试不使用依赖注入的MVC Unitesting框架 You can write Unittest with both database data and Mock data. If you want to create a mock layer i recommend you implement the Repository Pattern and Dependency Injection. The below example i have demonstrate a basic unit test with basic ASP.NET MVC Unitesting framework without using Dependency Injection [TestClass] public class YourControllerTest { private readonly SettingsController _settingsController = null; public SettingsControllerTest() { _settingsController=new SettingsController(); } [TestMethod] public void ListeSessionFraisType_Of_IEnumerable_W_H59MpxSessionFrais() { var indexModel = _settingsController.ListeSessionFrais(); Assert.IsInstanceOfType(indexModel, typeof(IEnumerable<W_H59MpxSessionFrais>)); } }
不要将datacontext作为参数传递。请遵循存储库模式。它还将从代码中抽象出datacontext,并且可以单独测试业务逻辑(存储库)。你将从网上获得很多代码示例来获取存储库模式 希望这有帮助
Don't pass datacontext as a parameter. Please follow the Repository pattern.It will also abstract the datacontext away from the code and can test the business logic(Repositories) alone. You will get a lot code examples from the net for Repository Pattern Hope this helps
我正在使用Nunit而不是MS测试我想要测试此方法的类 i'm working with Nunit not MS test and i want to have test class for this method
更多推荐
如何在Nunit项目中进行测试
发布评论