Exemple #1
0
        public void GetAll()
        {
            MockGenreService.Setup(r => r.GetAll()).Returns(new List <GenreBO>()
            {
                MockGenre
            });

            var result = _controller.Get();

            Assert.NotEmpty(result);
        }
        public async Task GetAllGenres()
        {
            //Preparation
            var databaseName = Guid.NewGuid().ToString();
            var context      = BuildContext(databaseName);
            var mapper       = BuildMap();

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

            var context2 = BuildContext(databaseName);

            //Testing
            var controller = new GenresController(context2, mapper);
            var response   = await controller.Get();

            //Verification
            var genres = response.Value;

            Assert.AreEqual(3, genres.Count);
        }
        public async Task GetGEnreByIdExist()
        {
            //Preparation
            var databaseName = Guid.NewGuid().ToString();
            var context      = BuildContext(databaseName);
            var mapper       = BuildMap();

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

            var context2 = BuildContext(databaseName);

            //Testing
            var controller = new GenresController(context2, mapper);
            var id         = 1;
            var response   = await controller.Get(id);

            //Verification
            var result = response.Value;

            Assert.AreEqual(id, result.Id);
        }
        public async Task Task_Get_WhenIdIsEmpty_ReturnsBadRequest()
        {
            //Arrange
            string id = string.Empty;
            var    mockGenreManager = new Mock <IGenreManager>();
            var    mockLogger       = new Mock <ILogger <GenresController> >();

            mockGenreManager.Setup(repo => repo.GetByIdAsync(id)).ReturnsAsync((GenreResponse)null);
            var controller = new GenresController(mockLogger.Object, mockGenreManager.Object);

            //Act
            var result = await controller.Get(id);

            //Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
        public async Task GetGenreByIdDoesNotExist()
        {
            //Preparation
            var databaseName = Guid.NewGuid().ToString();
            var context      = BuildContext(databaseName);
            var mapper       = BuildMap();

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

            //Verification
            var result = response.Result as StatusCodeResult;

            Assert.AreEqual(404, result.StatusCode);
        }
        public async Task GetGenreById_InvalidId_ShouldReturnNotFound()
        {
            // Arrange
            var databaseName = Guid.NewGuid().ToString();
            var dbContext    = BuildContext(databaseName);
            var mapper       = BuildMapper();

            var controller = new GenresController(dbContext, mapper);

            // Act
            var response = await controller.Get(1);

            var result = response.Result as StatusCodeResult;

            // Assert
            Assert.AreEqual(StatusCodes.Status404NotFound, result.StatusCode);
        }
        public async Task Task_Get_WhenIdIsNotEmpty_ReturnsOK()
        {
            //Arrange
            string id = Guid.NewGuid().ToString();
            var    mockGenreManager = new Mock <IGenreManager>();
            var    mockLogger       = new Mock <ILogger <GenresController> >();

            mockGenreManager.Setup(repo => repo.GetByIdAsync(id))
            .ReturnsAsync(new GenreResponse(new Core.Models.Genre {
                Name = "test", Description = "test", Id = id
            }));
            var controller = new GenresController(mockLogger.Object, mockGenreManager.Object);

            //Act
            var result = await controller.Get(id);

            //Assert
            Assert.IsType <OkObjectResult>(result);
        }
        public async Task GetAllGenres_ShouldReturnAllGenres()
        {
            // Arrange
            var databaseName = Guid.NewGuid().ToString();

            BuildGenreTestDatabase(databaseName);

            var dbContext = BuildContext(databaseName);
            var mapper    = BuildMapper();

            var controller = new GenresController(dbContext, mapper);

            // Act
            var response = await controller.Get();

            var genres = response.Value;

            // Assert
            Assert.AreEqual(2, genres.Count);
        }
        public async Task GetGenreById_ValidId_ShouldReturnGenre()
        {
            // Arrange
            var databaseName = Guid.NewGuid().ToString();

            BuildGenreTestDatabase(databaseName);

            var dbContext  = BuildContext(databaseName);
            var mapper     = BuildMapper();
            var expectedId = 1;

            var controller = new GenresController(dbContext, mapper);

            // Act
            var response = await controller.Get(expectedId);

            var actualId = response.Value.Id;

            // Assert
            Assert.AreEqual(expectedId, actualId);
        }
        public async Task Get_Calls_GetAllGenresAsync()
        {
            await _MoviesController.Get();

            await _Client.Received(1).GetAllGenresAsync();
        }