コード例 #1
0
        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);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }