コード例 #1
0
 public ConsumeFridgeItemCommand(long fridgeItemId, Guid userId, Guid fridgeId, AmountValue amountValue)
 {
     FridgeItemId = fridgeItemId;
     UserId       = userId;
     FridgeId     = fridgeId;
     AmountValue  = amountValue;
 }
コード例 #2
0
        public void IllegalAmountTest()
        {
            var thatDamnOffer = "1000000000000000100";
            var val           = AmountValue.FromString(thatDamnOffer, native: true);

            Assert.AreEqual(thatDamnOffer, val.ToString());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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;
        }
コード例 #7
0
        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"));
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        public void AmountValue_WithLessThanZero_ShouldThrowException()
        {
            AmountValue amountVal;

            Assert.Throws(typeof(AmountValueException), () => amountVal = new AmountValue(-10.0f, Unit.Grams));
        }
コード例 #11
0
 public void IncreaseFridgeItemAmount(AmountValue amountValue)
 {
     // handle unit - what if units are different?
     AmountValue = new AmountValue(AmountValue.Value + amountValue.Value, AmountValue.Unit);
 }
コード例 #12
0
 public void ChangeFridgeItemAmount(AmountValue amountValue)
 {
     AmountValue = amountValue;
 }
コード例 #13
0
ファイル: User.cs プロジェクト: Dariusz151/SmartFridgeApp
        public void ConsumeFridgeItem(long fridgeItemId, AmountValue amountValue)
        {
            var fridgeItem = GetFridgeItem(fridgeItemId);

            ConsumeFridgeItem(fridgeItem, amountValue);
        }
コード例 #14
0
ファイル: User.cs プロジェクト: Dariusz151/SmartFridgeApp
 private void ConsumeFridgeItem(FridgeItem item, AmountValue amountValue)
 {
     item.ConsumeFridgeItem(amountValue);
 }