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; }
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); }
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>)); }
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()); }
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); }
public void fetchData_for_firstRequiredDate_equal_to_null_proper_method_of_dataService_is_called() { AssetTimeframe atf = UnitTestTools.testAssetTimeframe(); Dictionary<AnalysisType, IAnalyzer> analyzers = new Dictionary<AnalysisType, IAnalyzer>(); DateTime firstRequired = new DateTime(2016, 8, 1); analyzers.Add(AnalysisType.Price, UnitTestTools.generateMockAnalyzer(atf, AnalysisType.Price, firstRequired).Object); analyzers.Add(AnalysisType.MACD, UnitTestTools.generateMockAnalyzer(atf, AnalysisType.MACD, null).Object); analyzers.Add(AnalysisType.ADX, UnitTestTools.generateMockAnalyzer(atf, AnalysisType.ADX, firstRequired).Object); Mock<IDataService> mockedDataService = new Mock<IDataService>(); QuotationService qService = new QuotationService(); qService.injectDataService(mockedDataService.Object); DataItem[] items = qService.fetchData(analyzers); mockedDataService.Verify(x => x.GetDataItems(atf, null, null, analyzers.Keys), Times.Exactly(1)); }
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"))); }
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"))); }
public void run_proper_items_are_full_calculated() { int itemsForAnalysis = 240; TimeframeSymbol timeframe = TimeframeSymbol.M5; AnalysisType analysisType = AnalysisType.Price; AssetTimeframe atf = UnitTestTools.testAssetTimeframe(); PriceAnalyzer analyzer = new PriceAnalyzer(atf); DateTime startDate = (new DateTime(2016, 4, 21, 12, 30, 0)).Proper(timeframe); DateTime lastAnalysisDate = (new DateTime(2016, 4, 23, 15, 0, 0)).Proper(timeframe); DateTime endDate = (new DateTime(2016, 4, 27, 15, 30, 0)).Proper(timeframe); DataItem[] items = UnitTestTools.getDataItemsArray(timeframe, startDate, endDate, UnitTestTools.createAnalysisTypeList(new AnalysisType[] { AnalysisType.Price })); Mock<IQuotationService> mockQuotationService = mockedQuotationService(atf, lastAnalysisDate, AnalysisType.Price); mockQuotationService.Setup(q => q.getLastCalculationDate(atf, analysisType)).Returns(lastAnalysisDate); Mock<IPriceProcessor> mockedProcessor = new Mock<IPriceProcessor>(); analyzer.injectProcessor(mockedProcessor.Object); analyzer.injectQuotationService(mockQuotationService.Object); DateTime expectedFirstRightOnlyItem = lastAnalysisDate.addTimeUnits(timeframe, -itemsForAnalysis); DateTime expectedLastRightOnlyItem = lastAnalysisDate; analyzer.Analyze(items); //Test 1. DateTime d = startDate; while (d.CompareTo(endDate) < 0) { d = d.getNext(timeframe); DataItem dataItem = items.SingleOrDefault(i => i.Date.Equals(d)); if (dataItem == null) { throw new ArgumentNullException(string.Format("Data item for [0] has not been found", d.ToString())); } if (d.CompareTo(expectedLastRightOnlyItem) > 0) { mockedProcessor.Verify(p => p.runFull(It.IsAny<IAnalyzer>(), dataItem, atf), Times.Exactly(1)); } else { mockedProcessor.Verify(p => p.runFull(It.IsAny<IAnalyzer>(), dataItem, atf), Times.Exactly(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); }
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); }
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); }
public void getMarket_returns_null_if_not_exist_in_repository() { const int NOT_EXISTING_ID = 20; //Arrange Mock<IMarketService> mockService = new Mock<IMarketService>(); Market.injectService(mockService.Object); //Act. Market market = Market.GetMarketById(NOT_EXISTING_ID); //Assert. Assert.IsNull(market); }
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); }
public void getCurrency_returns_null_if_not_exist_in_repository() { const int NOT_EXISTING_ID = 20; //Arrange Mock<IMarketService> mockService = new Mock<IMarketService>(); Currency.injectService(mockService.Object); //Act. Currency currency = Currency.GetCurrencyById(NOT_EXISTING_ID); //Assert. Assert.IsNull(currency); }
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); }
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); }
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); }
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); }
private Mock<IQuotationService> mockedQuotationService() { Mock<IQuotationService> quotationService = new Mock<IQuotationService>(); ProcessServiceFactory.Instance().GetQuotationService(quotationService.Object); return quotationService; }
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); }
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); }
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); }
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()); }
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); }
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); }
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; }
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; }
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()); }
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); }