public async Task ReturnsCreatedWhenModelStateValid() { var file = new FormFile(Stream.Null, 0, 10, "Test", "Test"); var createModelResult = new CreateModelResult <IFormFile>(file) { ImageId = Guid.NewGuid() }; _imageRepository .SaveImageAsync(file) .Returns(createModelResult); var result = await _controller.Post(file); await _imageRepository.Received(1).SaveImageAsync(Arg.Is <FormFile>(c => c.Name == file.Name)); result.Should().BeOfType <CreatedAtActionResult>().Which .Should().BeEquivalentTo(new { ActionName = nameof(ImagesController.Get), RouteValues = new RouteValueDictionary { { "imageId", createModelResult.ImageId } }, Value = file }, o => o.ExcludingMissingMembers()); }
public async Task ReturnsNotFoundWhenUpdateFails() { var file = new FormFile(Stream.Null, 0, 0, "Bad Test", "Bad Test"); var createModelResult = new CreateModelResult <IFormFile>(ResultStatus.Failed, "Update Failed"); _imageRepository .SaveImageAsync(Arg.Any <FormFile>(), Arg.Any <Guid>()) .Returns(createModelResult); var result = await _controller.Put(Guid.NewGuid(), file); result.Should().BeOfType <NotFoundObjectResult>().Which.Value .Should().Be(createModelResult.Reason); }
public async Task ReturnsBadRequestWhenModelStateIsInvalid() { var file = new FormFile(Stream.Null, 0, 0, "Bad Test", "Bad Test"); var createModelResult = new CreateModelResult <IFormFile>(ResultStatus.Failed, "Image is bad"); _imageRepository .SaveImageAsync(file) .Returns(createModelResult); var result = await _controller.Post(file); result.Should().BeOfType <BadRequestObjectResult>().Which.Value .Should().Be(createModelResult.Reason); }
public async Task ReturnsNoContentWhenUpdateSuccessful() { var imageId = Guid.NewGuid(); var file = new FormFile(Stream.Null, 0, 10, "Test", "Test"); var createModelResult = new CreateModelResult <IFormFile>(file) { ImageId = imageId }; _imageRepository .SaveImageAsync(Arg.Is <FormFile>(c => c.Name == file.Name && c.FileName == file.FileName), Arg.Is(imageId)) .Returns(createModelResult); var result = await _controller.Put(imageId, file); await _imageRepository.Received(1).SaveImageAsync(Arg.Any <FormFile>(), Arg.Any <Guid>()); result.Should().BeOfType <NoContentResult>(); }