Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
        public void Work_WhenDone_SetsDuration()
        {
            var sortingJob = new SortingJob(sorterMock.Object, Array.Empty <int>());

            sortingJob.Work();

            sortingJob.Duration.Should().NotBe(default(TimeSpan));
        }
Exemplo n.º 4
0
        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>());
        }
Exemplo n.º 6
0
        private SortingJob Create(IEnumerable <int> input)
        {
            var job = new SortingJob(input);

            this.jobsCollection.AddJob(job);

            return(job);
        }
Exemplo n.º 7
0
        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 }));
        }
Exemplo n.º 8
0
        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");
        }
Exemplo n.º 9
0
        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");
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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");
        }
Exemplo n.º 12
0
        public void WhenCreatedThenValuesIsNull()
        {
            var job = new SortingJob(new int[0]);

            Assert.IsNull(job.Values, "When created, values should be null");
        }
Exemplo n.º 13
0
        public void WhenCreatedThenStatusIsPending()
        {
            var job = new SortingJob(new int[0]);

            Assert.AreEqual(SortingJobStatus.Pending, job.Status, "When created, status should be pending");
        }
Exemplo n.º 14
0
        public void WhenCreatedThenDurationIsNegativeOne()
        {
            var job = new SortingJob(new int[0]);

            Assert.AreEqual(-1, job.Duration, "When created, duration should be -1");
        }
Exemplo n.º 15
0
        public void WhenCreatedThenIdIsAssigned()
        {
            var job = new SortingJob(new int[0]);

            Assert.IsNotNull(job.Id, "A new id should have been assigned");
        }
Exemplo n.º 16
0
 /// <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);
 }
Exemplo n.º 17
0
        public void WhenCreatedThenTimestampIsAssigned()
        {
            var job = new SortingJob(new int[0]);

            Assert.IsNotNull(job.Timestamp, "A new timestamp should have been assigned");
        }