Example #1
0
 public void Post_Staff_Object_To_DB()
 {
     var mockSet = new Mock<DbSet<staff>>();
     var mockContext = new Mock<StaffAppContext>();
     mockContext.Setup(m => m.staffs).Returns(mockSet.Object);
     var member = new staff
                 {
                     Email = "*****@*****.**",
                     FirstName = "Andy",
                     ID = 4,
                     LastName = "Nicoll"
                 };
     var staffRepo = new staffDAO(mockContext.Object);
     staffRepo.Post(member);
     mockSet.Verify(m => m.Add(It.IsAny<staff>()), Times.Once());
     mockContext.Verify(m => m.SaveChanges(), Times.Once());
 }
Example #2
0
        public void Put_Staff_Object_To_DB()
        {
            var data = new List<staff>{
            new staff
            {
                Email = "*****@*****.**",
                FirstName = "Andy",
                ID = 4,
                LastName = "Nicoll"
            },
            new staff{
                Email = "*****@*****.**",
                FirstName = "Asdndy",
                ID = 44,
                LastName = "Nidcoll"
            }
            }.AsQueryable();

            var mockSet = new Mock<DbSet<staff>>();
            mockSet.As<IQueryable<staff>>().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As<IQueryable<staff>>().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As<IQueryable<staff>>().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As<IQueryable<staff>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock<StaffAppContext>();
            mockContext.Setup(m => m.staffs).Returns(mockSet.Object);

            var singleStaff = new staff
            {
                Email = "*****@*****.**",
                FirstName = "Andy",
                ID = 4,
                LastName = "Nicoll"
            };

            var service = new staffDAO(mockContext.Object);
            service.Put(singleStaff);

            Assert.AreEqual("Nicoll", singleStaff.LastName);
            Assert.AreEqual("*****@*****.**", singleStaff.Email);
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }