Exemplo n.º 1
0
        public void if_timeframe_is_null_isValid_returns_false()
        {
            Asset asset = new Asset(1, "x");
            AssetTimeframe atf = new AssetTimeframe(asset, null);

            Assert.IsFalse(atf.isValid());
        }
Exemplo n.º 2
0
 public static Asset FromDto(AssetDto dto)
 {
     Asset asset = new Asset(dto.Id, dto.Name);
     asset.ShortName = (dto.Symbol == null || dto.Symbol.Length == 0 ? dto.Name : dto.Symbol);
     asset.setMarket(dto.IdMarket);
     return asset;
 }
Exemplo n.º 3
0
        public void function_returns_proper_symbol()
        {
            Asset asset = new Asset(1, "ABC") { ShortName = "ABC" };
            Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M30);
            AssetTimeframe atf = new AssetTimeframe(asset, timeframe);

            Assert.AreEqual("ABC_M30", atf.Symbol());
        }
Exemplo n.º 4
0
        public void if_both_asset_and_timeframe_are_set_isValid_returns_true()
        {
            Asset asset = new Asset(1, "x");
            Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M30);
            AssetTimeframe atf = new AssetTimeframe(asset, timeframe);

            Assert.IsTrue(atf.isValid());
        }
Exemplo n.º 5
0
 public void constructor_new_instance_empty_list_of_assetTimeframes_is_created()
 {
     const int ID = 2;
     const string NAME = "name";
     var asset = new Asset(ID, NAME);
     Assert.IsNotNull(asset.AssetTimeframes);
     Assert.IsInstanceOfType(asset.AssetTimeframes, typeof(IEnumerable<AssetTimeframe>));
 }
Exemplo n.º 6
0
        public void constructor_new_instance_has_proper_id_and_name()
        {
            const int ID = 2;
            const string NAME = "name";
            var asset = new Asset(ID, NAME);

            Assert.AreEqual(ID, asset.Id);
            Assert.AreEqual(NAME, asset.Name);
        }
Exemplo n.º 7
0
        public Dictionary<AnalysisType, IAnalyzer> getAnalyzers(Asset asset, Timeframe timeframe, IEnumerable<AnalysisType> types)
        {
            AssetTimeframe atf = new AssetTimeframe(asset, timeframe);
            var dict = new Dictionary<AnalysisType, IAnalyzer>();
            foreach (var type in types)
            {
                IAnalyzer analyzer = getAnalyzer(type, atf);
                dict.Add(type, analyzer);
            }

            return dict;
        }
Exemplo n.º 8
0
        public void getAnalyzers_returns_the_proper_analyzers_for_the_given_analysis_types()
        {
            AnalyzerFactory factory = AnalyzerFactory.Instance();
            Asset asset = new Asset(1, "a");
            Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M5);
            AnalysisType[] typesArr = new AnalysisType[] { AnalysisType.Price, AnalysisType.MACD, AnalysisType.Trendline };
            IEnumerable<AnalysisType> types = new List<AnalysisType>(typesArr);

            var analyzers = factory.getAnalyzers(asset, timeframe, types);

            //Check number of items in result dictionary.
            Assert.AreEqual(typesArr.Length, analyzers.Count);

            //Check if Price analyzers is correctly set.
            try
            {
                IAnalyzer analyzer;
                analyzers.TryGetValue(AnalysisType.Price, out analyzer);
                Assert.IsTrue(typeof(IPriceAnalyzer).IsAssignableFrom(analyzer.GetType()));
            }
            catch (ArgumentNullException)
            {
                Assert.Fail("Price analyzer not found");
            }

            //Check if MACD analyzers is correctly set.
            try
            {
                IAnalyzer analyzer;
                analyzers.TryGetValue(AnalysisType.MACD, out analyzer);
                Assert.IsTrue(typeof(IMacdAnalyzer).IsAssignableFrom(analyzer.GetType()));
            }
            catch (ArgumentNullException)
            {
                Assert.Fail("MACD analyzer not found");
            }

            //Check if Trendline analyzers is correctly set.
            try
            {
                IAnalyzer analyzer;
                analyzers.TryGetValue(AnalysisType.Trendline, out analyzer);
                Assert.IsTrue(typeof(ITrendlineAnalyzer).IsAssignableFrom(analyzer.GetType()));
            }
            catch (ArgumentNullException)
            {
                Assert.Fail("Trendline analyzer not found");
            }
        }
