Example #1
0
 public static Mock<IAnalyzer> generateMockAnalyzer(AssetTimeframe atf, AnalysisType type, DateTime? firstRequiredDate)
 {
     Mock<IAnalyzer> mock = new Mock<IAnalyzer>();
     mock.Setup(q => q.getFirstRequiredDate()).Returns(firstRequiredDate);
     mock.Setup(q => q.getAssetTimeframe()).Returns(atf);
     mock.Setup(q => q.getAnalysisType()).Returns(type);
     return mock;
 }
Example #2
0
        public void constructor_new_instance_empty_list_of_assetTimeframes_is_created()
        {
            //Arrange.
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            mockService.Setup(c => c.GetCurrencies()).Returns(currenciesCollection());
            Currency.injectService(mockService.Object);

            //Act.
            var pair = new FxPair(DEFAULT_ID, DEFAULT_NAME, DEFAULT_BASE_CURRENCY_ID, DEFAULT_QUOTE_CURRENCY_ID);

            //Assert.
            Assert.IsNotNull(pair.AssetTimeframes);
            Assert.IsInstanceOfType(pair.AssetTimeframes, typeof(IEnumerable<AssetTimeframe>));
        }
Example #3
0
        public void getAllCurrencies_returns_proper_number_of_items()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencies()).Returns(currenciesCollection());
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            Currency.injectService(mockService.Object);

            //Act.
            var usd = Currency.GetCurrencyById(1);
            var eur = Currency.GetCurrencyById(2);
            var currencies = Currency.GetAllCurrencies();

            //Asssert.
            Assert.AreEqual(4, currencies.Count());
        }
Example #4
0
        public void getAllMarkets_returns_existing_instances()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetMarkets()).Returns(marketsCollection());
            mockService.Setup(c => c.GetMarketById(It.IsAny<int>())).Returns((int a) => getMarket(a));
            Market.injectService(mockService.Object);

            //Act.
            var fx = Market.GetMarketById(1);
            var uk = Market.GetMarketById(2);
            var markets = Market.GetAllMarkets();

            //Assert.
            Assert.IsTrue(fx == markets.SingleOrDefault(m => m.ShortName.Equals("FX")));
            Assert.IsTrue(uk == markets.SingleOrDefault(m => m.ShortName.Equals("UK")));
        }
Example #5
0
        public void getAllCurrencies_returns_existing_instances()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencies()).Returns(currenciesCollection());
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            Currency.injectService(mockService.Object);

            //Act.
            var usd = Currency.GetCurrencyById(1);
            var eur = Currency.GetCurrencyById(2);
            var currencies = Currency.GetAllCurrencies();

            //Assert.
            Assert.IsTrue(eur == currencies.SingleOrDefault(c => c.Symbol.Equals("EUR")));
            Assert.IsTrue(usd == currencies.SingleOrDefault(c => c.Symbol.Equals("USD")));
        }
Example #6
0
        public void constructor_throw_exception_if_given_currency_doesnt_exist()
        {
            //Arrange.
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            Currency.injectService(mockService.Object);

            //Act.
            var pair = new FxPair(DEFAULT_ID, DEFAULT_NAME, DEFAULT_BASE_CURRENCY_ID, 20);
        }
Example #7
0
        public void constructor_new_instance_has_proper_id_name_and_currencies()
        {
            //Arrange.
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            mockService.Setup(c => c.GetCurrencyBySymbol(It.IsAny<string>())).Returns((string a) => getCurrencyBySymbol(a));
            mockService.Setup(c => c.GetCurrencies()).Returns(currenciesCollection());
            Currency.injectService(mockService.Object);

            //Act.
            var baseCurrency = Currency.GetCurrencyBySymbol(DEFAULT_BASE_CURRENCY_SYMBOL);
            var quoteCurrency = Currency.GetCurrencyBySymbol(DEFAULT_QUOTE_CURRENCY_SYMBOL);
            var pair = new FxPair(DEFAULT_ID, DEFAULT_NAME, baseCurrency, quoteCurrency);

            //Assert.
            Assert.AreEqual(DEFAULT_ID, pair.Id);
            Assert.AreEqual(DEFAULT_NAME, pair.Name);
            Assert.IsTrue(Currency.GetCurrencyById(DEFAULT_BASE_CURRENCY_ID) == pair.BaseCurrency);
            Assert.IsTrue(Currency.GetCurrencyBySymbol(DEFAULT_QUOTE_CURRENCY_SYMBOL) == pair.QuoteCurrency);
        }
