Exemple #1
0
        public void Equals_WithSameCurrencyFromAndTo_ShouldReturnTrue()
        {
            var exchangeRate1 = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);
            var exchangeRate2 = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            Assert.IsTrue(exchangeRate1.Equals(exchangeRate2));
            Assert.IsTrue(exchangeRate2.Equals(exchangeRate1));
        }
Exemple #2
0
        public void CanChangeFrom_TargetCurrencyCorrespond_ShouldReturnTrue()
        {
            var exchangeRate = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            string changeTo;

            Assert.IsTrue(exchangeRate.CanChangeFrom(CURRENCY_NAME_2, out changeTo));
        }
Exemple #3
0
        public void Equals_WithSameCurrencyToButNotFrom_ShouldReturnFalse()
        {
            var exchangeRate1 = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);
            var exchangeRate2 = ExchangeCurrency.Create(CURRENCY_NAME_3, CURRENCY_NAME_2, 0);

            Assert.IsFalse(exchangeRate1.Equals(exchangeRate2));
            Assert.IsFalse(exchangeRate2.Equals(exchangeRate1));
        }
Exemple #4
0
        public void CanChangeFrom_CurrencyNotManaged_ShouldReturnFalse()
        {
            var exchangeRate = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            string changeTo;

            Assert.IsFalse(exchangeRate.CanChangeFrom(CURRENCY_NAME_3, out changeTo));
        }
Exemple #5
0
        public void ToString_ThroughExchange_ShoudReturnPath()
        {
            var directExchange = ThroughExchange.Create(ExchangeCurrency.Create("INI", "INT", 1), "INI", "TAR", new List <IExchangeCurrency>()
            {
                ExchangeCurrency.Create("INT", "TAR", 1),
            });

            Assert.AreEqual("INI;INT;TAR", directExchange.ToString());
        }
Exemple #6
0
        public void CanChangeFrom_TargetCurrencyCorrespond_OutParamShouldBeEqualToInitialCurrency()
        {
            var exchangeRate = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            string changeTo;

            exchangeRate.CanChangeFrom(CURRENCY_NAME_2, out changeTo);

            Assert.AreEqual(CURRENCY_NAME_1, changeTo);
        }
Exemple #7
0
        public void CanChangeFrom_CurrencyNotManaged_OutParamShouldBeNull()
        {
            var exchangeRate = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            string changeTo;

            exchangeRate.CanChangeFrom(CURRENCY_NAME_3, out changeTo);

            Assert.IsNull(changeTo);
        }
Exemple #8
0
        public void Change_InitialSecondTargetFirst_ShouldReturnChangeExhangeRateValue()
        {
            const double expectedChangeResult = 3.14;
            var          exchangeRate         = (ExchangeCurrency)ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            exchangeRate.SetNewRate(new ExchangeRateStub {
                ChangeBackResult = expectedChangeResult
            });

            Assert.AreEqual(expectedChangeResult, exchangeRate.Change(CURRENCY_NAME_2, CURRENCY_NAME_1, 0));
        }
Exemple #9
0
        public void FactoryCreate_SameCurrencyTwice_ShouldReturnRightPath()
        {
            var availableExchangeCurrency = new List <IExchangeCurrency>
            {
                ExchangeCurrency.Create("AAA", "BBB", 1),
                ExchangeCurrency.Create("BBB", "CCC", 1),
                ExchangeCurrency.Create("CCC", "BBB", 1)
            };

            var chainFactory = new ExchangeChainFactory(availableExchangeCurrency);

            Assert.AreEqual("AAA;BBB;CCC", chainFactory.Create("AAA", "CCC").ToString());
        }
