Exemplo n.º 1
0
        public void Get_StrategyParam()
        {
            //Организация - создание стратегии
            IStrategy strategyMock = new Examples.Strategies.StrategyMock();
            StrategyInfo strategyInfo = new StrategyInfo { Id = 1, Name = "Mock", TypeName = "RMarket.Examples.Strategies.StrategyMock, RMarket.Examples" };
            Instance instance = new Instance { Id = 1, StrategyInfoId = strategyInfo.Id, StrategyInfo = strategyInfo, GroupID = new Guid("a76dc9b4-8816-438e-aed3-c123374c2e3e") };

            //Действие - Получение параметров
            IEnumerable<ParamEntity> strategyParams = StrategyHelper.GetStrategyParams(instance);

            ParamEntity param1 = strategyParams.FirstOrDefault(t => t.FieldName == "decimalParam");
            ParamEntity param2 = strategyParams.FirstOrDefault(t => t.FieldName == "period3");

            //Утверждение - Количество параметров
            Assert.AreEqual(6, strategyParams.Count());

            Assert.AreEqual(param1.DisplayName, "decimal param");
            Assert.AreEqual(param1.FieldValue, 30.25m);
            Assert.IsInstanceOfType(param1.FieldValue, typeof(Decimal));
            Assert.AreEqual(param1.Description, "Какой-то параметр типа Decimal");

            Assert.AreEqual(param2.DisplayName, "period3");
            Assert.AreEqual(param2.FieldValue, 30);
            Assert.AreEqual(param2.Description, null);

        }
Exemplo n.º 2
0
        public void BeginTest_HttpPost()
        {
            SessionHelper.session = new SessionStateMock();
            StrategyInfo strategyInfo = new StrategyInfo { Id = 1, Name = "Mock", TypeName = "RMarket.Examples.Strategies.StrategyMock, RMarket.Examples" };
            Ticker ticker = new Ticker { Id = 1, Code = "SBER" };
            TimeFrame timeFrame = new TimeFrame { Id = 11, Name = "1 day" };
            Instance instance = new Instance
            {
                Id = 1,
                GroupID = new Guid("a76dc9b4-8816-438e-aed3-c123374c2e3e"),
                StrParams = "[{\"FieldName\":\"withSleep\",\"FieldValue\":true}]",
                StrategyInfoId = strategyInfo.Id,
                StrategyInfo = strategyInfo,
                TickerId=ticker.Id,
                Ticker = ticker,
                TimeFrameId=timeFrame.Id,
                TimeFrame=timeFrame
            };
            Mock<IInstanceRepository> instanceRepoMock = new Mock<IInstanceRepository>();
            instanceRepoMock.Setup(m => m.Instances).Returns(new List<Instance>
            {
                instance
            }.AsQueryable());
            instanceRepoMock.Setup(m => m.Find(1)).Returns(instance);

            Mock<ICandleRepository> candleRepoMock = new Mock<ICandleRepository>();
            candleRepoMock.Setup(m => m.Candles).Returns(new List<Candle>
            {
                new Candle(ticker.Id,timeFrame.Id,new DateTime(2015,1,1),10m,15m,8m,11m,0),
                new Candle(ticker.Id,timeFrame.Id,new DateTime(2015,1,2),11m,15m,8m,11m,0),
                new Candle(ticker.Id,timeFrame.Id,new DateTime(2015,1,3),11m,16m,10m,15m,0),
            }.AsQueryable());

            TesterModel model = new TesterModel
            {
                InstanceId = 1,
                DateFrom=new DateTime(2015,1,1),
                DateTo=new DateTime(2015,2,1)
            };

            TesterController controller = CreateTestManagerController(instanceRepoMock.Object, candleRepoMock.Object);
           
            //Действие
            ActionResult result = controller.BeginTest(model);

            // Утверждение
            //1. В сесии есть объект результата
            List<TestResult> testResultCollection = (List<TestResult>)SessionHelper.session["TestResultCollection"];
            Assert.AreNotEqual(null, testResultCollection);

            //2. Проверка реквизитов сформированной стратегии
            IStrategy strategy = testResultCollection.FirstOrDefault(t => t.Id == 1).Strategy;
            Assert.AreEqual(ticker, strategy.Instr.Ticker);
            Assert.AreEqual(timeFrame, strategy.Instr.TimeFrame);

            //3. Стратегия стартована
            Assert.AreEqual(true, strategy.Manager.IsStarted);

        }
Exemplo n.º 3
0
        public void Get_Strategy_With_Save_Param()
        {
            //Организация - создание стратегии
            StrategyInfo strategyInfo = new StrategyInfo { Id = 1, Name = "Mock", TypeName = "RMarket.Examples.Strategies.StrategyMock, RMarket.Examples" };
            Instance instance = new Instance { Id = 1, StrategyInfoId = strategyInfo.Id, StrategyInfo = strategyInfo, GroupID = new Guid("a76dc9b4-8816-438e-aed3-c123374c2e3e"), StrParams = "[{\"FieldName\":\"decimalParam\",\"FieldValue\":30.26}]" };

            //Действие - Получение параметров
            IStrategy strategy = StrategyHelper.CreateStrategy(instance);

            //Утверждение - значения параметров стратегии
            var strategyMock = (Examples.Strategies.StrategyMock)strategy;

            Assert.AreEqual(strategyMock.period1, 5);
            Assert.AreEqual(strategyMock.decimalParam, 30.26m);
            Assert.IsInstanceOfType(strategyMock.decimalParam, typeof(Decimal));
        }
