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());
        }
Esempio n. 2
0
        public void Should_be_possible_to_get_a_number_of_times_that_was_executed_the_collectRequest()
        {
            CollectRequestFactory factory        = new CollectRequestFactory();
            IDocumentSession      fakeSession    = this.GetSession();
            CollectRequest        collectRequest = factory.CreateCollectRequest(fakeSession).Item2;

            Assert.IsTrue(collectRequest.GetNumberOfExecutions(fakeSession) == 0, "this request collect still not executed");

            //add two executions
            CollectExecution firstExecution = factory.CreateCollect(fakeSession);

            firstExecution.RequestId = collectRequest.Oid;
            firstExecution.ProbeExecutions.Add(factory.CreateProbeExecution(fakeSession, "registry"));
            firstExecution.ProbeExecutions.Add(factory.CreateProbeExecution(fakeSession, "family"));

            CollectExecution secondExecution = factory.CreateCollect(fakeSession);

            secondExecution.RequestId = collectRequest.Oid;
            secondExecution.ProbeExecutions.Add(factory.CreateProbeExecution(fakeSession, "registry"));
            fakeSession.SaveChanges();
            Assert.AreEqual(2, collectRequest.GetNumberOfExecutions(fakeSession));
        }
 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();
 }
 private void CheckTheDefaulStateOfRequestCollectAfterOneExecution(CollectRequest requestCollectAfterExecute)
 {
     Assert.IsNotNull(requestCollectAfterExecute);
     Assert.AreEqual(1, requestCollectAfterExecute.GetNumberOfExecutions(session));
 }