public async Task CreateGenre()
        {
            //Preparation
            var databaseName = Guid.NewGuid().ToString();
            var context      = BuildContext(databaseName);
            var mapper       = BuildMap();

            var newGenre = new GenreForCreationDto()
            {
                Name = "New Genre"
            };

            //Testing
            var controller = new GenresController(context, mapper);
            var response   = await controller.Post(newGenre);

            //Verification
            var result = response as CreatedAtRouteResult;

            Assert.AreEqual(201, result.StatusCode);

            var context2 = BuildContext(databaseName);
            var count    = await context2.Genres.CountAsync();

            Assert.AreEqual(1, count);
        }
        public async Task UpdateGenre()
        {
            //Preparation
            var databaseName = Guid.NewGuid().ToString();
            var context      = BuildContext(databaseName);
            var mapper       = BuildMap();

            context.Genres.Add(new Genre()
            {
                Name = "Genre 1"
            });
            context.SaveChanges();

            var context2            = BuildContext(databaseName);
            var genreForCreationDto = new GenreForCreationDto()
            {
                Name = "New Genre"
            };

            //Testing
            var id         = 1;
            var controller = new GenresController(context, mapper);
            var response   = await controller.Put(id, genreForCreationDto);

            //Verification
            var result = response as StatusCodeResult;

            Assert.AreEqual(204, result.StatusCode);

            var context3 = BuildContext(databaseName);
            var isExist  = await context3.Genres.AnyAsync(x => x.Name == "New Genre");

            Assert.IsTrue(isExist);
        }
Beispiel #3
0
        public async Task <IActionResult> AddGenre([FromBody] GenreForCreationDto genreForCreationDto)
        {
            if (genreForCreationDto == null)
            {
                return(BadRequest());
            }

            var genre = _mapper.Map <Genre>(genreForCreationDto);

            _repository.AddGenre(genre);
            await _unitOfWork.CompleteAsync();

            var genreToReturn = _mapper.Map <GenreDto>(genre);

            return(CreatedAtRoute("GetGenre", new { id = genreToReturn.Id }, genreToReturn));
        }
Beispiel #4
0
 public async Task <ActionResult> Put(int id, [FromBody] GenreForCreationDto genreForCreationDto)
 {
     return(await Put <GenreForCreationDto, Genre>(id, genreForCreationDto));
 }
Beispiel #5
0
 public async Task <ActionResult> Post([FromBody] GenreForCreationDto genreForCreationDto)
 {
     return(await Post <GenreForCreationDto, Genre, GenreDto>(genreForCreationDto, "GetGenre"));
 }