コード例 #1
0
        public void ShouldDeleteAPicture()
        {
            var id = Guid.NewGuid();

            var mockPictureRepository = new Mock <IPictureRepository>();

            mockPictureRepository.Setup(r => r.Get(id)).Returns(() =>
            {
                return(new Picture()
                {
                    Tags = "tag1,tag2"
                });
            });

            var mockTagRepository = new Mock <ITagRepository>();

            var pictureController = new PicturesController(mockPictureRepository.Object, mockTagRepository.Object);

            pictureController.Delete(id);

            mockPictureRepository.Verify(r => r.Get(id), Times.Once());
            mockPictureRepository.Verify(r => r.Delete(id), Times.Once());
            mockTagRepository.Verify(r => r.DecrementPictureCount("tag1"), Times.Once());
            mockTagRepository.Verify(r => r.DecrementPictureCount("tag2"), Times.Once());
            mockTagRepository.Verify(r => r.DecrementPictureCount(It.IsAny <string>()), Times.Exactly(2));
        }