public void WhenCreated_HoldsADiscountAndAName()
        {
            var discount = 1.0m;
            var prod     = new ProductItem("Bread", new Money(10, repo.Get("USD")));
            var item     = new ItemOnSaleRule(prod.ProductName, discount);

            Assert.Equal(discount, item.DiscountPercentage);
            Assert.Equal(prod.ProductName, item.ProductName);
        }
        public void WhenProductDoesNotExist_ReturnsAnEmptyMaybe()
        {
            var result = storage.GetProduct("non existing product", 1);

            var fallbackItem = new ProductItem("...", new Money(0.1m, repo.Get("USD")));

            var item = result.GetValueOrFallback(fallbackItem);

            Assert.Equal(fallbackItem, item);
        }
        public void Selector_GetsTheMaybeItemWhenRequested()
        {
            CurrencyTypeRepository repo = new CurrencyTypeRepository();

            var value1 = new Money(98.003m, repo.Get("USD"));
            var m      = new Maybe <Money>(value1);

            var selected = m.Select(x => x);

            Assert.Equal(m, selected);
        }
        public void Equals_WhenComparedWithAnotherMaybe_ThenReturnsFalseWhenDifferent()
        {
            const int value = 14;
            var       m1    = new Maybe <int>(value);
            var       m2    = new Maybe <int>(value + 1);

            Assert.False(m1.Equals(m2));

            var m3 = new Maybe <string>("hola");
            var m4 = new Maybe <string>("chau");

            Assert.False(m3.Equals(m4));

            CurrencyTypeRepository repo = new CurrencyTypeRepository();

            var value1 = new Money(98.003m, repo.Get("USD"));
            var value2 = new Money(98.002m, repo.Get("USD"));
            var m5     = new Maybe <Money>(value1);
            var m6     = new Maybe <Money>(value2);

            Assert.False(m5.Equals(m6));
        }
        public void Selector_GetsTheMaybeOfBoolWhenQueried()
        {
            CurrencyTypeRepository repo = new CurrencyTypeRepository();

            var value1 = new Money(98.003m, repo.Get("USD"));
            var m      = new Maybe <Money>(value1);

            var selected = m.Select(x => x.Amount >= 98m);

            var result = selected.GetValueOrFallback(false);

            Assert.True(result);
        }
Exemple #6
0
    public Currency(string isoCode)
    {
        if (!_repo.Exists(isoCode))
        {
            throw new ArgumentException("Invalid ISO Currency Code");
        }

        var newCurrency = _repo.Get(isoCode);

        IsoCode          = newCurrency.IsoCode;
        IsDigital        = newCurrency.IsDigital;
        GeneralName      = newCurrency.GeneralName;
        Symbol           = newCurrency.Symbol;
        DecimalPlace     = newCurrency.DecimalPlace;
        BaseDecimalPlace = newCurrency.BaseDecimalPlace;
        DecimalMark      = newCurrency.DecimalMark;
        ThousandMark     = newCurrency.ThousandMark;
    }
        public void Equals_WhenComparedWithAnotherMaybe_ThenReturnsTrueWhenSame()
        {
            const int value = 14;
            var       m1    = new Maybe <int>(value);
            var       m2    = new Maybe <int>(value);

            Assert.True(m1.Equals(m2));

            const string value2 = "hola";
            var          m3     = new Maybe <string>(value2);
            var          m4     = new Maybe <string>(value2);

            Assert.True(m3.Equals(m4));

            CurrencyTypeRepository repo = new CurrencyTypeRepository();

            var value3 = new Money(98.003m, repo.Get("USD"));
            var m5     = new Maybe <Money>(value3);
            var m6     = new Maybe <Money>(value3);

            Assert.True(m5.Equals(m6));
        }
    public void CurrencyIsEqual()
    {
        Currency cur1 = repo.Get("BTC");
        Currency cur2 = repo.Get("BTC");

        Assert.Equal <Currency>(cur1, cur2);
    }