public void GivenIdShoudReturnEntity() { DeviceType dt = new DeviceType() { Id = 0, Type = "Pression" }; var mockContext = new Mock <UserDataContext>(); mockContext.Setup(c => c.DeviceType.Find(0)).Returns(dt); var dao = new DeviceTypeDAO(mockContext.Object); var result = dao.Get(0); Assert.AreEqual(dt, result); }
public void GivenIdShouldRemoveFromDb() { DeviceType dt = new DeviceType() { Id = 0, Type = "Test" }; var mockContext = new Mock <UserDataContext>(); mockContext.Setup(c => c.DeviceType.Find(0)).Returns(dt); var dao = new DeviceTypeDAO(mockContext.Object); dao.Remove(0); mockContext.Verify(m => m.DeviceType.Remove(It.IsAny <DeviceType>()), Times.Once()); }
public void GivenNewEntityShouldAddInDb() { var data = new List <DeviceType>().AsQueryable(); var mockContext = new Mock <UserDataContext>(); var mockSet = SetupDbSet(data); mockContext.Setup(c => c.DeviceType).Returns(mockSet.Object); var dao = new DeviceTypeDAO(mockContext.Object); dao.Add(new DeviceType() { Id = 0, Type = "Pression" }); mockSet.Verify(m => m.Add(It.IsAny <DeviceType>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
public void GivenModifiedEntityShouldUpdateInDbAndReturnUpdatedEntity() { DeviceType dt = new DeviceType() { Id = 0, Type = "OriginalValue", Unit = "Test" }; var mockContext = new Mock <UserDataContext>(); mockContext.Setup(c => c.DeviceType.Find(0)).Returns(dt); var dao = new DeviceTypeDAO(mockContext.Object); var result = dao.Update(new DeviceType() { Id = 0, Type = "NewValue", Unit = "NewTest" }); Assert.AreEqual("NewValue", result.Type); Assert.AreEqual("NewTest", result.Unit); Assert.AreEqual(0, result.Id); }
public void ShouldReturnAllDeviceType() { var data = new List <DeviceType> { new DeviceType() { Id = 0, Type = "Pression" }, new DeviceType() { Id = 1, Type = "Tpt" } }.AsQueryable(); var mockContext = new Mock <UserDataContext>(); var mockSet = SetupDbSet(data); mockContext.Setup(c => c.DeviceType).Returns(mockSet.Object); var dao = new DeviceTypeDAO(mockContext.Object); var results = dao.All(); Assert.AreEqual(2, results.Count); }
public void GivenExistingDeviceTypeShouldThrowException() { var data = new List <DeviceType> { new DeviceType() { Id = 12, Type = "Pression" } }.AsQueryable(); var mockContext = new Mock <UserDataContext>(); var mockSet = SetupDbSet(data); mockContext.Setup(c => c.DeviceType).Returns(mockSet.Object); var dao = new DeviceTypeDAO(mockContext.Object); var ex = Assert.Throws <Exception>(() => dao.Add(new DeviceType() { Id = 0, Type = "Pression" })); Assert.AreEqual("DeviceType.Type already exists.", ex.Message); }