Esempio n. 1
0
        public void AddComment_ShouldAddCommentToPhotoAndCallUpdatePhoto()
        {
            _photoRepo = new Mock <IPhotoRepo>();
            _userRepo  = new Mock <IUserRepo>();
            _userRepo.Setup(c => c.Users).Returns(_users);
            var photo = new Photo()
            {
                Id = 1
            };
            var comment = new Comment()
            {
                Id = 1, UserId = "1"
            };
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "ImageAlbumDb")
                          .Options;

            using (var context = new AppDbContext(options))
            {
                _photoService = new PhotoService(context, _photoRepo.Object, _userRepo.Object);

                _photoService.AddComment(photo, comment);

                Assert.AreEqual(1, photo.Comments.Count());
                _photoRepo.Verify(c => c.UpdatePhoto(photo), Times.Once());
            }
        }