Exemplo n.º 1
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]);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void MethodAsync_PushOneAnswerItem()
        {
            // arrange
            string idTrue   = "keyTrue";
            string idFalse  = "keyFalse";
            string name     = "name";
            bool   isAnswer = default(bool);

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

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

                // assert 1
                Assert.AreEqual(isAnswer, true);

                // act 2
                isAnswer = await answerHelper.CheckAnswerAsync(idFalse);

                // assert 2
                Assert.AreEqual(isAnswer, false);
            }).GetAwaiter().GetResult();
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void Method_PushAnswer()
        {
            // arrange
            string id           = "key";
            string name         = "name";
            bool   isQueryTrue  = default(bool);
            bool   isQueryFalse = default(bool);
            var    query        = new QueryInfo(QueryType.SetProperty, id, string.Empty, name, null, null);
            var    answer       = new AnswerInfo(id, string.Empty, name, null, null);

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

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

            // act
            Task.Run(async() =>
            {
                await queryHelper.PushQueryAsync(query);
                isQueryTrue = await UnitTestHelper.QueryHandler.CheckQueryAsync(id);
            }).GetAwaiter().GetResult();

            UnitTestHelper.QueryHandler.PushAnswerAndDeleteQuery(answer);

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

            // assert
            Assert.IsTrue(isQueryTrue);
            Assert.IsFalse(isQueryFalse);
        }