BlueCollar.Test.RepositoryTests.GetHistoryList C# (CSharp) Method

GetHistoryList() protected method

Get history tests.
protected GetHistoryList ( ) : void
return void
        protected void GetHistoryList()
        {
            if (this.Repository != null)
            {
                IJob job = new TestJob() { Id = Guid.NewGuid() };
                DateTime now = DateTime.UtcNow.FloorWithSeconds();

                WorkerRecord workerRecord = new WorkerRecord()
                {
                    ApplicationName = BlueCollarSection.Section.ApplicationName,
                    MachineAddress = Machine.Address,
                    MachineName = Machine.Name,
                    Name = "Test Worker",
                    QueueNames = "*",
                    Signal = WorkerSignal.Stop,
                    Status = WorkerStatus.Working,
                    Startup = WorkerStartupType.Automatic,
                    UpdatedOn = now
                };

                this.Repository.CreateWorker(workerRecord, null);

                HistoryRecord historyRecord = new HistoryRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = JobSerializer.Serialize(job),
                    FinishedOn = now,
                    JobName = job.Name,
                    JobType = JobSerializer.GetTypeName(job.GetType()),
                    QueuedOn = now,
                    StartedOn = now,
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);

                var list = this.Repository.GetHistoryList(workerRecord.ApplicationName, null, 100, 0, null);
                Assert.IsNotNull(list);
                Assert.AreEqual(1, list.TotalCount);
                Assert.AreEqual(1, list.Records.Count);

                list = this.Repository.GetHistoryList(workerRecord.ApplicationName, "boo", 100, 0, null);
                Assert.IsNotNull(list);
                Assert.AreEqual(0, list.TotalCount);
                Assert.AreEqual(0, list.Records.Count);

                ScheduleRecord scheduleRecord = new ScheduleRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Enabled = true,
                    Name = "Test",
                    QueueName = "scheduled",
                    RepeatType = ScheduleRepeatType.None,
                    StartOn = now
                };

                this.Repository.CreateSchedule(scheduleRecord, null);

                historyRecord = new HistoryRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = JobSerializer.Serialize(job),
                    FinishedOn = now,
                    JobName = job.Name,
                    JobType = JobSerializer.GetTypeName(job.GetType()),
                    QueuedOn = now,
                    ScheduleId = scheduleRecord.Id.Value,
                    StartedOn = now,
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);

                list = this.Repository.GetHistoryList(workerRecord.ApplicationName, null, 100, 0, null);
                Assert.IsNotNull(list);
                Assert.AreEqual(2, list.TotalCount);
                Assert.AreEqual(2, list.Records.Count);
                Assert.IsTrue(list.Records.Where(h => h.ScheduleName == "Test").Count() == 1);
            }
        }