Esempio n. 1
0
        public void ShouldThrowDuringUpdateIfEntityDoesNotExist()
        {
            var mock = new Mock<IAdRepository>();
            mock.Setup(c => c.Update(It.IsAny<Ad>(), It.IsAny<int>())).Returns((Ad)null);
            mock.Setup(c => c.Get(It.IsAny<int>())).Returns((Ad)null);

            var controller = new AdsController(mock.Object);

            controller.Put(1, new Ad());
        }
Esempio n. 2
0
        public void CanCallUpdate()
        {
            var ad = new Ad()
            {
                Id = 30,
                Name = "30",
                Description = "30"
            };

            var mock = new Mock<IAdRepository>();
            mock.Setup(c => c.Update(It.IsAny<Ad>(), It.IsAny<int>())).Returns<Ad>(null);
            mock.Setup(c => c.Get(It.IsAny<int>())).Returns(ad);
            var controller = new AdsController(mock.Object);

            controller.Put(ad.Id, ad);

            mock.Verify(repo => repo.Update(It.IsAny<Ad>(), It.IsAny<int>()), Times.AtLeastOnce());
        }