public void GetTotalCost() { var quantity = 10m; var price = 5m; var resource = new ResourcePool <Resource>(0) { Quantity = quantity, CostPrice = price }; var totalCostExpected = quantity * price; var totalCostActual = resource.GetTotalCost(); Assert.Equal(totalCostExpected, totalCostActual); }
public void RemoveResource <T>(ResourcePool <T> resource, decimal quantity) where T : class { if (resource.Quantity < quantity) { throw new ArgumentOutOfRangeException("quantity", $"More than {resource.Quantity}"); } if (resource.Quantity == quantity) { resource.Quantity = 0; resource.CostPrice = 0; resource.TotalCost = 0; return; } resource.Quantity -= quantity; resource.TotalCost -= resource.GetTotalCost(); }
public void AddResource <T>(ResourcePool <T> resource, decimal quantity, decimal price) where T : class { resource.Quantity += quantity; resource.TotalCost = resource.GetTotalCost() + quantity * price; resource.CostPrice = resource.TotalCost / resource.Quantity; }