如何在Nunit项目中进行测试

如何在Nunit项目中进行测试

本文介绍了如何在Nunit项目中进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个方法:

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.net 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.net MVC 4 ,Razor and linq to entities

推荐答案

[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项目中进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 07:45