public void Should_be_possible_identify_when_an_unrecoverable_error_occurs()
        {
            IDocumentSession fakeSession    = provider.GetSession();
            CollectRequest   collectRequest = this.GetCollectRequest();

            session.SaveChanges();
            CollectExecutionManagerFactory factory = new CollectExecutionManagerFactory(collectRequest, session);

            session.SaveChanges();
            List <string> registryObjectsThatNotProcessInFirstTime = new List <string>()
            {
                "oval:org.mitre.oval:obj:4000"
            };
            List <string>           familyObjectsThatNotProcessInFirstTime = new List <string>();
            CollectExecutionManager executionManager = factory.CreateExecutionManagerWWithInvalidCredentialsScenario(this.GetResultForRegistry(collectRequest, registryObjectsThatNotProcessInFirstTime),
                                                                                                                     this.GetResultForFamily(collectRequest, familyObjectsThatNotProcessInFirstTime));

            session.SaveChanges();
            executionManager.ExecuteCollect(fakeSession, collectRequest, FamilyEnumeration.windows);
            session.SaveChanges();
            CollectRequest collectRequestAfterExecute = session.Load <CollectRequest>(collectRequest.Oid.ToString());

            this.CheckTheDefaulStateOfRequestCollectAfterOneExecution(collectRequestAfterExecute);
            Assert.AreEqual(true, collectRequestAfterExecute.GetCollectExecutions(session).First().ProbeExecutions.First().HasErrors());

            Assert.IsTrue(collectRequestAfterExecute.isClosed(), "the request Collect is not closed");
        }
        public void Should_be_possible_finalize_the_collectRequest_if_the_number_of_execution_exceeds_of_limits()
        {
            IDocumentSession fakeSession    = provider.GetSession();
            CollectRequest   collectRequest = this.GetCollectRequest();
            oval_definitions definitions    = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            var objList = new List <ObjectType>();

            objList.Add(new family_object()
            {
                id = "oval:org.mitre.oval:obj:1000"
            });
            objList.Add(new file_object()
            {
                id = "oval:org.mitre.oval:obj:5000"
            });
            definitions.objects = objList.ToArray();

            var newDefinitiondoc = new DefinitionDocument()
            {
                OriginalId = "01", Text = definitions.GetDefinitionsXml()
            };

            session.Store(newDefinitiondoc);
            collectRequest.OvalDefinitionsId = newDefinitiondoc.Oid;
            CollectExecutionManagerFactory factory = new CollectExecutionManagerFactory(collectRequest, session);
            List <string>           registryObjectsThatNotProcessInFirstTime = new List <string>();
            List <string>           familyObjectsThatNotProcessInFirstTime   = new List <string>();
            CollectExecutionManager executionManager = factory.CreateExecutionManagerForTheSuccessScenario(this.GetResultForRegistry(collectRequest, registryObjectsThatNotProcessInFirstTime),
                                                                                                           this.GetResultForFamily(collectRequest, familyObjectsThatNotProcessInFirstTime));

            session.Store(collectRequest);
            var newExecution1 = new CollectExecution()
            {
                RequestId = collectRequest.Oid
            };

            session.Store(newExecution1);
            var newExecution2 = new CollectExecution()
            {
                RequestId = collectRequest.Oid
            };

            session.Store(newExecution2);
            var newExecution3 = new CollectExecution()
            {
                RequestId = collectRequest.Oid
            };

            session.Store(newExecution3);
            executionManager.ExecuteCollect(fakeSession, collectRequest, FamilyEnumeration.windows);
            session.SaveChanges();

            CollectRequest collectRequestAfterExecute = session.Load <CollectRequest>(collectRequest.Oid.ToString());

            Assert.IsNotNull(collectRequest);
            Assert.AreEqual(4, collectRequestAfterExecute.GetNumberOfExecutions(session));
            Assert.IsTrue(collectRequestAfterExecute.isClosed());
        }
 private void EndCollect(IDocumentSession session, CollectRequest collectRequest, CollectExecution collectExecution)
 {
     if (collectTimeOut.IsExceededTheMaxOfExecutionsDefined(collectRequest.GetNumberOfExecutions(session)))
     {
         collectRequest.Close();
     }
     else
     {
         if (!collectRequest.isClosed())
         {
             if (!collectExecution.ExistsExecutionsWithError())
             {
                 collectRequest.TryClose(session);
             }
             else
             {
                 collectRequest.Reopen();
             }
         }
     }
     collectExecution.SetDateEndCollect();
     session.SaveChanges();
 }