コード例 #1
0
        public void Apply_CompatibleInstance_CorrectAmountAndCurrency()
        {
            var   subject    = new ExchangeRate(CurrencyIsoCode.EUR, CurrencyIsoCode.USD, 1.25m);
            Money compatible = 10m.Eur();

            Assert.That(subject.Apply(compatible), Must.Be.MoneyWith(12.5m, Currency.Usd));
        }
コード例 #2
0
        public void ExchangeRate_CanBeExtendedTo_SupportCustomRateArithmetic()
        {
            var stock      = new ExchangeRate(CurrencyIsoCode.EUR, CurrencyIsoCode.USD, 1.11111m);
            var truncating = new ExtendsApply(CurrencyIsoCode.EUR, CurrencyIsoCode.USD, 1.11111m);

            Assert.That(stock.Apply(1m.Eur()), Is.Not.EqualTo(truncating.Apply(1m.Eur())));
        }
コード例 #3
0
        public void Apply_IncompatibleInstance_Exception()
        {
            var   subject      = new ExchangeRate(CurrencyIsoCode.EUR, CurrencyIsoCode.USD, 1.25m);
            Money incompatible = 10m.Cad();

            Assert.That(() => subject.Apply(incompatible), Throws
                        .InstanceOf <DifferentCurrencyException>()
                        .With.Message.Contains("EUR")
                        .And.Message.Contains("CAD"));
        }
コード例 #4
0
            public Money To(CurrencyIsoCode to)
            {
                var rateCalculator = new ExchangeRate(_from.CurrencyCode, to, _rate);

                return(rateCalculator.Apply(_from));
            }