Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm able to create mock objects and do a update test with mocked entities successfully.
But the issue is with create test. Here is my sample code.
In this always my testPG is null and so the test fails

base class:
C#
public class TestContext where T : class
   {

       protected Mock<t> mockRepository;
       protected Mock<testentities> mockTestEntities;

       protected TestContext()
       {
           mockRepository = new Mock<t>(MockBehavior.Strict);
           mockTestEntities= new Mock<testentities>(MockBehavior.Strict);
           mockTestEntities.Setup(ase => ase.SaveChanges()).Returns(1);
      }


public class PGRepositoryTest : TestContext<ipgrepository>
    {


 [TestInitialize]
        public void TestInitialize()
        {
            pgRepository = new PGRepository(mockTestEntities.Object);
                
          pgViewModel = new PGViewModel
                                {   ID = 1,
                                    Name = "PG Unit Test",
                                    DisplayName = "PG Unit Test",
                                    IsActive = true,                                    
                                };
            sessionViewModel = pgViewModel;

            userContext = new UserContext
                                {
                                    UserID = "XXXX"
                                };
}


 [TestMethod]
        public void CreateTest()
        {
            
            var IdSet = new IDSet();
            
            IdSet = pgRepository.Create(pgViewModel, sessionViewModel, userContext);
            
            PresentationGroupViewModel testPG = pgRepository.GetPresentationGroup(IdSet.ID);              

              Assert.AreEqual(IdSet.ID, testPG.ID);

        }
}</ipgrepository></testentities></t></testentities></t>
Posted
Updated 29-May-14 3:16am
v4

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