public void IdIsUnique() { var job1 = new SortingJob(new int[0]); var job2 = new SortingJob(new int[0]); Assert.AreNotEqual(job1.Id, job2.Id, "Ids should be unique"); }
private void EnqueueJob(SortingJob job) { var stopwatch = new Stopwatch(); stopwatch.Start(); try { // Execute the sorting logic job.Sort(); job.Status = SortingJobStatus.Completed; } catch (InvalidOperationException e) { this.logger.LogError($"Error while executing sorting job '{job.Id}': {e.Message}"); job.Status = SortingJobStatus.Error; throw e; } finally { // Tracked time: until sorting is complete stopwatch.Stop(); // Update the job job.Duration = stopwatch.ElapsedMilliseconds; } }
public void Work_WhenDone_SetsDuration() { var sortingJob = new SortingJob(sorterMock.Object, Array.Empty <int>()); sortingJob.Work(); sortingJob.Duration.Should().NotBe(default(TimeSpan)); }
public void Work_SortsUsingSorter() { var sortingJob = new SortingJob(sorterMock.Object, Array.Empty <int>()); sortingJob.Work(); sorterMock.Verify(s => s.Sort(It.IsAny <int[]>()), Times.Once()); }
public InMemoryJobStoreTests() { var sorterMock = new Mock <ISorter <int> >(); loggerMock = new Mock <ILogger <InMemoryJobStore> >(); sorterMock.Setup(s => s.Sort(Array.Empty <int>())).Returns(Array.Empty <int>()).Verifiable(); sortingJob = new SortingJob(sorterMock.Object, Array.Empty <int>()); }
private SortingJob Create(IEnumerable <int> input) { var job = new SortingJob(input); this.jobsCollection.AddJob(job); return(job); }
public async Task <IActionResult> SortArray([FromBody] int[] numbers) { var job = new SortingJob(Sorter, numbers); await this.jobStore.Save(job.Id, job); await this.runner.Execute(job); return(this.Accepted(new { job.Id, job.Timestamp, job.Status })); }
public void CollectionHoldsReferenceToJobs() { var collection = new SortingJobCollection(); var job = new SortingJob(new int[0]); collection.AddJob(job); var retrievedJob = collection.RetrieveJob(job.Id); Assert.IsTrue((object)job == (object)retrievedJob, "Collection is not properly storing jobs"); }
public void AddAndRetrieveJob() { var collection = new SortingJobCollection(); var job = new SortingJob(new int[0]); collection.AddJob(job); var retrievedJob = collection.RetrieveJob(job.Id); Assert.IsNotNull(retrievedJob, "Retrieval was not successful"); }
public void Work_WhenDone_SetsSortedOutput() { var sortingJob = new SortingJob(sorterMock.Object, unsortedArray); sortingJob.Work(); sortingJob.Output.Should().NotBeNull(); sortingJob.Output.Should().NotBeEmpty(); sortingJob.Output.Should().BeSameAs(sortedArray); }
public void RetrieveAllJobs() { var collection = new SortingJobCollection(); var job1 = new SortingJob(new int[0]); var job2 = new SortingJob(new int[0]); collection.AddJob(job1); collection.AddJob(job2); var jobs = collection.RetrieveJobs(); Assert.IsTrue(jobs.Count() > 0, "Retrieval of all jobs was not successful"); }
public void WhenCreatedThenValuesIsNull() { var job = new SortingJob(new int[0]); Assert.IsNull(job.Values, "When created, values should be null"); }
public void WhenCreatedThenStatusIsPending() { var job = new SortingJob(new int[0]); Assert.AreEqual(SortingJobStatus.Pending, job.Status, "When created, status should be pending"); }
public void WhenCreatedThenDurationIsNegativeOne() { var job = new SortingJob(new int[0]); Assert.AreEqual(-1, job.Duration, "When created, duration should be -1"); }
public void WhenCreatedThenIdIsAssigned() { var job = new SortingJob(new int[0]); Assert.IsNotNull(job.Id, "A new id should have been assigned"); }
/// <summary> /// Adds a new job in the database. /// </summary> /// <param name="job"></param> public virtual void AddJob(SortingJob job) { this.jobs.Add(job.Id, job); }
public void WhenCreatedThenTimestampIsAssigned() { var job = new SortingJob(new int[0]); Assert.IsNotNull(job.Timestamp, "A new timestamp should have been assigned"); }