Пример #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;
        }
Пример #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);
        }
Пример #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);
 }
Пример #4
0
Файл: Test.cs Проект: dgayer/oom
 public void CanCreatePrice()
 {
     var x = new Price(1, Currency.EUR);
     Assert.IsTrue(x.Amount == 1);
     Assert.IsTrue(x.Unit == Currency.EUR);
 }
Пример #5
0
Файл: Test.cs Проект: dgayer/oom
 public void CanConvertPrice()
 {
     var x = new Price(1, Currency.EUR);
     Assert.IsTrue(x.ConvertTo(Currency.JPY).Amount > 1);
 }
Пример #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);
 }
Пример #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);
 }
Пример #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;
 }
Пример #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);
 }
Пример #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);
 }