예제 #1
0
        public void Method_SetQueryList()
        {
            // arrange
            var queryType = QueryType.SetProperty;

            string[] keys = { "key1", "key2", "key3" };
            var      list = new List <QueryInfo>()
            {
                new QueryInfo(queryType, keys[0], string.Empty, string.Empty, null, null),
                new QueryInfo(queryType, keys[1], string.Empty, string.Empty, null, null),
                new QueryInfo(queryType, keys[2], string.Empty, string.Empty, null, null)
            };

            UnitTestHelper.StartUp();

            // act
            UnitTestHelper.QueryHandler.SetQueryList(list);

            // assert
            Assert.IsNotNull(UnitTestHelper.QueryHandler.QueryList);
            Assert.AreEqual(list.Count, UnitTestHelper.QueryHandler.QueryList.Count);
            for (int i = 0; i < list.Count; i++)
            {
                Assert.AreEqual(list[i].QueryKey, UnitTestHelper.QueryHandler.QueryList[i].QueryKey);
            }
        }
예제 #2
0
        public void Method_FindDelegateType()
        {
            // arrange
            string[,] names =
            {
                { "TimedBarsResolved", "_ICQGCELEvents_TimedBarsResolvedEventHandler" },
                { "TimedBarsAdded",    "_ICQGCELEvents_TimedBarsAddedEventHandler"    },
                { "TimedBarsUpdated",  "_ICQGCELEvents_TimedBarsUpdatedEventHandler"  }
            };
            Type[] types = new Type[names.GetLength(0)];
            UnitTestHelper.StartUp();

            // act
            var nullType = QueryHandler.FindDelegateType(UnitTestHelper.QueryHandler.CQGAssembly, "name");

            for (int i = 0; i < types.Length; i++)
            {
                types[i] = QueryHandler.FindDelegateType(UnitTestHelper.QueryHandler.CQGAssembly, names[i, 0]);
            }

            // assert
            Assert.IsNull(nullType);
            for (int i = 0; i < types.Length; i++)
            {
                Assert.IsNotNull(types[i]);
                Assert.AreEqual(names[i, 1], types[i].Name);
            }
        }
예제 #3
0
        public void Method_GetAnswerData()
        {
            // arrange
            AnswerInfo answer   = default(AnswerInfo);
            string     id       = "key";
            bool       isAnswer = default(bool);
            string     name     = "name";

            Core.LogChange += CQG_LogChange_Mock;
            var answerHelper = new AnswerHelper();

            UnitTestHelper.StartUp();
            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();

            // act
            Task.Run(async() =>
            {
                await AnswerHandler.PushAnswerAsync(new AnswerInfo(id, string.Empty, name));
                answer = answerHelper.GetAnswerData(id, out isAnswer);
            }).GetAwaiter().GetResult();

            // assert
            Assert.IsTrue(isAnswer);
            Assert.AreEqual(id, answer.AnswerKey);
        }
예제 #4
0
        public void Method_DCEventHandler()
        {
            // arrange
            string id        = "keyDCEventHandler";
            bool   isAnswer  = default(bool);
            string name      = "name";
            var    argValues = new Dictionary <int, object>()
            {
                { 0, "value1" }, { 1, "value2" }
            };

            Core.LogChange += CQG_LogChange_Mock;
            var answerHelper = new AnswerHelper();

            UnitTestHelper.StartUp();
            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();

            // act
            Task.Run(async() =>
            {
                await AnswerHandler.PushAnswerAsync(new AnswerInfo(id, string.Empty, name, null, argValues));
            }).GetAwaiter().GetResult();
            var answer = answerHelper.GetAnswerData(id, out isAnswer);

            // assert
            Assert.IsTrue(isAnswer);
            Assert.AreEqual(id, answer.AnswerKey);
            Assert.IsNotNull(answer.ArgValues);
            Assert.AreEqual("value1", answer.ArgValues[0]);
            Assert.AreEqual("value2", answer.ArgValues[1]);
        }
