示例#1
0
        public void Parse_DifferentCurrencySeparator_NotImportant()
        {
            ExchangeRate parsed = ExchangeRate.Parse("EUR-USD 1.25");

            Assert.That(parsed.From, Is.EqualTo(CurrencyIsoCode.EUR));
            Assert.That(parsed.To, Is.EqualTo(CurrencyIsoCode.USD));
            Assert.That(parsed.Rate, Is.EqualTo(1.25m));
        }
示例#2
0
        public void Parse_CaseInsensitiveCurrencies()
        {
            ExchangeRate parsed = ExchangeRate.Parse("eur/USd 1.25");

            Assert.That(parsed.From, Is.EqualTo(CurrencyIsoCode.EUR));
            Assert.That(parsed.To, Is.EqualTo(CurrencyIsoCode.USD));
            Assert.That(parsed.Rate, Is.EqualTo(1.25m));
        }
示例#3
0
            public void WhenCurrencyPairHasSameCurrencies_ThenParsingShouldThrow()
            {
                using (new SwitchCulture("en-US"))
                {
                    Action action = () => ExchangeRate.Parse("EUR/EUR 1.2591");

                    action.ShouldThrow <FormatException>();
                }
            }
        public void WhenCurrencyPairInNlCulture_ThenParsingShouldSucceed()
        {
            var fx1 = ExchangeRate.Parse("EUR/USD 1,2591");

            fx1.BaseCurrency.Code.Should().Be("EUR");
            fx1.QuoteCurrency.Code.Should().Be("USD");
            fx1.Value.Should().Be(1.2591M);

            var fx2 = ExchangeRate.Parse("EUR/USD1,2591");

            fx2.BaseCurrency.Code.Should().Be("EUR");
            fx2.QuoteCurrency.Code.Should().Be("USD");
            fx2.Value.Should().Be(1.2591M);
        }
        public void WhenCurrencyPairIsEmpty_ThenThrowException()
        {
            Action action = () => ExchangeRate.Parse("");

            action.ShouldThrow <FormatException>();
        }
        public void WhenCurrencyPairIsNull_ThenThrowException()
        {
            Action action = () => ExchangeRate.Parse(null);

            action.ShouldThrow <ArgumentNullException>();
        }
        public void WhenCurrencyPairHasSameCurrencies_ThenThrowException()
        {
            Action action = () => ExchangeRate.Parse("EUR/EUR 1.2591");

            action.ShouldThrow <FormatException>();
        }
        public void WhenCurrencyPairIsNotANumber_ThenThrowException()
        {
            Action action = () => ExchangeRate.Parse("EUR/USD 1,ABC");

            action.ShouldThrow <FormatException>();
        }
示例#9
0
 public void Parse_MissingRate_Exception()
 {
     Assert.That(() => ExchangeRate.Parse("USD/EUR  "), Throws.InstanceOf <FormatException>());
 }
示例#10
0
 public void Parse_UndefinedCurrencies_Exception(string undefinedCurrency)
 {
     Assert.That(() => ExchangeRate.Parse(undefinedCurrency), Throws.InstanceOf <FormatException>());
 }
示例#11
0
        public void Parse_InverseOf_ToString()
        {
            var subject = new ExchangeRate(CurrencyIsoCode.EUR, CurrencyIsoCode.USD, 1.25m);

            Assert.That(ExchangeRate.Parse(subject.ToString()), Is.EqualTo(subject));
        }