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)); }
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); }
public void Exchange_ShouldThrow_WhenCurrencyIsNotFound(FxExchange exchange, IExchangeRateHolder rateHolder) { // arrange var sut = new CurrencyExchanger(rateHolder); // act // assert Should.Throw <InvalidCurrencyException>(() => sut.Exchange(exchange)); }
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); }
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); } }
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)); }
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); }
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)); }