Exemplo n.º 9
0
        public void after_setup_properties_are_correctly_set()
        {
            Asset asset = new Asset(1, "USD");
            Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M5);
            AnalysisType[] types = new AnalysisType[] { AnalysisType.Price };

            Mock<IQuotationService> mockQuotationService = UnitTestTools.mockedQuotationService();
            mockQuotationService.Setup(q => q.getLastCalculationDate(It.IsAny<string>(), It.IsAny<string>())).Returns(new DateTime());

            var service = new ProcessService(asset, timeframe);
            service.Setup(types);

            Assert.AreEqual(service.getAsset(), asset);
            Assert.AreEqual(service.getTimeframe(), timeframe);
        }
Exemplo n.º 10
0
 public void run_if_there_is_no_analyzers_assigned_exception_is_thrown()
 {
     Asset asset = new Asset(1, "USD");
     Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M5);
     var service = new ProcessService(asset, timeframe);
     AnalysisType[] types = new AnalysisType[] { };
     service.Setup(types);
     service.Run(true);
 }
Exemplo n.º 11
0
 public static IAnalyzer getAnalyzer(this AnalysisType type, Asset asset, Timeframe timeframe)
 {
     AssetTimeframe atf = new AssetTimeframe(asset, timeframe);
     return AnalyzerFactory.Instance().getAnalyzer(type, atf);
 }
Exemplo n.º 12
0
 public IProcessService GetProcessService(Asset asset, Timeframe timeframe)
 {
     return GetProcessService(new AssetTimeframe(asset, timeframe));
 }
Exemplo n.º 13
0
 public AssetTimeframe(Asset asset, Timeframe timeframe)
 {
     loadParams(asset, timeframe);
 }
Exemplo n.º 14
0
 private void loadParams(Asset asset, Timeframe timeframe)
 {
     this.asset = asset;
     this.timeframe = timeframe;
 }
Exemplo n.º 15
0
 public ProcessService(Asset asset, Timeframe timeframe)
 {
     this.assetTimeframe = new AssetTimeframe(asset, timeframe);
 }
Exemplo n.º 16
0
        public void if_quotationService_returns_empty_array_of_data_items_Run_returns_false()
        {
            var mockQuotationService = UnitTestTools.mockedQuotationService();
            DataItem[] items = new DataItem[] { };
            mockQuotationService.Setup(q => q.fetchData(It.IsAny<Dictionary<AnalysisType, IAnalyzer>>())).Returns(items);

            Asset asset = new Asset(1, "USD");
            Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M15);
            ProcessService service = new ProcessService(asset, timeframe);
            AnalysisType[] types = new AnalysisType[] { AnalysisType.Price };
            service.Setup(types);

            Assert.IsFalse(service.Run(true));
        }
Exemplo n.º 17
0
 public void run_if_timeframe_is_empty_exception_is_thrown()
 {
     Asset asset = new Asset(1, "USD");
     Timeframe timeframe = null;
     var service = new ProcessService(asset, timeframe);
     AnalysisType[] types = new AnalysisType[] { AnalysisType.MACD, AnalysisType.Price };
     service.Setup(types);
     service.Run(true);
 }
Exemplo n.º 18
0
 private static object jsonAsset(Asset asset)
 {
     return new
     {
         id = asset.Id,
         name = asset.Name,
         asset = asset
     };
 }
Exemplo n.º 19
0
        public void quotationProcessor_is_called_once_for_loading_data()
        {
            Asset asset = new Asset(1, "USD");
            Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M15);
            ProcessService service = new ProcessService(asset, timeframe);
            var mockQuotationService = UnitTestTools.mockedQuotationService();
            AnalysisType[] types = new AnalysisType[] { AnalysisType.Price };
            service.injectQuotationService(mockQuotationService.Object);
            service.Setup(types);
            service.Run(true);

            mockQuotationService.Verify(x => x.fetchData(It.IsAny<Dictionary<AnalysisType, IAnalyzer>>()), Times.Exactly(1));
        }
Exemplo n.º 20
0
 public static Asset testAsset()
 {
     var asset = new Asset(1, "asset");
     return asset;
 }