private void HandleBuyChanged(bool value) { var current = _reserve.GetProductStatus(_productId); if (value != current.ShouldConsume) { _reserve.SetConsume(_productId, value); } }
public void ProvideProduct_AddsProvide() { const int amount = 100; _reserve.SetProvide(ProductId, true); var status = _reserve.GetProductStatus(ProductId); var before = _reserve.GetProvideProducts().FirstOrDefault(i => i.ProductId == ProductId); _inventory.TryAddProduct(ProductId, amount); var after = _reserve.GetProvideProducts().FirstOrDefault(i => i.ProductId == ProductId); Assert.IsNotNull(status); Assert.IsTrue(status.ShouldProvide); Assert.IsFalse(status.ShouldConsume); Assert.IsNull(before); Assert.IsNotNull(after); Assert.AreEqual(amount, after.Amount); }
public void Initialize(InventoryReserve reserve, int productId, int maxAmount) { _reserve = reserve; _productId = productId; var current = _reserve.GetProductStatus(_productId); if (current == null) { _reserve.AddReservation(_productId, 0, false, false); } BuyToggle.onValueChanged.AddListener(HandleBuyChanged); SellToggle.onValueChanged.AddListener(HandleSellChanged); Slider.minValue = 0; Slider.maxValue = maxAmount; Slider.onValueChanged.AddListener(HandleAmountChanged); }