Example #1
0
        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;
        }
Example #2
0
        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);
        }
Example #3
0
 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);
 }
Example #4
0
File: Test.cs Project: dgayer/oom
 public void CanCreatePrice()
 {
     var x = new Price(1, Currency.EUR);
     Assert.IsTrue(x.Amount == 1);
     Assert.IsTrue(x.Unit == Currency.EUR);
 }
Example #5
0
File: Test.cs Project: dgayer/oom
 public void CanConvertPrice()
 {
     var x = new Price(1, Currency.EUR);
     Assert.IsTrue(x.ConvertTo(Currency.JPY).Amount > 1);
 }
Example #6
0
 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);
 }
Example #7
0
 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);
 }
Example #8
0
 /// <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;
 }
Example #9
0
 /// <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);
 }
Example #10
0
 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);
 }