Example #8
0
        public void assetFromDto_has_the_same_properties_as_dto()
        {
            //Arrange.
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetMarketById(It.IsAny<int>())).Returns((int a) => getMarket(a));
            Market.injectService(mockService.Object);
            AssetDto dto = new AssetDto { Id = 1, IdMarket = 1, Name = "EURUSD", Symbol = "EURUSD" };

            //Act.
            Asset asset = Asset.FromDto(dto);

            //Assert.
            Assert.AreEqual(1, asset.Id);
            Assert.AreEqual("EURUSD", asset.Name);
            Assert.AreEqual("EURUSD", asset.ShortName);
        }
Example #9
0
        public void getMarket_returns_the_same_instance_each_time()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetMarketById(It.IsAny<int>())).Returns((int a) => getMarket(a));
            Market.injectService(mockService.Object);

            //Act
            var fx1 = Market.GetMarketById(1);
            var uk1 = Market.GetMarketById(2);
            var us1 = Market.GetMarketById(3);
            var fx2 = Market.GetMarketByName("Forex");
            var uk2 = Market.GetMarketBySymbol("UK");
            var fx3 = Market.GetMarketBySymbol("FX");
            var us2 = Market.GetMarketBySymbol("US");
            var fx4 = Market.GetMarketById(1);

            Assert.IsTrue(fx1 == fx2);
            Assert.IsTrue(fx1 == fx3);
            Assert.IsTrue(fx1 == fx4);
            Assert.IsTrue(uk1 == uk2);
            Assert.IsTrue(us1 == us2);
        }
Example #10
0
        public void getMarket_returns_existing_instance_by_id()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetMarketById(It.IsAny<int>())).Returns((int a) => getMarket(a));
            Market.injectService(mockService.Object);

            //Act.
            Market market = Market.GetMarketById(DEFAULT_ID);

            //Assert.
            Assert.IsNotNull(market);
            Assert.AreEqual(DEFAULT_NAME, market.Name);
            Assert.AreEqual(DEFAULT_SHORT_NAME, market.ShortName);
            Assert.AreEqual(DEFAULT_ID, market.Id);
        }
Example #11
0
        public void getMarket_returns_existing_instance_by_symbol()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(a => a.GetMarketBySymbol(DEFAULT_SHORT_NAME)).Returns(defaultMarket());
            Market.injectService(mockService.Object);

            //Act.
            Market market = Market.GetMarketBySymbol(DEFAULT_SHORT_NAME);

            //Assert.
            Assert.IsNotNull(market);
            Assert.AreEqual(DEFAULT_NAME, market.Name);
            Assert.AreEqual(DEFAULT_SHORT_NAME, market.ShortName);
            Assert.AreEqual(DEFAULT_ID, market.Id);
        }
Example #12
0
 private Mock<IQuotationService> mockedQuotationService(AssetTimeframe atf, DateTime lastAnalysisDate, AnalysisType type)
 {
     Mock<IQuotationService> obj = new Mock<IQuotationService>();
     obj.Setup(mqs => mqs.getLastCalculationDate(atf, type)).Returns(lastAnalysisDate);
     return obj;
 }
Example #13
0
        public void getMarket_after_adding_new_item_returns_existing_instance()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetMarketById(It.IsAny<int>())).Returns((int a) => getMarket(a));
            Market.injectService(mockService.Object);

            //Act.
            Market baseMarket = Market.GetMarketById(1);
            Market newMarket = Market.GetMarketById(2);
            Market baseMarketAgain = Market.GetMarketById(1);

            //Assert.
            Assert.AreSame(baseMarket, baseMarketAgain);
        }
Example #14
0
        public void getFxPair_returns_null_if_not_exist_in_repository()
        {
            const int NOT_EXISTING_ID = 20;

            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetFxPair(It.IsAny<int>())).Returns((int a) => getFxPairById(a));
            mockService.Setup(c => c.GetFxPair(It.IsAny<string>())).Returns((string a) => getFxPairBySymbol(a));

            FxPair.injectService(mockService.Object);

            //Act.
            FxPair pair = FxPair.GetFxPairById(NOT_EXISTING_ID);

            //Assert.
            Assert.IsNull(pair);
        }
Example #15
0
        public void getCurrency_after_adding_new_item_returns_existing_instance()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            Currency.injectService(mockService.Object);

            //Act.
            Currency eur = Currency.GetCurrencyById(1);
            Currency usd = Currency.GetCurrencyById(2);
            Currency eurAgain = Currency.GetCurrencyById(1);

            //Assert.
            Assert.AreSame(eur, eurAgain);
        }
