public void CreatePixelart_OptionsAreNull_ThrowsException() { var image = _fixture.Create <Image>(); PixelizingOptions options = null; void Action() => _generator.CreatePixelart(image, options); Assert.Throws <ArgumentNullException>(Action); }
public void CreatePixelart_FromImage_ReturnsAnother(PixelizingOptions options, Image image, SColor[,] expected) { _mockResizer .Setup(x => x.Resize(It.IsAny <Image>(), It.IsAny <Size>())) .Returns((Image img, Size size) => img); var actual = _generator.CreatePixelart(image, options).Pixels; Assert.Equal(expected, actual); }
public void CreatePixelart_ImageIsNull_ThrowsException() { Image image = null; var options = new PixelizingOptions { AvailibleColors = new[] { SColor.White, SColor.Black }, Size = new Size(100, 200) }; void Action() => _generator.CreatePixelart(image, options); Assert.Throws <ArgumentNullException>(Action); }
public async Task CreateAsync_ByModel_CreatesAndSavesPixelart() { var model = new PixelartCreateModel { SourcePath = "path/to/file.png", Size = new Size(2, 3), AvailibleColorsIds = new[] { 1, 2, 3 }, Unit = SizeUnit.Pixel }; var image = _fixture.Create <Image>(); var colors = new Color[] { new Color { Id = 1 }, new Color { Id = 2 }, new Color { Id = 3 }, new Color { Id = 4 } }; var options = new PixelizingOptions { AvailibleColors = new[] { new SColor(), new SColor(), new SColor(), }, Size = new Size(2, 3) }; var expected = _fixture.Create <string>(); _storageMock.Setup(s => s.GetImage(model.SourcePath)).Returns(image); _repositoryMock.Setup(r => r.GetAsync( It.IsAny <Expression <Func <Color, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())) .ReturnsAsync(colors); _generatorMock.Setup(g => g.CreatePixelart(It.IsAny <Image>(), It.IsAny <PixelizingOptions>())); _storageMock.Setup(s => s.SaveImage(It.IsAny <Image>())).Returns(expected); var result = await _service.CreateAsync(model); Assert.Equal(expected, result.ResultPath); _generatorMock.VerifyAll(); _repositoryMock.VerifyAll(); _storageMock.VerifyAll(); }
public async Task <PixelartCreationResultModel> CreateAsync(PixelartCreateModel model) { var image = _storage.GetImage(model.SourcePath); var ids = model.AvailibleColorsIds; var colors = await _repository.GetAsync <Color>(x => ids.Contains(x.Id)); var options = new PixelizingOptions { AvailibleColors = colors.Select(x => System.Drawing.Color.FromArgb(x.A, x.R, x.G, x.B)), Size = model.Size * (int)model.Unit }; var result = _pixelartGenerator.CreatePixelart(image, options); var path = _storage.SaveImage(result); return(new PixelartCreationResultModel { ResultPath = path }); }