Beispiel #1
0
        public void TestExchangeRatesEquality()
        {
            var newRateA = StockExchange.ExchangeRate(DateTime.Now, "CHF", "USD", 2.0M);
            var newRateB = StockExchange.ExchangeRate(DateTime.Now, "CHF", "USD", 2.0M);

            Assert.IsTrue(newRateA.Equals(newRateB));
            Assert.IsFalse(newRateA.Equals(null));
        }
Beispiel #2
0
        public void TestGetExchangeRateOn()
        {
            var targetDate    = new DateTime(2012, 10, 5, 8, 0, 0);
            var stockExchange = new StockExchange();

            stockExchange.AddExchangeRate(StockExchange.ExchangeRate(targetDate.AddDays(-2), "CHF", "USD", 2.0M));
            stockExchange.AddExchangeRate(StockExchange.ExchangeRate(new DateTime(2012, 12, 7, 7, 0, 0), "CHF", "USD", 2.1M));
            stockExchange.AddExchangeRate(StockExchange.ExchangeRate(new DateTime(2013, 2, 8, 8, 0, 0), "CHF", "USD", 2.2M));
            Assert.AreEqual(stockExchange.GetExchangeRateOn("CHF", "USD", targetDate), StockExchange.ExchangeRate(targetDate.AddDays(-2), "CHF", "USD", 2.0M));
            Assert.AreEqual(stockExchange.GetExchangeRateOn("CHF", "CAD", targetDate), null);
        }
Beispiel #3
0
        public void TestAddExchangeRates()
        {
            var fixedNow = DateTime.Now;
            var newRate  = StockExchange.ExchangeRate(fixedNow, "CHF", "USD", 2.0M);

            Assert.AreEqual(newRate, StockExchange.ExchangeRate(fixedNow, "CHF", "USD", 2.0M));

            var offsetRate = StockExchange.ExchangeRate(DateTime.Now, "CHF", "USD", 2.1M);

            Assert.AreNotEqual(newRate, offsetRate);
        }
Beispiel #4
0
        public void TestMoneyEquality()
        {
            var stockExchange = new StockExchange();

            stockExchange.AddExchangeRate(StockExchange.ExchangeRate(DateTime.Now, "CHF", "USD", 2.0M));
            var bank = new Bank(stockExchange, new MockUpCurrencyListing(), "USD");

            Assert.IsTrue(bank.Dollar(5M).Equals(bank.Dollar(5M)));
            Assert.IsFalse(bank.Dollar(5M).Equals(bank.Franc(5M)));
            Assert.IsTrue(bank.Franc(10M).Equals(bank.Franc(10M)));
            Assert.IsFalse(bank.Dollar(5M).Equals(null));
        }
Beispiel #5
0
        public void TestGetExchangeRate()
        {
            var stockExchange = new StockExchange();

            stockExchange.AddExchangeRate(StockExchange.ExchangeRate(DateTime.Now, "CHF", "USD", 2.0M));
            stockExchange.AddExchangeRate(StockExchange.ExchangeRate(DateTime.Now.AddMilliseconds(1d), "CHF", "USD", 2.1M));
            var bank = new Bank(stockExchange, new MockUpCurrencyListing(), "USD");

            var currentRate = stockExchange.GetExchangeRate("CHF", "USD");

            Assert.AreEqual(currentRate.ConversionRate, 2.1M);
            Assert.AreEqual(bank.GetInternalExchangeRate("CHF"), currentRate);
            Assert.AreEqual(stockExchange.GetExchangeRate("CHF", "CAD"), null);
        }
Beispiel #6
0
        public void TestMixedSubtraction()
        {
            var stockExchange = new StockExchange();

            stockExchange.AddExchangeRate(StockExchange.ExchangeRate(DateTime.Now, "CHF", "USD", 2.0M));
            var bank = new Bank(stockExchange, new MockUpCurrencyListing(), "USD");

            var runCommands = new MoneyHandler();
            var result      = runCommands.Add(bank, bank.Dollar(5M), bank.Franc(-5M));

            Assert.AreEqual(result, bank.Dollar(-5M));

            result = runCommands.Add(bank, result, bank.Franc(10M));
            Assert.AreEqual(result, bank.Dollar(15M));
        }
Beispiel #7
0
        public void TestMixedMultiplication()
        {
            var stockExchange = new StockExchange();

            stockExchange.AddExchangeRate(StockExchange.ExchangeRate(DateTime.Now, "CHF", "USD", 2.0M));
            var bank = new Bank(stockExchange, new MockUpCurrencyListing(), "USD");

            var runCommands = new MoneyHandler();
            var product     = runCommands.Multiply(bank, bank.Dollar(5M), bank.Franc(5M));

            Assert.AreEqual(product, bank.Dollar(50M));

            product = runCommands.Multiply(bank, product, bank.Franc(2M));
            Assert.AreEqual(product, bank.Dollar(200M));

            product = runCommands.Undo(bank.Franc(2M));
            Assert.AreEqual(product, bank.Dollar(50M));

            product = runCommands.Redo(bank, bank.Franc(2M));
            Assert.AreEqual(product, bank.Dollar(200M));
        }