コード例 #1
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");
        }
コード例 #2
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");
        }
コード例 #3
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");
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
 /// <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;
 }