예제 #5
0
        public void MethodAsync_RemoveOneAnswerItem()
        {
            // arrange
            string id       = "key";
            bool   isAnswer = default(bool);
            string name     = "name";

            Core.LogChange += CQG_LogChange_Mock;
            var answerHelper = new AnswerHelper();

            UnitTestHelper.StartUp();
            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();

            Task.Run(async() =>
            {
                // act
                await AnswerHandler.PushAnswerAsync(new AnswerInfo(id, string.Empty, name, null, null));
                isAnswer = await answerHelper.CheckAnswerAsync(id);
                await answerHelper.RemoveAnswerAsync(id);
                isAnswer = await answerHelper.CheckAnswerAsync(id);
            }).GetAwaiter().GetResult();

            // assert
            Assert.AreEqual(isAnswer, false);
        }
예제 #6
0
        public void MethodAsync_RemoveOneQueryItem()
        {
            // arrange
            var    qType   = QueryType.CallMethod;
            string id      = "key";
            bool   isQuery = default(bool);
            string name    = "name";

            Core.LogChange += CQG_LogChange_Mock;
            var queryHelper = new QueryHelper();

            UnitTestHelper.StartUp();

            Task.Run(async() =>
            {
                // act
                await queryHelper.PushQueryAsync(new QueryInfo(qType, id, string.Empty, name, null, null));
                isQuery = await UnitTestHelper.QueryHandler.CheckQueryAsync(id);
                await UnitTestHelper.QueryHandler.RemoveQueryAsync(id);
                isQuery = await UnitTestHelper.QueryHandler.CheckQueryAsync(id);
            }).GetAwaiter().GetResult();

            // assert
            Assert.AreEqual(isQuery, false);
        }
예제 #7
0
        public void MethodAsync_GetAllQueries()
        {
            // arrange
            var qType = QueryType.SetProperty;

            string[] keys = { "key1", "key2", "key3", "key4", "key5" };
            string   name = "name";

            Core.LogChange += CQG_LogChange_Mock;
            var queryHelper = new QueryHelper();

            UnitTestHelper.StartUp();
            UnitTestHelper.QueryHandler.NewQueriesReady += CQG_GetQueries;
            answers = new List <QueryInfo>();

            Task.Run(async() =>
            {
                // act
                for (int i = 0; i < keys.Length; i++)
                {
                    await queryHelper.PushQueryAsync(new QueryInfo(qType, keys[i], string.Empty, name, null, null));
                }
                UnitTestHelper.QueryHandler.ReadQueries();
            }).GetAwaiter().GetResult();

            // assert
            Assert.AreEqual(answers.Count, 5);
            for (int i = 0; i < answers.Count; i++)
            {
                Assert.AreEqual((answers[i].QueryKey == keys[i]), true);
            }
        }
예제 #8
0
        public void Method_DeleteProcessedQuery()
        {
            // arrange
            string id           = "key";
            string name         = "name";
            bool   isQueryTrue  = default(bool);
            bool   isQueryFalse = default(bool);

            Core.LogChange += CQG_LogChange;
            var queryHelper = new QueryHelper();

            UnitTestHelper.StartUp();

            // act 1
            Task.Run(async() =>
            {
                await queryHelper.PushQueryAsync(new QueryInfo(QueryType.SetProperty, id, string.Empty, name, null, null));
                isQueryTrue = await UnitTestHelper.QueryHandler.CheckQueryAsync(id);
            }).GetAwaiter().GetResult();

            UnitTestHelper.QueryHandler.DeleteProcessedQuery(id);

            Task.Run(async() =>
            {
                isQueryFalse = await UnitTestHelper.QueryHandler.CheckQueryAsync(id);
            }).GetAwaiter().GetResult();

            // assert
            Assert.IsTrue(isQueryTrue);
            Assert.IsFalse(isQueryFalse);
        }
