public void ConvertTo_returns_image_with_valid_size(string path, int desiredW, int desiredH) { var ext = path.Split('.', StringSplitOptions.RemoveEmptyEntries).Last(); var imgRepresentation = new AuctionImageRepresentation(new AuctionImageMetadata(ext), File.ReadAllBytes(path)); var size = new AuctionImageSize(desiredW, desiredH); var converted = service.ConvertTo(imgRepresentation, size); converted.Should().NotBeNull(); converted.Img.Length.Should().BeGreaterThan(0); converted.Metadata.Should().NotBeNull(); using (var img = Image.Load(converted.Img)) { img.Width.Should().BeLessOrEqualTo(desiredW); img.Height.Should().BeLessOrEqualTo(desiredH); img.Width.Should().BeGreaterThan(0); img.Height.Should().BeGreaterThan(0); } }
private void AddConvertedImage(string imageId, AuctionImageSize size, AuctionImageRepresentation imgRepresentation) { AuctionImageRepresentation converted = null; try { converted = _imageConverterService.ConvertTo(imgRepresentation, size); } catch (Exception ex) { throw new DomainException("Cannot convert image", ex); } try { _imageRepository.Add(imageId, converted); } catch (Exception ex) { throw new DomainException("Cannot add image", ex); } }