private ProcessReport Verify(string measureCode, string name, decimal price, ProviderData dataOnServer, int?code, MeasureUnit measureUnit, DateTime timestamp) { data.Timestamp = timestamp; data.Products = new[] { new ProductData() { Id = new Guid(), MeasureUnitCode = measureCode, Name = name, Price = price } }; dataSerialized = JsonConvert.SerializeObject(data); A.CallTo(() => repository.FindByProviderId(A <Guid> .Ignored)).Returns(dataOnServer); A.CallTo(() => productsReference.FindCodeByName(A <string> .Ignored)).Returns(code); A.CallTo(() => measureUnitsReference.FindByCode(A <string> .Ignored)).Returns(measureUnit); return(new ProviderProcessor(productsReference, measureUnitsReference, repository).ProcessProviderData(dataSerialized)); }
public void SetUp() { productsReference = A.Fake <ProductsReference>(); A.CallTo(() => productsReference.FindCodeByName("unknown")).Returns(null); A.CallTo(() => productsReference.FindCodeByName("known")).Returns(42); ProductsReference.SetInstance(productsReference); measureUnitsReference = A.Fake <MeasureUnitsReference>(); A.CallTo(() => measureUnitsReference.FindByCode("unknown")).Returns(null); A.CallTo(() => measureUnitsReference.FindByCode("known")).Returns(new MeasureUnit()); MeasureUnitsReference.SetInstance(measureUnitsReference); processor = new ProviderProcessor(A.Fake <ProviderRepository>(), null); memoryAppender = new MemoryAppender(); BasicConfigurator.Configure(memoryAppender); }
private IEnumerable <ProductValidationResult> ValidateNames(ProductData[] data) { foreach (var product in data) { if (!productsReference.FindCodeByName(product.Name).HasValue) { yield return(new ProductValidationResult(product, "Unknown product name", ProductValidationSeverity.Error)); } } }
public void SetUp() { data = new ProviderData(); data.Products = new ProductData[0]; dataSerialized = JsonConvert.SerializeObject(data); repository = A.Fake <IProviderRepository>(); A.CallTo(() => repository.FindByProviderId(A <Guid> .Ignored)).Returns(null); A.CallTo(() => repository.RemoveById(A <Guid> .Ignored)).DoesNothing(); A.CallTo(() => repository.Save(A <ProviderData> .Ignored)).DoesNothing(); A.CallTo(() => repository.Update(A <ProviderData> .Ignored)).DoesNothing(); productsReference = A.Fake <ProductsReference>(); A.CallTo(() => productsReference.FindCodeByName(A <string> .Ignored)).Returns(null); measureUnitsReference = A.Fake <MeasureUnitsReference>(); A.CallTo(() => measureUnitsReference.FindByCode(A <string> .Ignored)).Returns(null); }
public IList <ProductValidationResult> ValidateProduct(ProductData product) { var result = new List <ProductValidationResult>(); if (!productsReference.FindCodeByName(product.Name).HasValue) { result.Add(new ProductValidationResult(product, "Unknown product name", ProductValidationSeverity.Error)); } if (product.Price <= 0) { result.Add(new ProductValidationResult(product, "Bad price", ProductValidationSeverity.Warning)); } if (!IsValidMeasureUnitCode(product.MeasureUnitCode)) { result.Add(new ProductValidationResult(product, "Bad units of measure", ProductValidationSeverity.Warning)); } return(result); }