public Product Update(Product entity) { Debug.WriteLine("UPDATING product in database"); var existing = Products.First(c => c.ID == entity.ID); Mapper.Map(entity, existing); return entity; }
public void Is_invalid_when_item_amount_does_not_equal_item_amount_times_product_price() { var orderItem = new OrderItem() { Amount = 30, Quantity = 3 }; var product = new Product { Price = 11 }; var rule = new OrderItemAmountValidityRule(orderItem, product); rule.Validate().IsValid.ShouldBe(false); rule.ErrorMessage.ShouldNotBe(null); }
public void Is_invalid_when_item_price_does_not_equal_product_price() { var orderItem = new OrderItem() { Price = 10 }; var product = new Product { Price = 11 }; var rule = new OrderItemPriceValidityRule(orderItem, product); rule.Validate().IsValid.ShouldBe(false); rule.ErrorMessage.ShouldNotBe(null); }
public void Is_valid_when_item_price_equals_product_price() { var orderItem = new OrderItem() { Price = 10 }; var product = new Product { Price = 10 }; var rule = new OrderItemPriceValidityRule(orderItem, product); rule.Validate().IsValid.ShouldBe(true); rule.ErrorMessage.ShouldBe(null); }
public async Task Is_valid_when_item_amount_equals_item_quantity_times_product_price_async() { var orderItem = new OrderItem() { Amount = 30, Quantity = 3 }; var product = new Product { Price = 10 }; var rule = new OrderItemAmountValidityRule(orderItem, product); await rule.ValidateAsync(); rule.IsValid.ShouldBe(true); rule.ErrorMessage.ShouldBe(null); }
public Product Insert(Product entity) { lock (_lockObject) { var nextID = Products.Max(c => c.ID) + 1; entity.ID = nextID; Products.Add(entity); return entity; } }
public Task<Product> UpdateAsync(Product entity) { return Task.Run(() => Update(entity)); }
public Task<Product> InsertAsync(Product entity) { return Task.Run(() => Insert(entity)); }
public OrderItemPriceValidityRule(OrderItem item, Product product) { _item = item; _product = product; }
public OrderItemAmountValidityRule(OrderItem item, Product product) { _item = item; _product = product; }