예제 #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());
        }
예제 #2
0
파일: Asset.cs 프로젝트: mielk/waluty
 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;
 }
예제 #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());
        }
예제 #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());
        }
예제 #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>));
 }
예제 #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);
        }
예제 #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;
        }
예제 #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");
            }
        }
예제 #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);
        }
예제 #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);
 }
예제 #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);
 }
예제 #12
0
 public IProcessService GetProcessService(Asset asset, Timeframe timeframe)
 {
     return GetProcessService(new AssetTimeframe(asset, timeframe));
 }
예제 #13
0
 public AssetTimeframe(Asset asset, Timeframe timeframe)
 {
     loadParams(asset, timeframe);
 }
예제 #14
0
 private void loadParams(Asset asset, Timeframe timeframe)
 {
     this.asset = asset;
     this.timeframe = timeframe;
 }
예제 #15
0
 public ProcessService(Asset asset, Timeframe timeframe)
 {
     this.assetTimeframe = new AssetTimeframe(asset, timeframe);
 }
예제 #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));
        }
예제 #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);
 }
예제 #18
0
 private static object jsonAsset(Asset asset)
 {
     return new
     {
         id = asset.Id,
         name = asset.Name,
         asset = asset
     };
 }
예제 #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));
        }
예제 #20
0
 public static Asset testAsset()
 {
     var asset = new Asset(1, "asset");
     return asset;
 }