Example #1
0
        public void CreateGenre_ShouldCallInsertGenreOnceWhenEntity()
        {
            // Act
            _genreService.CreateGenre(_genre);

            // Assert
            _genreRepository.Verify(a => a.Insert(It.IsAny <Genre>()), Times.Once);
        }
        public async void AddGenreWorks()
        {
            // arrange
            var genreVM = new GenreViewModel {
                Name = "Genre"
            };

            // act
            await _genreService.CreateGenre(genreVM);

            var getGenres = await _genreService.GetGenres();

            // assert
            Assert.NotNull(getGenres);
            Assert.Equal("Genre", getGenres.First().Name);
        }
 public IHttpActionResult Post(GenreCreate model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     if (!_service.CreateGenre(model))
     {
         return(InternalServerError());
     }
     return(Ok("Genre created successfully!"));
 }
        public void CreateGenre_ShouldCallFactoryCreateGenreMethod_WhenValidParametersPassed()
        {
            var name = "Comedy";
            var genreRepositoryMock = new Mock <IRepository <Genre> >();
            var unitOfWorkMock      = new Mock <IUnitOfWork>();
            var genreFactoryMock    = new Mock <IGenreFactory>();
            var genreService        = new GenreService(
                genreRepositoryMock.Object, unitOfWorkMock.Object, genreFactoryMock.Object);

            genreService.CreateGenre(name);

            genreFactoryMock.Verify(f => f.CreateGenre(name), Times.Once);
        }
        public void CreateGenre_ShouldReturnCorrectGenre_WhenValidParametersPassed()
        {
            var name = "Comedy";
            var genreRepositoryMock = new Mock <IRepository <Genre> >();
            var unitOfWorkMock      = new Mock <IUnitOfWork>();
            var genreFactoryMock    = new Mock <IGenreFactory>();
            var genre = new Genre(name);

            genreFactoryMock.Setup(f => f.CreateGenre(name)).Returns(genre);
            var genreService = new GenreService(
                genreRepositoryMock.Object, unitOfWorkMock.Object, genreFactoryMock.Object);

            var returnedGenre = genreService.CreateGenre(name);

            Assert.AreSame(genre, returnedGenre);
        }