public ConsumeFridgeItemCommand(long fridgeItemId, Guid userId, Guid fridgeId, AmountValue amountValue) { FridgeItemId = fridgeItemId; UserId = userId; FridgeId = fridgeId; AmountValue = amountValue; }
public void IllegalAmountTest() { var thatDamnOffer = "1000000000000000100"; var val = AmountValue.FromString(thatDamnOffer, native: true); Assert.AreEqual(thatDamnOffer, val.ToString()); }
public void FridgeItem_CreateNewShouldHaveDateTimeNow() { FoodProduct foodProduct = new FoodProduct("Mleko", _category); AmountValue amountValue = new AmountValue(15.3f, Unit.Grams); var fridgeItem = new FridgeItem(foodProduct.FoodProductId, "desc", amountValue); var dateTime = DateTime.Now; Assert.AreEqual(dateTime.ToShortDateString(), fridgeItem.EnteredAt.ToShortDateString()); }
public void FridgeItem_ConsumeWithSameAmountValue_ShouldSetIsConsumed() { FoodProduct foodProduct = new FoodProduct("Mleko", _category); AmountValue amountValue = new AmountValue(100.0f, Unit.Mililiter); FridgeItem fridgeItem = new FridgeItem(foodProduct.FoodProductId, "desc", amountValue); AmountValue amountValToConsume = new AmountValue(100.0f, Unit.Mililiter); fridgeItem.ConsumeFridgeItem(amountValToConsume); Assert.AreEqual(true, fridgeItem.IsConsumed); }
public void FridgeItem_UpdateItemNote_ShouldHaveNewValue() { FoodProduct foodProduct = new FoodProduct("Mleko", _category); AmountValue amountValue = new AmountValue(15.3f, Unit.Grams); var fridgeItem = new FridgeItem(foodProduct.FoodProductId, "desc", amountValue); string noteUpdated = "updatedDesc"; fridgeItem.UpdateFridgeItemNote(noteUpdated); Assert.AreEqual(fridgeItem.Note, noteUpdated); }
public FridgeItem(short foodProductId, string note, AmountValue amountValue) { //if (foodProduct is null) // throw new DomainException("Food product is null", "InvalidFoodProduct"); AmountValue = amountValue; IsConsumed = false; Note = note; FoodProductId = foodProductId; EnteredAt = DateTime.Now; }
public void FridgeItem_UpdateConsumed_ShouldThrowException() { FoodProduct foodProduct = new FoodProduct("Mleko", _category); AmountValue amountValue = new AmountValue(100.0f, Unit.Mililiter); FridgeItem fridgeItem = new FridgeItem(foodProduct.FoodProductId, "desc", amountValue); AmountValue amountValToConsume = new AmountValue(100.0f, Unit.Mililiter); fridgeItem.ConsumeFridgeItem(amountValToConsume); // first consume Assert.AreEqual(true, fridgeItem.IsConsumed); Assert.Throws(typeof(DomainException), () => fridgeItem.UpdateFridgeItemNote("updated")); }
public virtual AmountValue GetAmount(string dateType) { AmountValue dateValue; dateValue = Amounts.FirstOrDefault(p => p.AmountType == dateType); if (dateValue == null) { dateValue = new AmountValue() { Consumer = this, AmountType = dateType, Value = 0 }; Amounts.Add(dateValue); } return(dateValue); }
public void ConsumeFridgeItem(AmountValue amountValue) { if (IsConsumed) { throw new DomainException("This item is consumed! Cant consume again.", "ConsumeFridgeItemFailed"); } if (this.AmountValue.CompareTo(amountValue) <= 0) { this.AmountValue.ResetAmount(); IsConsumed = true; } else { IsConsumed = false; this.AmountValue.DecreaseAmount(amountValue); } }
public void AmountValue_WithLessThanZero_ShouldThrowException() { AmountValue amountVal; Assert.Throws(typeof(AmountValueException), () => amountVal = new AmountValue(-10.0f, Unit.Grams)); }
public void IncreaseFridgeItemAmount(AmountValue amountValue) { // handle unit - what if units are different? AmountValue = new AmountValue(AmountValue.Value + amountValue.Value, AmountValue.Unit); }
public void ChangeFridgeItemAmount(AmountValue amountValue) { AmountValue = amountValue; }
public void ConsumeFridgeItem(long fridgeItemId, AmountValue amountValue) { var fridgeItem = GetFridgeItem(fridgeItemId); ConsumeFridgeItem(fridgeItem, amountValue); }
private void ConsumeFridgeItem(FridgeItem item, AmountValue amountValue) { item.ConsumeFridgeItem(amountValue); }