public void If_Create_Money_Then_Get_Currency_It_Should_Be_Return_Currency() { //Given var fiveBucks = FakeDataBuilder.MakeDollar(5); var fiveFranc = FakeDataBuilder.MakeFranc(5); //When //Then Assert.Equal("USD", fiveBucks.GetCurrency()); Assert.Equal("CHF", fiveFranc.GetCurrency()); }
public void Multiplier_equal_0_then_throw_exception() { //Given IExchangeService service = new ExchangeService(); //When ArgumentNullException exception = Assert.Throws <ArgumentNullException>(() => service.Times(FakeDataBuilder.MakeDollar(5), 0)); //Then Assert.Contains("Multiplier can not be 0", exception.Message); }
public void Exchange_currency_then_return_assign_currency_and_correct_amount() { //Given IExchangeService exchange = new ExchangeService(); var tenFranc = FakeDataBuilder.MakeFranc(10); exchange.AddRate("CHF", "USD", 2); //When ICurrencyExpression result = exchange.Exchange(tenFranc, "USD"); //Then Assert.Equal(FakeDataBuilder.MakeDollar(5), result); }
public void If_Same_Amount_Currency_Then_Compare_Equal_It_Should_Be_Return_True() { //Given var fiveBucks = FakeDataBuilder.MakeDollar(5); var fiveFranc = FakeDataBuilder.MakeFranc(5); //When //Then Assert.True(fiveBucks.Equals(FakeDataBuilder.MakeDollar(5))); Assert.False(fiveBucks.Equals(FakeDataBuilder.MakeDollar(6))); Assert.True(fiveFranc.Equals(FakeDataBuilder.MakeFranc(5))); Assert.False(fiveFranc.Equals(FakeDataBuilder.MakeFranc(6))); Assert.False(fiveFranc.Equals(FakeDataBuilder.MakeDollar(5))); }
public void Currency_Times_N_then_return_amount_multiplied_by_N() { //Given IExchangeService exchange = new ExchangeService(); int fakeAmount = 5; ICurrencyExpression fiveBucks = FakeDataBuilder.MakeDollar(fakeAmount); ICurrencyExpression fiveFranc = FakeDataBuilder.MakeFranc(fakeAmount); //When var result = exchange.Times(fiveBucks, 8); //Then Assert.True(FakeDataBuilder.MakeDollar(10).Equals(exchange.Times(fiveBucks, 2))); Assert.True(FakeDataBuilder.MakeDollar(15).Equals(exchange.Times(fiveBucks, 3))); Assert.True(FakeDataBuilder.MakeFranc(10).Equals(exchange.Times(fiveFranc, 2))); Assert.True(FakeDataBuilder.MakeFranc(15).Equals(exchange.Times(fiveFranc, 3))); }
public void Invalid_params_to_Exchange_then_throw_exception() { //Given IExchangeService exchange = new ExchangeService(); //When ArgumentNullException exception = Assert.Throws <ArgumentNullException>(() => exchange.Exchange(FakeDataBuilder.MakeDollar(1), null)); //Then Assert.Contains("Exchange must assign Currency", exception.Message); ArgumentNullException sourceException = Assert .Throws <ArgumentNullException>(() => exchange.Exchange(null, "USD")); Assert.Contains("Exchange must be have Money", sourceException.Message); }
public void Sum_Params_contains_diff_money_and_param_To_is_null_then_throw_exception() { //Given IExchangeService exchange = new ExchangeService(); var Bucks = FakeDataBuilder.MakeDollar(1); var Franc = FakeDataBuilder.MakeFranc(10); //When ArgumentNullException exception = Assert.Throws <ArgumentNullException>(() => exchange.Sum( null, new ICurrencyExpression[] { Bucks, Franc } )); //Then Assert.Contains("addeds contains diff currency,mush be assign currency", exception.Message); }
public void Sum_and_Times_N_and_ExchangeTo_then_return_correct_total() { //Given IExchangeService service = new ExchangeService(); var tenBucks = FakeDataBuilder.MakeDollar(10); var fiveBucks = FakeDataBuilder.MakeDollar(5); service.AddRate("CHF", "USD", 2); //When ICurrencyExpression result = service .Sum(new Money[] { tenBucks, fiveBucks }) .Times(2) .ExchangeTo("USD"); //Then Assert.Equal(FakeDataBuilder.MakeDollar(30), result); }
public void After_ExchangeTo_currency_then_clean_ExpressionList() { //Given IExchangeService exchange = new ExchangeService(); var fiveBucks = FakeDataBuilder.MakeDollar(5); var tenFranc = FakeDataBuilder.MakeFranc(10); exchange.AddRate("CHF", "USD", 2); //When ICurrencyExpression sameParamSum = exchange .Sum(new Money[] { fiveBucks, fiveBucks }) .ExchangeTo("USD"); int counts = exchange.ExpressionsList.Count(); //Then Assert.Equal(0, counts); }
public void ExchangeTo_then_return_correct_currency() { //Given ExchangeService service = new ExchangeService(); service.AddRate("CHF", "USD", 2); //When ICurrencyExpression result = service .Sum( new ICurrencyExpression[] { FakeDataBuilder.MakeDollar(5), FakeDataBuilder.MakeFranc(10) }).ExchangeTo("USD"); //Then Assert.Equal(FakeDataBuilder.MakeDollar(10), result); }