예제 #9
0
        public void Method_IsDelegate()
        {
            // arrange
            Type[]      noDelegateTypes = { typeof(string), typeof(int), typeof(MyClass) };
            Type[]      delegateTypes   = { typeof(myDelegate1), typeof(myDelegate2), typeof(myDelegate3) };
            List <bool> resaltFalse     = new List <bool>();
            List <bool> resaltTrue      = new List <bool>();

            UnitTestHelper.StartUp();

            // act
            foreach (var type in noDelegateTypes)
            {
                resaltFalse.Add(QueryHandler.IsDelegate(type));
            }
            foreach (var type in delegateTypes)
            {
                resaltTrue.Add(QueryHandler.IsDelegate(type));
            }

            // assert
            for (int i = 0; i < resaltFalse.Count; i++)
            {
                Assert.IsFalse(resaltFalse[i]);
                Assert.IsTrue(resaltTrue[i]);
            }
        }
예제 #10
0
        public void FakeCQG_TimedBarsRequest()
        {
            // arrange
            UnitTestHelper.StartUp();
            #region Timer
            Timer timer = new Timer();
            timer.Interval  = 30;
            timer.AutoReset = true;
            timer.Elapsed  += Timer_Elapsed;
            timer.Start();
            #endregion
            CQGCEL fakeCQGCel = new CQGCELClass();
            Core.LogChange += CQG_LogChange;
            CQGTimedBarsRequest m_TimedBarsRequest;
            CQGTimedBars        CQGTimedBars;
            var startTime = new DateTime(2016, 06, 06);
            List <eTimedBarsRequestOutputs> TimedBarsRequestOutputs = new List <eTimedBarsRequestOutputs>();
            TimedBarsRequestOutputs.Add(eTimedBarsRequestOutputs.tbrActualVolume);
            TimedBarsRequestOutputs.Add(eTimedBarsRequestOutputs.tbrTickVolume);
            TimedBarsRequestOutputs.Add(eTimedBarsRequestOutputs.tbrAskVolume);
            TimedBarsRequestOutputs.Add(eTimedBarsRequestOutputs.tbrBidVolume);
            TimedBarsRequestOutputs.Add(eTimedBarsRequestOutputs.tbrOpenInterest);
            int recurrenceСount = 10;

            // act
            while (recurrenceСount > 0)
            {
                m_TimedBarsRequest                              = fakeCQGCel.CreateTimedBarsRequest();
                m_TimedBarsRequest.Symbol                       = "h";
                m_TimedBarsRequest.IncludeEnd                   = false;
                m_TimedBarsRequest.RangeStart                   = startTime;
                m_TimedBarsRequest.RangeEnd                     = DateTime.Now;
                m_TimedBarsRequest.HistoricalPeriod             = eHistoricalPeriod.hpWeekly;
                m_TimedBarsRequest.TickFilter                   = eTickFilter.tfDefault;
                m_TimedBarsRequest.Continuation                 = eTimeSeriesContinuationType.tsctNoContinuation;
                m_TimedBarsRequest.EqualizeCloses               = true;
                m_TimedBarsRequest.DaysBeforeExpiration         = 0;
                m_TimedBarsRequest.UpdatesEnabled               = false;
                m_TimedBarsRequest.IgnoreEventsOnHistoricalBars = false;
                m_TimedBarsRequest.SessionsFilter               = 0;
                m_TimedBarsRequest.SessionFlags                 = eSessionFlag.sfUndefined;
                m_TimedBarsRequest.ExcludeAllOutputs();
                foreach (eTimedBarsRequestOutputs selectedOutput in TimedBarsRequestOutputs)
                {
                    m_TimedBarsRequest.IncludeOutput(selectedOutput, true);
                }
                CQGTimedBars TimedBars = fakeCQGCel.RequestTimedBars(m_TimedBarsRequest);
                CQGTimedBars = fakeCQGCel.AllTimedBars.get_ItemById(TimedBars.Id);

                // assert
                Assert.IsNotNull(CQGTimedBars);
                Assert.AreEqual(25, CQGTimedBars.Count);
                recurrenceСount--;
            }
        }
