public void ProcessReasoningTask_PartialFacts_APIDoesNotRespond()
        {
            var reasoningTask = ReasoningMocks.GetReasoningTask(ReasoningTaskStatus.WAITING);

            reasoningTask.ReasoningProcess.KnowledgeBase.RuleSet[0].Predicates[0].LeftTerm.Value = null;
            reasoningTask.ReasoningProcess.KnowledgeBase.RuleSet[1].Predicates[0].LeftTerm.Value = null;
            reasoningTask.Sources = new List <IVariableSource>
            {
                new VariableSource
                {
                    VariableIds = new List <string> {
                        "var1"
                    },
                    Request = new ReasoningRequest
                    {
                        Uri    = "http://localhost:8080",
                        Method = ReasoningRequestMethod.GET
                    }
                }
            };

            var reasoningTaskRepository = new Mock <IReasoningTaskRepository>();

            reasoningTaskRepository.Setup(x => x.GetAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(reasoningTask));
            var reasoningService = new ReasoningService();

            var service = MockReasoningTaskResolver(reasoningTaskRepository.Object, reasoningService);

            var result = service.ProcessReasoningTask("testId").Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(ReasoningTaskStatus.STOPPED, result.Status);
            Assert.IsTrue(result.ReasoningProcess.ReasonedItems.Count == 0);
        }
        public void CancelTaskAsync_ExistingTask()
        {
            var reasoningTask           = ReasoningMocks.GetReasoningTask(ReasoningTaskStatus.WAITING);
            var reasoningTaskRepository = new Mock <IReasoningTaskRepository>();

            reasoningTaskRepository.Setup(x => x.GetAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(reasoningTask));

            var service = MockReasoningTaskService(reasoningTaskRepository.Object);

            var result = service.CancelTaskAsync("testId").Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(ReasoningTaskStatus.CANCELLED, result.Status);
        }
        public void ProcessReasoningTask_AllFacts()
        {
            var reasoningTask = ReasoningMocks.GetReasoningTask(ReasoningTaskStatus.WAITING);

            var reasoningTaskRepository = new Mock <IReasoningTaskRepository>();

            reasoningTaskRepository.Setup(x => x.GetAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(reasoningTask));
            var reasoningService = new ReasoningService();

            var service = MockReasoningTaskResolver(reasoningTaskRepository.Object, reasoningService);

            var result = service.ProcessReasoningTask("testId").Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(ReasoningTaskStatus.FINISHED, result.Status);
            Assert.IsTrue(result.ReasoningProcess.ReasonedItems.Count == 1);
        }
        public void SetVariablesAsync_ExistingTask()
        {
            var reasoningTask     = ReasoningMocks.GetReasoningTask(ReasoningTaskStatus.STOPPED);
            var variablesResource = new VariablesResource {
                Variables = new List <IVariable>()
            };

            var reasoningTaskRepository = new Mock <IReasoningTaskRepository>();

            reasoningTaskRepository.Setup(x => x.GetAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(reasoningTask));
            var reasoningService = new ReasoningService();

            var service = MockReasoningTaskService(reasoningTaskRepository.Object, null, reasoningService);

            var result = service.SetVariablesAsync("testId", variablesResource).Result;

            Assert.IsNotNull(result);
            Assert.IsTrue(result.MissingVariableIds.ToList().Count == 0);
        }
        public void ProcessReasoningTask_PartialFacts_APISendsRequestOnEnd()
        {
            var reasoningTask = ReasoningMocks.GetReasoningTask(ReasoningTaskStatus.WAITING);

            reasoningTask.Actions = new List <IReasoningAction>
            {
                new ReasoningAction
                {
                    ReasoningItems = new List <IVariable>
                    {
                        new Variable("conclusion1", 1)
                    },
                    ReasoningRequests = new List <IReasoningRequest>
                    {
                        new ReasoningRequest
                        {
                            Uri    = "http://localhost:8080",
                            Method = ReasoningRequestMethod.POST
                        }
                    }
                }
            };

            var httpClientService = new Mock <IHttpClientService>();

            httpClientService.Setup(x => x.ExecuteTaskAsync(It.IsAny <IReasoningRequest>()))
            .Returns(Task.CompletedTask);
            var reasoningTaskRepository = new Mock <IReasoningTaskRepository>();

            reasoningTaskRepository.Setup(x => x.GetAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(reasoningTask));
            var reasoningService = new ReasoningService();

            var service = MockReasoningTaskResolver(reasoningTaskRepository.Object, reasoningService, null, httpClientService.Object);

            var result = service.ProcessReasoningTask("testId").Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(ReasoningTaskStatus.FINISHED, result.Status);
            Assert.IsTrue(result.ReasoningProcess.ReasonedItems.Count == 1);
        }