Click here to Skip to main content
15,891,745 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi , I have this method :
C#
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();
       }

and i want to do test with Nunit ,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
Posted

Where exactly are you stuck?
Possibly with the MpxFraisContext db parameter. Here you need a "mock". That is, an object of that type which contains some data or none (depending on the singular test). You may create such an object yourself, or use a "mocking framework", e.g. Moq.
A function could look like:
C#
[Test]
public void TestListeSessionFrais()
{
    MpxFraisContext db = [create and fill that object with useful data]
    int siteID = 1;
    int stval = 2;
    string codeFrais = "a";
    IEnumerable<w_h59mpxsessionfrais> retVal = [YourClass].ListeSessionFrais(db, siteID, stval, codeFrais);
    int expectedCount = 1;
    Assert.IsNotNull(retVal, "the function must return a value different from null");
    //... some more Asserts on the returned object, e.g. count, properties of first object in list,...
}</w_h59mpxsessionfrais>
 
Share this answer
 
how to use mock in test class ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900