public async Task SaveDataset_GivenViewModelIsNotNullButResponseContainsModelErrors_ReturnsBadRequest()
        {
            // Arrange
            ValidatedApiResponse <NewDatasetVersionResponseModel> response = new ValidatedApiResponse <NewDatasetVersionResponseModel>(HttpStatusCode.BadRequest);

            response.ModelState = new Dictionary <string, IEnumerable <string> >
            {
                { "Name", new [] { "Invalid name" } }
            };

            CreateDatasetViewModel viewModel = new CreateDatasetViewModel();

            IDatasetsApiClient apiClient = CreateApiClient();

            apiClient
            .CreateDataset(Arg.Any <CreateNewDatasetModel>())
            .Returns(response);

            ILogger logger = CreateLogger();

            DatasetController controller = CreateController(apiClient, logger);

            // Act
            IActionResult result = await controller.SaveDataset(viewModel);

            // Assert
            logger
            .Received(1)
            .Warning(Arg.Is("Invalid model provided"));

            result
            .Should()
            .BeOfType <BadRequestObjectResult>();
        }
        public void SaveDataset_GivenViewModelIsNull_ThowsArgumentNullException()
        {
            // Arrange
            CreateDatasetViewModel viewModel = null;

            DatasetController controller = CreateController();

            // Act
            Func <Task> test = async() => await controller.SaveDataset(viewModel);

            // Assert
            test
            .Should()
            .ThrowExactly <ArgumentNullException>();
        }
        public async Task SaveDataset_GivenResponseIsSuccess_ReturnsSuccess()
        {
            // Arrange
            NewDatasetVersionResponseModel responseModel = new NewDatasetVersionResponseModel
            {
                DatasetId = "dataset-id"
            };

            ValidatedApiResponse <NewDatasetVersionResponseModel> response = new ValidatedApiResponse <NewDatasetVersionResponseModel>(HttpStatusCode.OK, responseModel);

            CreateDatasetViewModel viewModel = new CreateDatasetViewModel();

            IDatasetsApiClient apiClient = CreateApiClient();

            apiClient
            .CreateDataset(Arg.Any <CreateNewDatasetModel>())
            .Returns(response);

            ILogger logger = CreateLogger();

            DatasetController controller = CreateController(apiClient, logger);

            // Act
            IActionResult result = await controller.SaveDataset(viewModel);

            // Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();

            OkObjectResult objectResult = result as OkObjectResult;

            NewDatasetVersionResponseModel content = objectResult.Value as NewDatasetVersionResponseModel;

            content
            .DatasetId
            .Should()
            .Be("dataset-id");
        }
        public async Task SaveDataset_GivenResponseIsInternalServerError_ReturnsStatusCode500()
        {
            // Arrange
            ValidatedApiResponse <NewDatasetVersionResponseModel> response = new ValidatedApiResponse <NewDatasetVersionResponseModel>(HttpStatusCode.InternalServerError);

            CreateDatasetViewModel viewModel = new CreateDatasetViewModel();

            IDatasetsApiClient apiClient = CreateApiClient();

            apiClient
            .CreateDataset(Arg.Any <CreateNewDatasetModel>())
            .Returns(response);

            ILogger logger = CreateLogger();

            DatasetController controller = CreateController(apiClient, logger);

            // Act
            IActionResult result = await controller.SaveDataset(viewModel);

            // Assert
            logger
            .Received(1)
            .Error(Arg.Is($"Error when posting data set with status code: 500"));

            result
            .Should()
            .BeOfType <StatusCodeResult>();

            StatusCodeResult statusCodeResult = result as StatusCodeResult;

            statusCodeResult
            .StatusCode
            .Should()
            .Be(500);
        }