Replies: 2 comments 1 reply
-
What's the stack trace? You've posted no meaningful information. Can you please properly format your code samples also. I'm curious to why you're even mocking |
Beta Was this translation helpful? Give feedback.
-
I m mocking the Iformfile because when in the Jenkins pipeline we don't want to create any dependency on the actual file. I have updated the above code sample let me know if you need more information. I m using real image which is of PNG format "Image cannot be loaded. Available decoders:\r\n - JPEG : JpegDecoder\r\n - TGA : TgaDecoder\r\n - GIF : GifDecoder\r\n - PNG : PngDecoder\r\n - BMP : BmpDecoder\r\n" This is the stack trace at SixLabors.ImageSharp.Image.Load(Configuration configuration, Stream stream, IImageFormat& format) |
Beta Was this translation helpful? Give feedback.
-
HI
I m trying to moq IFormFile object for a unit test in .net core application but the moq always fails on this line SixLabors.ImageSharp.Image.Load(postedFile.OpenReadStream(), out SixLabors.ImageSharp.Formats.IImageFormat format)).
Tried everything Read real image
Created custom Byte
Always fails below is my moq code
public void CreateCompany_Success()
{
var formFile = new Mock();
var sourceImg = File.OpenRead(@"Assets\SampleIcon.png");
var ms = new MemoryStream();
var writer = new StreamWriter(ms);
writer.Write(sourceImg);
writer.Flush();
ms.Position = 0;
var fileName = "logo.png";
formFile.Setup(f => f.FileName).Returns(fileName).Verifiable();
formFile.Setup(_ => _.CopyToAsync(It.IsAny(), It.IsAny()))
.Returns((Stream stream, CancellationToken token) => ms.CopyToAsync(stream))
.Verifiable();
}
public bool CheckValidFileDimensionsLinux(this IFormFile postedFile, ImageDimension imageDimension = null)
{
try
{
using (var image = SixLabors.ImageSharp.Image.Load(postedFile.OpenReadStream(), out
SixLabors.ImageSharp.Formats.IImageFormat format))
{
if (imageDimension != null && !ValidDimensionsLinux(image, imageDimension))
{
return false;
}
}
}
catch (Exception ex)
{
return false;
}
finally
{
postedFile.OpenReadStream().Position = 0;
}
return true;
}
Beta Was this translation helpful? Give feedback.
All reactions