예제 #11
0
        public void ProcessedQuery_CheckingQueryAnswerAppropriate()
        {
            // arrange
            #region Timer
            Timer timer = new Timer();
            timer.Interval  = 30;
            timer.AutoReset = true;
            timer.Elapsed  += TimerElapsed_CheckingQueryAnswerAppropriate;
            timer.Start();
            #endregion

            int      countQueries = 1000;
            string[] ids          = new string[countQueries];
            var      queries      = new List <QueryInfo>();
            var      answers      = new List <AnswerInfo>();
            var      queryHelper  = new QueryHelper();
            var      answerHelper = new AnswerHelper();
            Core.LogChange += CQG_LogChange;
            UnitTestHelper.StartUp();

            //Generate values array
            for (int i = 0; i < ids.Length; i++)
            {
                ids[i] = string.Concat("key", i.ToString());
            }

            // act
            for (int i = 0; i < ids.Length; i++)
            {
                var query = Core.CreateQuery(QueryType.CallCtor, ids[i], string.Empty, string.Empty, string.Empty);
                queries.Add(query);
            }

            foreach (var query in queries)
            {
                Task.Run(async() =>
                {
                    await queryHelper.PushQueryAsync(query);
                }).GetAwaiter().GetResult();
            }

            foreach (var id in ids)
            {
                var answer = answerHelper.GetAnswerData(id);
                answers.Add(answer);
            }

            // assert
            Assert.AreEqual(countQueries, queries.Count);
            Assert.AreEqual(countQueries, answers.Count);
            for (int i = 0; i < answers.Count; i++)
            {
                Assert.IsTrue(queries[i].QueryKey == answers[i].AnswerKey);
            }
        }
예제 #12
0
        //10 sec act test
        public async void ProcessedQuery_WithLongAct()
        {
            // arrange
            string id   = "key";
            string name = "name";
            bool   isQuery;
            var    queryHelper  = new QueryHelper();
            var    answerHelper = new AnswerHelper();

            Core.LogChange += CQG_LogChange;
            UnitTestHelper.StartUp();

            // act
            var query = Core.CreateQuery(QueryType.CallCtor, id, string.Empty, name, string.Empty);
            await queryHelper.PushQueryAsync(query);

            isQuery = await UnitTestHelper.QueryHandler.CheckQueryAsync(id);

            // assert 1
            Assert.IsTrue(isQuery);

            UnitTestHelper.QueryHandler.ProcessQuery(query);

            //Waight some time after procssed query
            Task.Delay(10000).GetAwaiter().GetResult();

            Task.Run(async() =>
            {
                isQuery = await UnitTestHelper.QueryHandler.CheckQueryAsync(id);

                // assert 2
                Assert.IsFalse(isQuery);
            }).GetAwaiter().GetResult();

            var answer = answerHelper.GetAnswerData(id);

            // assert 3
            Assert.IsNotNull(answer);
            Assert.AreEqual(id, answer.AnswerKey);
        }
예제 #13
0
        public void FakeCQG_EventHandlersWork()
        {
            // arrange
            UnitTestHelper.StartUp();
            string statusConnectionUp = "csConnectionUp";
            Timer  timer = new Timer();

            timer.Interval  = 30;
            timer.AutoReset = true;
            timer.Elapsed  += Timer_Elapsed;
            timer.Start();
            CQGCEL fakeCQGCel = new CQGCELClass();

            fakeCQGCel.DataConnectionStatusChanged += new _ICQGCELEvents_DataConnectionStatusChangedEventHandler(Cell_DataConnectionStatusChanged);
            Core.LogChange += CQG_LogChange;

            // act
            fakeCQGCel.Startup();
            Task.Delay(300).GetAwaiter().GetResult();

            // assert
            Assert.AreEqual(statusConnectionUp, status);
        }