コード例 #1
0
ファイル: AddMovie.cs プロジェクト: vasil87/MoviesMVC
        public void CallGetMovieAndReturnChangedResultIfAlreadyExists()
        {
            //Arrange
            var guid      = Guid.NewGuid();
            var testMovie = new Movies()
            {
                Id = Guid.NewGuid()
            };
            var sut = new MoviesServiceForTest(movies.Object, genresRepo.Object, commentsRepo.Object, userRepo.Object, likesRepo.Object, dislikesRepo.Object, saver.Object);

            sut.MovieToReturn = new Movies();

            //Act
            var result = sut.AddMovie(testMovie);

            //Assert
            Assert.AreEqual(result.ErrorMsg, "Already Exists");
            Assert.AreEqual(result.ResulType, ResultType.AlreadyExists);
            Assert.AreEqual(sut.GetMovieCount, 1);
        }
コード例 #2
0
ファイル: AddMovie.cs プロジェクト: vasil87/MoviesMVC
        public void MovieDoesntExistCallGenresRespoAllAndSaveChange()
        {
            //Arrange
            var called = 0;
            var guid   = Guid.NewGuid();
            var genre  = new Genres()
            {
                Name = "Test"
            };
            var genre2 = new Genres()
            {
                Name = "Test2"
            };
            var genres = new List <Genres>();

            genres.Add(genre);
            genres.Add(genre2);
            var testMovie = new Movies()
            {
                Genres = genres
            };
            var genresInDataBase = new List <Genres>();

            genresInDataBase.Add(genre);
            genresRepo.Setup(x => x.All()).Returns(genresInDataBase.AsQueryable());
            movies.Setup(x => x.Add(It.IsAny <Movies>())).Callback(() => { called++; });
            var sut = new MoviesServiceForTest(movies.Object, genresRepo.Object, commentsRepo.Object, userRepo.Object, likesRepo.Object, dislikesRepo.Object, saver.Object);

            sut.MovieToReturn = (Movies)null;

            //Act
            var result = sut.AddMovie(testMovie);

            //Assert
            Assert.AreEqual(called, 1);
            genresRepo.Verify(x => x.All(), Times.Exactly(2));
            Assert.AreEqual(result.ErrorMsg, "Saved");
            Assert.AreEqual(result.ResulType, ResultType.Success);
            Assert.AreEqual(sut.GetMovieCount, 1);
        }