Exemple #10
0
        public void Change_ExchangeRateChainExist_ShouldReturnExchangeRateResultRounded()
        {
            const int expectedChangeResult = 59033;
            var       bank = new Bank();

            bank.AddExchangeRate(ExchangeCurrency.Create("AUD", "CHF", 0.9661));
            bank.AddExchangeRate(ExchangeCurrency.Create("JPY", "KRW", 13.1151));
            bank.AddExchangeRate(ExchangeCurrency.Create("EUR", "CHF", 1.2053));
            bank.AddExchangeRate(ExchangeCurrency.Create("AUD", "JPY", 86.0305));
            bank.AddExchangeRate(ExchangeCurrency.Create("EUR", "USD", 1.2989));
            bank.AddExchangeRate(ExchangeCurrency.Create("JPY", "INR", 0.6571));

            var changeResult = bank.Change("EUR", "JPY", 550);

            Assert.AreEqual(expectedChangeResult, changeResult);
        }
Exemple #11
0
        public void FactoryCreate_Loop_ShouldReturnRightPath()
        {
            var availableExchangeCurrency = new List <IExchangeCurrency>
            {
                ExchangeCurrency.Create("EUR", "USD", 1),
                ExchangeCurrency.Create("USD", "LIV", 1),
                ExchangeCurrency.Create("USD", "CHF", 1),
                ExchangeCurrency.Create("USD", "AUD", 1),
                ExchangeCurrency.Create("CHF", "LIV", 1),
                ExchangeCurrency.Create("CHF", "AUD", 1),
                ExchangeCurrency.Create("CHF", "AUD", 1),
                ExchangeCurrency.Create("LIV", "AUD", 1),
                ExchangeCurrency.Create("JPY", "LIV", 1)
            };

            var chainFactory = new ExchangeChainFactory(availableExchangeCurrency);

            Assert.AreEqual("EUR;USD;LIV;JPY", chainFactory.Create("EUR", "JPY").ToString());
        }
Exemple #12
0
 public void Create_WithOnlyWhiteSpaceFromCurrencyName_ShouldThrowArgumentNullException()
 {
     ExchangeCurrency.Create(" ", null, 0);
 }
Exemple #13
0
 public void Create_WithNullFromCurrencyName_ShouldThrowArgumentNullException()
 {
     ExchangeCurrency.Create(null, null, 0);
 }
Exemple #14
0
        public void Change_TargetCurrencyNotManaged_ThrowArgumentException()
        {
            var exchangeRate = (ExchangeCurrency)ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            exchangeRate.Change(CURRENCY_NAME_1, CURRENCY_NAME_3, 0);
        }
Exemple #15
0
        public void Equals_WithNull_ShouldReturnFalse()
        {
            var exchangeRate1 = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            Assert.IsFalse(exchangeRate1.Equals(null));
        }
Exemple #16
0
 public void Create_WithSameFromAndToCurrencyName_ShouldThrowArgumentException()
 {
     ExchangeCurrency.Create(CURRENCY_NAME, CURRENCY_NAME, 0);
 }
Exemple #17
0
 public void Create_WithOnlyWhiteSpaceToCurrencyName_ShouldThrowArgumentNullException()
 {
     ExchangeCurrency.Create(CURRENCY_NAME, " ", 0);
 }
Exemple #18
0
 public void Create_WithEmptyToCurrencyName_ShouldThrowArgumentNullException()
 {
     ExchangeCurrency.Create(CURRENCY_NAME, string.Empty, 0);
 }
Exemple #19
0
        public void CanChange_SwitchedInitialAndTargetCurrencyManaged_ShouldReturnTrue()
        {
            var exchangeRate = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            Assert.IsTrue(exchangeRate.CanChange(CURRENCY_NAME_2, CURRENCY_NAME_1));
        }
Exemple #20
0
 public void Create_WithEmptyFromCurrencyName_ShouldThrowArgumentNullException()
 {
     ExchangeCurrency.Create(string.Empty, null, 0);
 }
Exemple #21
0
 public void Create_WithNullToCurrencyName_ShouldThrowArgumentNullException()
 {
     ExchangeCurrency.Create(CURRENCY_NAME, null, 0);
 }
Exemple #22
0
        public void CanChange_TargetCurrencyNotManaged_ShouldReturnFalse()
        {
            var exchangeRate = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            Assert.IsFalse(exchangeRate.CanChange(CURRENCY_NAME_1, CURRENCY_NAME_3));
        }