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 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 WhenNonExistingJobIsRequestedThenNullIsReturned() { var jobsDb = new SortingJobCollection(); Assert.Empty(jobsDb.RetrieveJobs()); var controller = new SortingController( Mocks.GetMockedLogger <SortingController>(), jobsDb); var job = controller.Get(Guid.Empty.ToString()); Assert.Null(job); }
public void WhenNoJobsThenGetAllReturnsEmptyCollection() { var jobsDb = new SortingJobCollection(); Assert.Empty(jobsDb.RetrieveJobs()); var controller = new SortingController( Mocks.GetMockedLogger <SortingController>(), jobsDb); var jobs = controller.GetAll(); Assert.NotNull(jobs); Assert.Empty(jobs); }
public void WhenAddingNewJobThenJobIdIsReturned() { var jobsDb = new SortingJobCollection(); Assert.Empty(jobsDb.RetrieveJobs()); var controller = new SortingController( Mocks.GetMockedLogger <SortingController>(), jobsDb); SortingController.CreateJobResponse response = controller.Post(new int[] { 2, 1 }); Assert.NotNull(response); Assert.NotNull(response.Id); Assert.NotEmpty(response.Id); }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { // Add in memory collection of jobs var jobsCollection = new SortingJobCollection(); services.AddSingleton(jobsCollection); // Add CORS capabilities services.AddCors(this.ConfigureCors); // Add response caching capabilities services.AddResponseCaching(this.ConfigureResponseCaching); // Add the controllers defined in this assembly services.AddControllers() .AddJsonOptions(this.ConfigureJsonSerialization); }
public void WhenAddingNewJobThenCollectionImmediatelyHasNewJob() { var jobsDb = new SortingJobCollection(); Assert.Empty(jobsDb.RetrieveJobs()); var controller = new SortingController( Mocks.GetMockedLogger <SortingController>(), jobsDb); var jobs = controller.Post(new int[] { 2, 1 }); Assert.NotEmpty(jobsDb.RetrieveJobs()); var job = jobsDb.RetrieveJobs().First(); Assert.NotNull(job); }
/// <summary> /// Initializes a new instance of the <see cref="SortingController"/> class. /// </summary> /// <param name="logger">The logger passed as dependency.</param> /// <param name="jobsCollection">The collection used to store jobs across different calls.</param> public SortingController(ILogger <SortingController> logger, SortingJobCollection jobsCollection) { this.logger = logger; this.jobsCollection = jobsCollection; }