Exemplo n.º 4
0
        public void Can_Edit_Instance()
        {
            // Организация - создание имитированного хранилища данных            
            StrategyInfo strategyInfo = new StrategyInfo { Id = 1, Name = "Mock", TypeName = "RMarket.Examples.Strategies.StrategyMock, RMarket.Examples" };
            Instance instance1 = new Instance { Id = 1, GroupID = new Guid("a76dc9b4-8816-438e-aed3-c123374c2e3e"), StrategyInfoId = 1, StrategyInfo = strategyInfo };
            Instance instance2 = new Instance { Id = 2, GroupID = new Guid("a76dc9b4-8816-438e-aed3-c123374c2e3e"), StrategyInfoId = 1, StrategyInfo = strategyInfo };
            Instance instance3 = new Instance { Id = 3, GroupID = new Guid("a8a15362-1c4b-4f5a-97a3-50e7484d9bac"), StrategyInfoId = 1, StrategyInfo = strategyInfo };

            Mock<IInstanceRepository> instanceRepoMock = new Mock<IInstanceRepository>();
            instanceRepoMock.Setup(m => m.Instances).Returns(new List<Instance>
            {
                instance1,
                instance2,
                instance3,
            }.AsQueryable());
            instanceRepoMock.Setup(m => m.Find(1)).Returns(instance1);
            instanceRepoMock.Setup(m => m.Find(2)).Returns(instance2);
            instanceRepoMock.Setup(m => m.Find(3)).Returns(instance3);
            instanceRepoMock.Setup(m => m.Find(6)).Returns<object>(null);


            // Организация - создание контроллера
            InstanceController controller = CreateInstanceController(instanceRepoMock.Object, null, null, null);

            //Действие
            InstanceModel model1 = ((ViewResult)controller.Edit( 1)).ViewData.Model as InstanceModel;
            InstanceModel model2 = ((ViewResult)controller.Edit( 2)).ViewData.Model as InstanceModel;
            InstanceModel model3 = ((ViewResult)controller.Edit( 3)).ViewData.Model as InstanceModel;
            ActionResult result6 = controller.Edit( 6);

            // Утверждение - Редактируем верные объекты из списка
            Assert.AreEqual(1, model1.Id);
            Assert.AreEqual(2, model2.Id);
            Assert.AreEqual(3, model3.Id);

            //Неверный объект 
            Assert.IsInstanceOfType(result6, typeof(ActionResult));

        }
Exemplo n.º 5
0
        public void CreateFirstGeneration()
        {
            //!!! Долго

            Ticker ticker = new Ticker
            {
                Id = 1,
                Name = "sber",
                Code = "sber",
            };
            TimeFrame timeFrame = new TimeFrame
            {
                Id = 10,
                Name = "10",
                ToMinute = 10
            };
            StrategyInfo strategyInfo = new StrategyInfo
            {
                Id = 20,
                Name = "Mock",
                TypeName = "RMarket.Examples.Strategies.StrategyMock, RMarket.Examples"
            };

            SelectionModel selection = new SelectionModel
            {
                Id = 30,
                Name = "TestSelection",
                TickerId = ticker.Id,
                Ticker = ticker,
                TimeFrameId = timeFrame.Id,
                TimeFrame=timeFrame,
                StrategyInfoId = strategyInfo.Id,
                StrategyInfo=strategyInfo,
                AmountResults = 10,
                Balance = 1000,
                CreateDate = new DateTime(2016, 1, 1),
                DateFrom = new DateTime(2016, 1, 1),
                DateTo = new DateTime(2016, 1, 10),
                Description = "for test",
                GroupID = new Guid("7ada9499-cb8e-44ad-862a-a93920ff4760"),
                Slippage = 0.01M,
                Rent = 0.1M,
                SelectionParams = new List<ParamSelection>
                {
                    new ParamSelection
                    {
                        FieldName="Param1",
                        TypeName = "System.Int32",
                        ValueMin = 6,
                        ValueMax=10
                    },
                    new ParamSelection
                    {
                        FieldName="Param2",
                        ValueMin = (byte)1,
                        TypeName = "System.Byte",
                        ValueMax=(byte)5
                    },
                    new ParamSelection
                    {
                        FieldName="OtherParam",
                        TypeName = "System.Boolean",
                        ValueMin = true,
                        ValueMax=true
                    }
                    //Добавить вещественный
                }
            };

            List<InstanceModel> instances1 = OptimizationHelper.CreateFirstGeneration(selection);

            Assert.AreEqual(10, instances1.Count);
            Assert.AreEqual(1, instances1[0].TickerId);
            Assert.AreEqual(10, instances1[0].TimeFrameId);
            Assert.AreEqual(20, instances1[0].StrategyInfoId);
            Assert.AreEqual(30, instances1[0].SelectionId);

            Assert.AreEqual(true, instances1[0].StrategyParams.Any(p=>p.FieldName== "OtherParam" && (bool)p.FieldValue==true));
            Assert.AreEqual(true, instances1[0].StrategyParams.Any(p=>p.FieldName== "Param1" && (int)p.FieldValue >= 6 && (int)p.FieldValue <= 10));
            Assert.AreEqual(true, instances1[0].StrategyParams.Where(p=>p.FieldName == "Param2").Single().FieldValue.GetType() == typeof(byte));

        }