private GiftCard(Price amount, string code, bool isRedeemed) { if (amount.Amount <= 0) throw new ArgumentException("Amount must be greater than 0.", nameof(amount)); Amount = amount; Code = code; IsRedeemed = isRedeemed; }
public Book(string title, string isbn, Price price) { if (string.IsNullOrWhiteSpace(title)) throw new ArgumentException("Title must not be empty.", nameof(title)); if (string.IsNullOrWhiteSpace(isbn)) throw new ArgumentException("ISBN must not be empty.", nameof(isbn)); Title = title; ISBN = isbn; UpdatePrice(price.Amount, price.Unit); }
public void CanComparePrices() { var a = new Price(1, Currency.EUR); var b = new Price(1, Currency.EUR); Assert.IsFalse(a < b); Assert.IsTrue(a <= b); Assert.IsTrue(a == b); Assert.IsFalse(a != b); Assert.IsTrue(a >= b); Assert.IsFalse(a > b); }
public void CanCreatePrice() { var x = new Price(1, Currency.EUR); Assert.IsTrue(x.Amount == 1); Assert.IsTrue(x.Unit == Currency.EUR); }
public void CanConvertPrice() { var x = new Price(1, Currency.EUR); Assert.IsTrue(x.ConvertTo(Currency.JPY).Amount > 1); }
public void CanAddPricesWithDifferentCurrency() { var x = new Price(1, Currency.EUR) + new Price(1, Currency.USD); Assert.IsTrue(x.Unit == Currency.EUR); Assert.IsTrue(x.Amount > 1); }
public void CanAddPrices() { var x = new Price(1, Currency.EUR) + new Price(1, Currency.EUR); Assert.IsTrue(x.Unit == Currency.EUR); Assert.IsTrue(x.Amount == 2); }
/// <summary> /// Updates the book's price. /// </summary> /// <param name="newPrice">Price must not be negative.</param> public void UpdatePrice(Price newPrice) { if (newPrice.Amount < 0) throw new ArgumentException("Price must not be negative.", nameof(newPrice)); m_price = newPrice; }
/// <summary> /// Updates the book's price. /// </summary> /// <param name="newPrice">Price must not be negative.</param> /// <param name="newCurrency">Currency.</param> public void UpdatePrice(decimal newPrice, Currency currency) { if (newPrice < 0) throw new ArgumentException("Price must not be negative.", nameof(newPrice)); m_price = new Price(newPrice, currency); }
private static bool BinaryOp(Price x, Price y, Func<decimal, decimal, bool> op) { if (object.ReferenceEquals(x, null) || object.ReferenceEquals(y, null)) throw new ArgumentNullException(); if (x.Unit == y.Unit) return op(x.Amount, y.Amount); return op(x.Amount, y.ConvertTo(x.Unit).Amount); }