public void AddNominationInCategory_ShouldCallCategoryRepositoryMockAndMovieRepositoryMockOnce_WhenTheMovieIsNotInTheDB()
        {
            var categoryRepositoryMock = MockRepository.GenerateMock <ICategoryRepository>();
            var movieRepositoryMock    = MockRepository.GenerateMock <IMovieRepository>();

            //Arrange
            Movie movie = new Movie {
                Id = 1
            };
            var movieCredit = new List <string>()
            {
                "1"
            };

            movieRepositoryMock.Expect(dao => dao.HasMovie(1)).Return(false);
            movieRepositoryMock.Expect(dao => dao.AddMovie(movie)).Repeat.Once();
            categoryRepositoryMock.Expect(dao => dao.AddNomination(1, 1, movieCredit)).Repeat.Once();

            var categoryService = new CategoryService(categoryRepositoryMock, movieRepositoryMock);

            //Act
            categoryService.AddMovieInCategory(1, movie, movieCredit);

            //Assert
            movieRepositoryMock.VerifyAllExpectations();
            categoryRepositoryMock.VerifyAllExpectations();
        }
Пример #2
0
        public void AddMovieInCategory_ShouldNotCallCategoryRepositoryMockAndMovieRepositoryMock_WhenTheMovieIsInTheDB()
        {
            var categoryRepositoryMock = MockRepository.GenerateMock <ICategoryRepository>();
            var movieRepositoryMock    = MockRepository.GenerateMock <IMovieRepository>();

            //Arrange
            Movie movie = new Movie {
                Id = 1
            };

            movieRepositoryMock.Expect(dao => dao.HasMovie(1)).Return(true);
            movieRepositoryMock.Expect(dao => dao.AddMovie(movie)).Repeat.Never();
            movieRepositoryMock.Expect(dao => dao.OverrideMovie(movie)).Repeat.Once();
            categoryRepositoryMock.Expect(dao => dao.AddNomination(Arg <int> .Is.Equal(1), Arg <int> .Is.Equal(1), Arg <List <string> > .Matches(x => x.Count == 0))).Repeat.Once();

            var unitOfWorkMockMock = MockRepository.GenerateStub <IUnitOfWork>();

            unitOfWorkMockMock.Stub(uow => uow.CategoryRepository).Return(categoryRepositoryMock);
            unitOfWorkMockMock.Stub(uow => uow.MovieRepository).Return(movieRepositoryMock);

            var categoryService = new CategoryService(unitOfWorkMockMock);

            //Act
            categoryService.AddMovieInCategory(1, movie, null);

            //Assert
            movieRepositoryMock.VerifyAllExpectations();
            categoryRepositoryMock.VerifyAllExpectations();
        }
Пример #3
0
        public void AddMovieInCategory_ShouldCallOnlyCategoryRepositoryMock_WhenTheMovieIsInTheDBButNotForThisCategory()
        {
            var categoryRepositoryMock = MockRepository.GenerateMock <ICategoryRepository>();
            var movieRepositoryMock    = MockRepository.GenerateMock <IMovieRepository>();

            //Arrange
            Movie movie = new Movie {
                Id = 1
            };

            movieRepositoryMock.Expect(dao => dao.HasMovie(1)).Return(true);
            categoryRepositoryMock.Expect(dao => dao.HasMovieInCategory(1, 1)).Return(false);
            movieRepositoryMock.Expect(dao => dao.AddMovie(movie)).Repeat.Never();
            categoryRepositoryMock.Expect(dao => dao.AddMovie(1, 1)).Repeat.Once();

            var categoryService = new CategoryService(categoryRepositoryMock, movieRepositoryMock);

            //Act
            categoryService.AddMovieInCategory(1, movie);

            //Assert
            movieRepositoryMock.VerifyAllExpectations();
            categoryRepositoryMock.VerifyAllExpectations();
        }