public void should_record_a_successful_run()
        {
            var userAgent = new UserAgent("browser", "Browser", null);
            var job = new Job("job");
            var run = new Run(job, "run", "http://foo");
            var runUserAgent = new RunUserAgent(run, userAgent);
            Client client = userAgent.SpawnNewClient("ip", "os");
            run.BeginClientRun(client);

            Save(userAgent, job, run, runUserAgent, client, run.ClientRuns.Single());

            var runCompleted = new CompleteRun
                {
                    Client_Id = client.Id,
                    Run_id =  run.Id,
                    Total = 10
                };

            //            WithDbContext(context => GetInstance<CompleteRunHandler>().Handle(runCompleted));

            WithDbContext(context =>
                              {
                                  GetInstance<CompleteRunHandler>().Handle(runCompleted);
                                  var foundRun = context.Find<Run>(run.Id);

                                  var single = foundRun.RunUserAgents.Single();

                                  var clientRun = single.Run.ClientRuns.Where(x => x.Client.UserAgent.Id == single.UserAgent.Id).FirstOrDefault() ?? new ClientRun();

                                  clientRun.IndicatesSuccess().ShouldBeTrue();
                                  single.RemainingRuns.ShouldEqual(0);
                                  single.RunStatus.ShouldEqual(RunStatusType.Finished);
                              });
        }
Exemplo n.º 2
0
        public void Apply(CompleteRun message)
        {
            Client.Updated = SystemTime.NowThunk();

            RecordRunStatus(fail: message.Fail,
                            error: message.Error,
                            total: message.Total,
                            results: message.Results);

            if (message.RepresentsAPassingRun())
            {
                Run.Pass(this);

            }
            else // test fail or error
            {
                Run.Fail(this);
            }
        }
Exemplo n.º 3
0
        protected override void SetUp()
        {
            StructureMap.Inject(typeof(IEventPublisher), new NoOpEventPublisher());

            var browser1 = new UserAgent("test", "test 1", 1);
            var browser2 = new UserAgent("test", "test 2", 2);
            var browser3 = new UserAgent("another", "another 1", 3);

            _client1 = browser1.SpawnNewClient(null, null);
            _client2 = browser2.SpawnNewClient(null, null);
            _client3 = browser3.SpawnNewClient(null, null);

            Save(browser1, browser2, browser3, _client1, _client2, _client3);

            WithDbContext(context =>
                              {
                                  var userAgentCache = new UserAgentCache(() => context);
                                  var newJobCreator = new CreateJobHandler(context, userAgentCache);
                                  newJobCreator.Handle(new CreateJob
                                      {
                                          Name = "job",
                                          Runs = new[]
                                              {
                                                  new CreateJob.CreateNewRun {Name = "C", Url = "foo"},
                                                  new CreateJob.CreateNewRun {Name = "A", Url = "foo"},
                                                  new CreateJob.CreateNewRun {Name = "B", Url = "foo"},
                                                  new CreateJob.CreateNewRun {Name = "D", Url = "foo"},
                                              }
                                      });
                                  context.SaveChanges();
                                  context.All<Client>().Count().ShouldEqual(3);
                              });

            WithDbContext(context =>
                              {
                                  for (int i = 0; i < 4; i++)
                                  {
                                      foreach (var client in new[]{_client1, _client2, _client3})
                                      {
                                          var nextRunQuery = new NextRunQuery(client.Id);
                                          var handler = GetInstance<NextRunQueryHandler>();
                                          var nextRunResult = handler.Handle(nextRunQuery);

                                          var runCompleted = new CompleteRun {Client_Id = client.Id, Run_id = nextRunResult.id, Total = 1};
                                          GetInstance<CompleteRunHandler>().Handle(runCompleted);
                                      }
                                  }
                              });

            long jobId = 0;

            WithDbContext(context =>
                              {
                                  var job = context.Jobs.Single();
                                  jobId = job.Id;

                                  job.Status.ShouldEqual(JobStatusType.Complete);

                              });

            WithDbContext(context =>
                              {
                                  var resetJob = new ResetJob(jobId);

                                  var resetJobHandler = new ResetJobHandler(context, S<IOutputCacheInvalidator>());

                                  resetJobHandler.Handle(resetJob);
                              });
        }