Example #16
0
        public void getCurrency_returns_the_same_instance_each_time()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            Currency.injectService(mockService.Object);

            //Act
            var eur1 = Currency.GetCurrencyById(2);
            var usd1 = Currency.GetCurrencyById(1);
            var jpy1 = Currency.GetCurrencyById(3);
            var gbp1 = Currency.GetCurrencyById(4);
            var eur2 = Currency.GetCurrencyByName("Euro");
            var usd2 = Currency.GetCurrencyBySymbol("USD");
            var eur3 = Currency.GetCurrencyBySymbol("EUR");
            var jpy2 = Currency.GetCurrencyBySymbol("JPY");
            var eur4 = Currency.GetCurrencyById(2);

            Assert.IsTrue(eur1 == eur2);
            Assert.IsTrue(eur1 == eur3);
            Assert.IsTrue(eur1 == eur4);
            Assert.IsTrue(usd1 == usd2);
            Assert.IsTrue(jpy1 == jpy2);
        }
Example #17
0
        public void getFxPairs_returns_existing_instances()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetFxPair(It.IsAny<int>())).Returns((int a) => getFxPairById(a));
            mockService.Setup(c => c.GetFxPair(It.IsAny<string>())).Returns((string a) => getFxPairBySymbol(a));
            mockService.Setup(c => c.GetFxPairs()).Returns(pairsCollection());
            FxPair.injectService(mockService.Object);

            //Act.
            var eurusd = FxPair.GetFxPairById(1);
            var usdjpy = FxPair.GetFxPairById(2);
            var fxPairs = FxPair.GetAllFxPairs();

            //Assert.
            Assert.IsTrue(eurusd == fxPairs.SingleOrDefault(c => c.Name.Equals("EURUSD")));
            Assert.IsTrue(usdjpy == fxPairs.SingleOrDefault(c => c.Name.Equals("USDJPY")));
        }
Example #18
0
        public void getFxPairs_returns_proper_number_of_items()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetFxPair(It.IsAny<int>())).Returns((int a) => getFxPairById(a));
            mockService.Setup(c => c.GetFxPair(It.IsAny<string>())).Returns((string a) => getFxPairBySymbol(a));
            mockService.Setup(c => c.GetFxPairs()).Returns(pairsCollection());
            FxPair.injectService(mockService.Object);

            //Act.
            var eurusd = FxPair.GetFxPairById(1);
            var usdjpy = FxPair.GetFxPairById(2);
            var fxPairs = FxPair.GetAllFxPairs();

            //Asssert.
            Assert.AreEqual(5, fxPairs.Count());
        }
Example #19
0
        public void constructor_with_currencies_ids_assign_proper_currencies()
        {
            //Arrange.
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            mockService.Setup(c => c.GetCurrencies()).Returns(currenciesCollection());
            Currency.injectService(mockService.Object);

            //Act.
            var pair = new FxPair(DEFAULT_ID, DEFAULT_NAME, DEFAULT_BASE_CURRENCY_ID, DEFAULT_QUOTE_CURRENCY_ID);

            //Assert.
            Assert.IsTrue(Currency.GetCurrencyById(DEFAULT_BASE_CURRENCY_ID) == pair.BaseCurrency);
            Assert.IsTrue(Currency.GetCurrencyById(DEFAULT_QUOTE_CURRENCY_ID) == pair.QuoteCurrency);
        }
Example #20
0
        public void constructor_throw_exception_if_the_same_currencies_given()
        {
            //Arrange.
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            Currency.injectService(mockService.Object);

            //Act.
            Currency currency = Currency.GetCurrencyById(1);
            var pair = new FxPair(DEFAULT_ID, DEFAULT_NAME, currency, currency);
        }
Example #21
0
        public void getFxPair_after_adding_new_item_returns_existing_instance()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetFxPair(It.IsAny<int>())).Returns((int a) => getFxPairById(a));
            mockService.Setup(c => c.GetFxPair(It.IsAny<string>())).Returns((string a) => getFxPairBySymbol(a));
            FxPair.injectService(mockService.Object);

            //Act.
            FxPair eurusd = FxPair.GetFxPairById(1);
            FxPair usdjpy = FxPair.GetFxPairById(2);
            FxPair eurusdAgain = FxPair.GetFxPairById(1);

            //Assert.
            Assert.AreSame(eurusd, eurusdAgain);
        }
Example #22
0
        public void getFxPair_returns_existing_instance_by_symbol()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetFxPair(It.IsAny<int>())).Returns((int a) => getFxPairById(a));
            mockService.Setup(c => c.GetFxPair(It.IsAny<string>())).Returns((string a) => getFxPairBySymbol(a));
            FxPair.injectService(mockService.Object);

            //Act.
            FxPair pair = FxPair.GetFxPairBySymbol(DEFAULT_NAME);

            //Assert.
            Assert.IsNotNull(pair);
            Assert.AreEqual(DEFAULT_ID, pair.Id);
            Assert.AreEqual(DEFAULT_NAME, pair.Name);
        }
