/// <inheritdoc/> public async Task <string> AddAsync(Stream imageStream) { var code = _barcodeService.ParseBarcodePhoto(imageStream); if (string.IsNullOrEmpty(code)) { throw new ValidationException("Barcode wasn't read from the uploaded photo"); } var barcodeDB = await _barcodeService.GetBarcodeFromDBAsync(code); if (barcodeDB != null && IsProductsInDB(p => p.Barcode != null && string.Equals(p.Barcode.Code, barcodeDB.Code, StringComparison.CurrentCultureIgnoreCase), out var products)) { return(products.First().Id); } else { var barcode = await _barcodeService.GetBarcodeFromCatalogAsync(code); var newProduct = new Product { Barcode = barcode, Name = barcode.ProductName, Composition = barcode.Composition, Brand = barcode.Brand, Country = barcode.Country, Weight = barcode.Weight, PicturePath = barcode.PicturePath, }; return(await _productRepository.AddAsync(_mapper.Map <ProductDB>(newProduct))); } }
public void GetAsync_Barcode_By_GoodImage() { //Arrange Barcode barcode = new Barcode(); //Act using (Stream stream = new MemoryStream()) { _imageGood.Save(stream, ImageFormat.Bmp); var code = _service.ParseBarcodePhoto(stream); barcode = _service.GetBarcodeFromCatalogAsync(code).Result; } //Assert Assert.AreEqual(_verified.PicturePath, barcode.PicturePath); }