public void ShouldGetViewResultWhenAddImageGetMethodSucceeds()
        {
            // Arrange
            var client     = GetMockOfIImageGalleryHttpClient(HttpStatusCode.OK);
            var controller = new GalleryController(client.Object);

            // Act
            var result = controller.AddImage();

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Null(viewResult.Model);
        }
        public async void ShouldGetViewResultWhenAddImagePostMethodInvalidatePostedData()
        {
            // Arrange
            var client     = GetMockOfIImageGalleryHttpClient(HttpStatusCode.OK);
            var controller = new GalleryController(client.Object);

            controller.ModelState.AddModelError("Title", "Title is required");
            var addImageViewModel = new AddImageViewModel();

            // Action
            var response = await controller.AddImage(addImageViewModel);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(response);

            Assert.Null(viewResult.Model);
        }
        public async void ShouldGetExceptionWhenAddImagePostMethodFailed()
        {
            // Arrange
            var client            = GetMockOfIImageGalleryHttpClient(HttpStatusCode.BadRequest);
            var controller        = new GalleryController(client.Object);
            var addImageViewModel = new AddImageViewModel();

            addImageViewModel.Files.Add(await GetFormFileAsync());

            // Act
            var result = controller.AddImage(addImageViewModel);

            // Assert
            var exception = await Assert.ThrowsAsync <Exception>(() => result);

            Assert.Equal("A problem happend while calling the API: Because this client's handler always fails", exception.Message);
        }
        public async void ShouldGetRedirectToActionResultWhenAddImagePostMethodSucceeds()
        {
            // Arrange
            var client            = GetMockOfIImageGalleryHttpClient(HttpStatusCode.OK);
            var controller        = new GalleryController(client.Object);
            var addImageViewModel = new AddImageViewModel
            {
                Title = "New Image Title",
            };

            addImageViewModel.Files.Add(await GetFormFileAsync());

            // Action
            var response = await controller.AddImage(addImageViewModel);

            // Assert
            var result = Assert.IsType <RedirectToActionResult>(response);

            Assert.Equal("Index", result.ActionName);
        }