Example #23
0
 private void arrangeFxMoq()
 {
     //Arrange
     Mock<IMarketService> mockService = new Mock<IMarketService>();
     mockService.Setup(c => c.GetFxPair(It.IsAny<int>())).Returns((int a) => getFxPairById(a));
     mockService.Setup(c => c.GetFxPair(It.IsAny<string>())).Returns((string a) => getFxPairBySymbol(a));
     mockService.Setup(c => c.GetFxPairs()).Returns(pairsCollection());
     FxPair.injectService(mockService.Object);
 }
Example #24
0
        public void fxPair_fromDto_has_the_same_properties_as_dto()
        {
            //Arrange.
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            Currency.injectService(mockService.Object);
            FxPairDto dto = new FxPairDto { Id = 1, Name = "EURUSD", BaseCurrency = 1, QuoteCurrency = 2, IsActive = true };

            //Act.
            var pair = FxPair.FromDto(dto);

            //Assert.
            Assert.AreEqual(1, pair.Id);
            Assert.AreEqual("EURUSD", pair.Name);
            Assert.AreEqual(true, pair.IsFx);
            Assert.AreEqual(true, pair.IsActive);
            Assert.AreEqual(1, pair.BaseCurrency.Id);
            Assert.AreEqual(2, pair.QuoteCurrency.Id);
            Assert.IsTrue(Currency.GetCurrencyById(1) == pair.BaseCurrency);
            Assert.IsTrue(Currency.GetCurrencyById(2) == pair.QuoteCurrency);
        }
Example #25
0
        private IEnumerable<FxPair> pairsCollection()
        {
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            Currency.injectService(mockService.Object);

            List<FxPair> fxPairs = new List<FxPair>();
            fxPairs.Add(new FxPair(1, "EURUSD", 2, 1));
            fxPairs.Add(new FxPair(2, "USDJPY", 1, 3));
            fxPairs.Add(new FxPair(3, "GBPUSD", 4, 1));
            fxPairs.Add(new FxPair(4, "EURGBP", 2, 4));
            fxPairs.Add(new FxPair(5, "EURJPY", 2, 3));
            return fxPairs;
        }
Example #26
0
        public void getFxPair_returns_the_same_instance_each_time()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetFxPair(It.IsAny<int>())).Returns((int a) => getFxPairById(a));
            mockService.Setup(c => c.GetFxPair(It.IsAny<string>())).Returns((string a) => getFxPairBySymbol(a));
            FxPair.injectService(mockService.Object);

            //Act
            var eurusd1 = FxPair.GetFxPairById(1);
            var usdjpy1 = FxPair.GetFxPairById(2);
            var eurjpy1 = FxPair.GetFxPairById(5);
            var gbpusd1 = FxPair.GetFxPairById(3);
            var eurusd2 = FxPair.GetFxPairBySymbol("EURUSD");
            var usdjpy2 = FxPair.GetFxPairBySymbol("USDJPY");
            var eurusd3 = FxPair.GetFxPairBySymbol("EURUSD");
            var eurjpy2 = FxPair.GetFxPairBySymbol("EURJPY");
            var eurusd4 = FxPair.GetFxPairById(1);

            Assert.IsTrue(eurusd1 == eurusd2);
            Assert.IsTrue(eurusd1 == eurusd3);
            Assert.IsTrue(eurusd1 == eurusd4);
            Assert.IsTrue(usdjpy1 == usdjpy2);
            Assert.IsTrue(eurjpy1 == eurjpy2);
        }
Example #27
0
        public void getAllMarkets_returns_proper_number_of_markets()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetMarkets()).Returns(marketsCollection());
            mockService.Setup(c => c.GetMarketById(It.IsAny<int>())).Returns((int a) => getMarket(a));
            Market.injectService(mockService.Object);

            //Act.
            var fx = Market.GetMarketById(1);
            var uk = Market.GetMarketById(2);
            var markets = Market.GetAllMarkets();

            //Asssert.
            Assert.AreEqual(3, markets.Count());
        }
Example #28
0
        public void getCurrency_returns_existing_instance_by_symbol()
        {
            //Arrange
            Mock<IMarketService> mockService = new Mock<IMarketService>();
            mockService.Setup(c => c.GetCurrencyById(It.IsAny<int>())).Returns((int a) => getCurrency(a));
            Currency.injectService(mockService.Object);

            //Act.
            Currency currency = Currency.GetCurrencyBySymbol(DEFAULT_SYMBOL);

            //Assert.
            Assert.IsNotNull(currency);
            Assert.AreEqual(DEFAULT_ID, currency.Id);
            Assert.AreEqual(DEFAULT_NAME, currency.Name);
            Assert.AreEqual(DEFAULT_SYMBOL, currency.Symbol);
        }