示例#1
0
        public Money Sum(Money augend, Money addend, Currency targetCurrency)
        {
            var x   = _currencyExchanger.Exchange(augend, targetCurrency);
            var y   = _currencyExchanger.Exchange(addend, targetCurrency);
            var sum = x.Amount + y.Amount;

            return(new Money(sum, targetCurrency));
        }
示例#2
0
        public void Exchange_FiveDollars_To_Dollars_Result_FiveDollars()
        {
            // Arrange
            var fiveDollars = MoneyProvider.Dollar(5);

            // Act
            var result = _exchanger.Exchange(fiveDollars, Currency.USD);

            // Assert
            Assert.AreEqual(fiveDollars, result);
        }
示例#3
0
        public void Exchange_ShouldThrow_WhenCurrencyIsNotFound(FxExchange exchange, IExchangeRateHolder rateHolder)
        {
            // arrange
            var sut = new CurrencyExchanger(rateHolder);

            // act
            // assert
            Should.Throw <InvalidCurrencyException>(() => sut.Exchange(exchange));
        }
示例#4
0
        public void Exchange_ShouldReturnTheSameAmount_AsRequested(FxExchange exchange, IExchangeRateHolder rateHolder)
        {
            // arrange
            var sut = new CurrencyExchanger(rateHolder);

            exchange.CurrencyPair.From = exchange.CurrencyPair.To;
            // act
            var result = sut.Exchange(exchange);

            // assert

            result.ShouldBe(exchange.Amount);
        }
示例#5
0
        private static void ExecuteExchange(FxExchange fxExchange)
        {
            var exchanger = new CurrencyExchanger(new ExchangeRateHolder(100));

            try
            {
                Console.WriteLine(exchanger.Exchange(fxExchange));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#6
0
        public void Exchange_IsCase_Insensitive(string from, string to)
        {
            // arrange
            var exchange = new FxExchange
            {
                Amount       = 1,
                CurrencyPair = new CurrencyPair {
                    From = from, To = to
                }
            };
            var sut = new CurrencyExchanger(new ExchangeRateHolder(100));

            // act
            // assert
            Should.NotThrow(() => sut.Exchange(exchange));
        }
示例#7
0
        public void Exchange_ShouldExchangeTheAmount_AsRequested(string from, string to, int ammount, double expected)
        {
            // arrange
            var exchange = new FxExchange {
                Amount = ammount, CurrencyPair = new CurrencyPair {
                    From = from, To = to
                }
            };

            var sut = new CurrencyExchanger(new ExchangeRateHolder(100));

            // act
            var result = sut.Exchange(exchange);

            // assert
            result.ShouldBe(expected);
        }
示例#8
0
        public void Exchange_ShouldThrow_WithMessage(string currency, string expected)
        {
            // arrange
            var exchange = new FxExchange
            {
                Amount       = 1,
                CurrencyPair = new CurrencyPair {
                    From = currency, To = "USD"
                }
            };
            var sut = new CurrencyExchanger(new ExchangeRateHolder(100));

            // act
            // assert
            var exception = Should.Throw <InvalidCurrencyException>(() => sut.Exchange(exchange));

            exception.Message.ShouldBe(string.Format(expected, currency));
        }