public async Task Basic_Post_Get_Delete_Image() { using var stream = File.OpenRead("Assets/test.png"); var imageFile = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name)); var postResult = await _controller.PostImage(imageFile, "Media", "example_id"); Assert.IsType <CreatedAtActionResult>(postResult.Result); var createdResult = postResult.Result as CreatedAtActionResult; var createdImage = createdResult.Value as Image; var getResult = await _controller.GetImage(createdImage.Id); Assert.Equal(createdImage, getResult.Value); Assert.Equal(createdImage.ImageFile.Path, getResult.Value.ImageFile.Path); var deleteResult = await _controller.DeleteImage(createdImage.Id); Assert.Equal(createdImage, deleteResult.Value); getResult = await _controller.GetImage(createdImage.Id); Assert.Equal(Status.Deleted, getResult.Value.IsDeletedStatus); }
public void PostImage_ReturnsStoredImageLocation_WithValidImage() { // Arrange IFormFile validImageFile = MockImageFile(); // Act IActionResult response = _controller.PostImage(validImageFile, string.Empty); // Assert response.Should().BeAssignableTo <CreatedAtActionResult>(); var objectResult = (CreatedAtActionResult)response; // Needs to contain these keys so resource location is correct. objectResult.RouteValues.Keys.Should().Contain("imageName"); objectResult.RouteValues.Keys.Should().Contain("recipeName"); objectResult.ActionName.Should().Be(nameof(ImagesController.GetImage)); }
public void PostImageTest() { AzureToolkitContext context = GetAzureToolkitContext(); var controller = new ImagesController(context); var request = new ImagePostRequest() { URL = new Uri("https://azuretkstorageoleier.blob.core.windows.net/savedimages/D30DFA0F40F3410C282A831D55AF58D9792C225F.jpeg"), EncodingFormat = "jpg", Id = Guid.NewGuid().ToString() }; Task <IActionResult> task = controller.PostImage(request); task.Wait(); }
public async Task PostImageTest() { ImagePatchDTO newImage = new ImagePatchDTO() { Path = "profile", ByteImage = Convert.ToBase64String(DbContent[0].ByteImage), Type = Order.ProductType.FOLT, Active = true }; var ImageResult = await ImagesController.PostImage(newImage); var NewImage = db.GetDbContext().Images.Find(DbContent.Count + 1); Assert.IsNotNull(NewImage); Assert.AreEqual(NewImage.ImageId, DbContent.Count + 1); Assert.AreEqual(NewImage.Path, "profile"); Assert.AreEqual(NewImage.Type, Order.ProductType.FOLT); Assert.AreEqual(NewImage.Active, true); }