Exemplo n.º 1
0
        public void UpdateWithValidObject_ReturnOk()
        {
            MockGenreService.Setup(r => r.Update(It.IsAny <GenreBO>())).Returns((GenreBO updatedGenre) => updatedGenre);

            var result  = _controller.Put(MockGenre.Id, MockGenre);
            var message = ResultMessageService.GetMessage(result);

            Assert.IsType <OkObjectResult>(result);
            Assert.Contains("Updated!", message);
        }
        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);
        }
Exemplo n.º 3
0
        public async Task UpdateGenre()
        {
            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 controller = new GenresController(context2, mapper);

            var genreCreationDTO = new GenreCreationDTO {
                Name = "New name"
            };

            var id       = 1;
            var response = await controller.Put(id, genreCreationDTO);

            var result = response as StatusCodeResult;

            Assert.AreEqual(204, result.StatusCode);

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

            Assert.IsTrue(exists);
        }
        public async Task ReplaceGenre_ValidId_ShouldReplaceGenre()
        {
            // Arrange
            var databaseName = Guid.NewGuid().ToString();

            BuildGenreTestDatabase(databaseName);
            var testDbContext   = BuildContext(databaseName);
            var verifyDbContext = BuildContext(databaseName);

            var mapper = BuildMapper();

            var expectedGenresCount = verifyDbContext.Genres.Count();
            var expectedName        = "New Genre Name";

            var createGenreDTO = new CreateGenreDTO()
            {
                Name = expectedName
            };

            var controller = new GenresController(testDbContext, mapper);

            // Act
            var response = await controller.Put(1, createGenreDTO);

            var result     = response as StatusCodeResult;
            var actualName = verifyDbContext.Genres.Find(1).Name;

            // Assert
            Assert.AreEqual(StatusCodes.Status204NoContent, result.StatusCode);
            Assert.AreEqual(expectedName, actualName);
        }
        public async Task ReplaceGenre_InvalidId_ShouldReturnNotFound()
        {
            // Arrange
            var databaseName = Guid.NewGuid().ToString();
            var dbContext    = BuildContext(databaseName);
            var mapper       = BuildMapper();

            var testGenresCount = dbContext.Genres.Count();
            var expectedName    = "New Genre Name";

            var createGenreDTO = new CreateGenreDTO()
            {
                Name = expectedName
            };

            var controller = new GenresController(dbContext, mapper);

            // Act
            var response = await controller.Put(testGenresCount + 1, createGenreDTO);

            var result = response as StatusCodeResult;

            // Assert
            Assert.AreEqual(StatusCodes.Status404NotFound, result.StatusCode);
        }
        public void ShouldCreateGenre()
        {
            var model = new CreateGenreModel
            {
                Name          = "Name",
                ParentGenreId = 1
            };

            _genreService.Setup(m => m.Create(It.IsAny <string>(), It.IsAny <int>()));

            HttpResponseMessage response = _genresController.Put(model);

            _genreService.Verify(m => m.Create(It.IsAny <string>(), It.IsAny <int>()), Times.AtLeastOnce);
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
        }