Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="T:HospitalAllocation.Providers.Allocation.Database.AllocationDatabaseStore"/>
        /// class using the specified options.
        /// </summary>
        /// <param name="dbOptions">The options used to access the database.</param>
        public AllocationDatabaseStore(DbContextOptions <AllocationContext> dbOptions)
        {
            _dbOptions = dbOptions;

            using (var context = new AllocationContext(dbOptions))
            {
                // Fill the memory store with the latest allocations, if any exist
                _allocation = new AllocationMemoryStore();
                if (context.TeamAllocations.Where(t => t.Type == Model.TeamType.A).Any())
                {
                    AllocationProvider.SetPodAllocation(_allocation.PodA,
                                                        ModelConverter.PodFromModel(GetLatestAllocation(Model.TeamType.A, context)));
                }
                if (context.TeamAllocations.Where(t => t.Type == Model.TeamType.B).Any())
                {
                    AllocationProvider.SetPodAllocation(_allocation.PodB,
                                                        ModelConverter.PodFromModel(GetLatestAllocation(Model.TeamType.B, context)));
                }
                if (context.TeamAllocations.Where(t => t.Type == Model.TeamType.C).Any())
                {
                    AllocationProvider.SetPodAllocation(_allocation.PodC,
                                                        ModelConverter.PodFromModel(GetLatestAllocation(Model.TeamType.C, context)));
                }
                if (context.TeamAllocations.Where(t => t.Type == Model.TeamType.D).Any())
                {
                    AllocationProvider.SetPodAllocation(_allocation.PodD,
                                                        ModelConverter.PodFromModel(GetLatestAllocation(Model.TeamType.D, context)));
                }
                if (context.TeamAllocations.Where(t => t.Type == Model.TeamType.Senior).Any())
                {
                    AllocationProvider.SetSeniorTeamAllocation(_allocation.SeniorTeam,
                                                               ModelConverter.SeniorTeamFromModel(GetLatestAllocation(Model.TeamType.Senior, context)));
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:HospitalAllocation.Providers.Allocation.JsonFile.AllocationJsonFileStore"/> class.
 /// </summary>
 /// <param name="file">The file backing the JSON store</param>
 /// <param name="allocation">The initial allocation data for the file store</param>
 private AllocationJsonFileStore(FileInfo file, IcuAllocation allocation)
 {
     _jsonFile   = file;
     _allocation = new AllocationMemoryStore();
     AllocationProvider.SetPodAllocation(_allocation.PodA, allocation.PodA);
     AllocationProvider.SetPodAllocation(_allocation.PodB, allocation.PodB);
     AllocationProvider.SetPodAllocation(_allocation.PodC, allocation.PodC);
     AllocationProvider.SetPodAllocation(_allocation.PodD, allocation.PodD);
     AllocationProvider.SetSeniorTeamAllocation(_allocation.SeniorTeam, allocation.SeniorTeam);
 }
            public void MutantAllocationOverwritesOriginal_ResultEqualsMutant()
            {
                // Given
                var mutation      = MockPodA.GetMutantPodA();
                var fooAllocation = MockAllocation.GetTestAllocation();

                // When
                AllocationProvider.SetPodAllocation(fooAllocation.PodA, mutation.AsPod);
                // Then
                Assert.True(EqualMethods.PodStoreEqual(mutation, fooAllocation.PodA));
            }
            public void MutantAllocationOverwritesOriginal_ResultEqualsMutant()
            {
                // Given
                var mutation      = MockSeniorTeam.GetMutantSeniorTeam();
                var fooAllocation = MockAllocation.GetTestAllocation();

                // When
                AllocationProvider.SetSeniorTeamAllocation(fooAllocation.SeniorTeam, mutation.AsSeniorTeam);
                // Then
                Assert.True(EqualMethods.SeniorTeamStoreEqual(mutation, fooAllocation.SeniorTeam));
            }
            private void NullTeam_BadRequest()
            {
                // Given
                var fooAllocation = MockAllocation.GetTestAllocation();
                var fooProvider   = new AllocationProvider(fooAllocation);
                var fooController = new TeamController(fooProvider);
                // When
                var nullRes = fooController.GetTeam(null);

                // Then
                Assert.IsType <BadRequestObjectResult>(nullRes);
            }
            private void NullAllocationToValidPod_BadRequest()
            {
                // Given
                var fooAllocation = MockAllocation.GetTestAllocation();
                var fooProvider   = new AllocationProvider(fooAllocation);
                var fooController = new TeamController(fooProvider);
                // When
                var nullAllocRes = fooController.AddAllocationToPod(TeamType.A, null);

                // Then
                Assert.IsType <BadRequestObjectResult>(nullAllocRes);
            }
            private void ValidAllocation_Ok()
            {
                // Given
                var fooAllocation          = MockAllocation.GetTestAllocation();
                var fooProvider            = new AllocationProvider(fooAllocation);
                var fooController          = new TeamController(fooProvider);
                var fooNewSeniorAllocation = new SeniorAllocationRequest(MockSeniorTeam.GetMutantSeniorTeam().AsSeniorTeam);
                // When
                var seniorRes = fooController.AddAllocationToSeniorTeam(fooNewSeniorAllocation);

                // Then
                Assert.IsType <OkObjectResult>(seniorRes);
            }
            private void ValidAllocationToValidPod_Success()
            {
                // Given
                var fooAllocation    = MockAllocation.GetTestAllocation();
                var fooProvider      = new AllocationProvider(fooAllocation);
                var fooController    = new TeamController(fooProvider);
                var fooNewAllocation = new PodAllocationRequest(MockPodD.GetTestPodD().AsPod);
                // When
                var successRes = fooController.AddAllocationToPod(TeamType.A, fooNewAllocation);

                // Then
                Assert.IsType <JsonResult>(successRes);
            }
            private void ValidAllocationToNullPod_BadRequest()
            {
                // Given
                var fooAllocation    = MockAllocation.GetTestAllocation();
                var fooProvider      = new AllocationProvider(fooAllocation);
                var fooController    = new TeamController(fooProvider);
                var fooNewAllocation = new PodAllocationRequest(MockPodD.GetTestPodD().AsPod);
                // When
                var nullTypeRes = fooController.AddAllocationToPod(null, fooNewAllocation);

                // Then
                Assert.IsType <BadRequestObjectResult>(nullTypeRes);
            }
            public void Pod_Success()
            {
                // Given
                var fooAllocation = MockAllocation.GetTestAllocation();
                var fooProvider   = new AllocationProvider(fooAllocation);
                var fooController = new TeamController(fooProvider);
                // When
                var podRes = fooController.GetTeam(TeamType.A);
                // Then
                var jsonPodRes         = Assert.IsType <JsonResult>(podRes);
                var podSummaryResponse = Assert.IsType <TeamSummaryResponse>(jsonPodRes.Value);

                Assert.Equal(ResponseStatus.Success, podSummaryResponse.Status);
            }
            public void ValidList_Success()
            {
                // Given
                var fooAllocation = MockAllocation.GetTestAllocation();
                var fooProvider   = new AllocationProvider(fooAllocation);
                var fooController = new TeamController(fooProvider);
                // When
                var res = fooController.GetTeamList();
                // Then
                var jsonResult       = Assert.IsType <JsonResult>(res);
                var teamListResponse = Assert.IsType <TeamListResponse>(jsonResult.Value);

                Assert.Equal(ResponseStatus.Success, teamListResponse.Status);
            }
Exemple #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:HospitalAllocation.Controllers.TeamController"/> class.
 /// </summary>
 /// <param name="allocationProvider">Provides an interface to the allocation store</param>
 public TeamController(AllocationProvider allocationProvider)
 {
     _allocation = allocationProvider;
 }
Exemple #13
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc().AddJsonOptions(options =>
            {
                // When we receive JSON message bodies, ones that are
                // malformed in some way just come through as null.
                // Adding this handler means we get a nice print out
                // describing what causes it to deserialise to null
                options.SerializerSettings.Error = (sender, e) =>
                {
                    Console.Error.WriteLine(e.ErrorContext.OriginalObject);
                    Console.Error.WriteLine(e.ErrorContext.Error.StackTrace);
                    Console.Error.WriteLine("-----ERROR-----");
                    Console.Error.WriteLine("Path: " + e.ErrorContext.Path);
                    Console.Error.WriteLine("Error causing member: " + e.ErrorContext.Member);
                    Console.Error.WriteLine("Message: " + e.ErrorContext.Error.Message);
                    Console.Error.WriteLine();
                };
            });

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v2", new Info {
                    Title = "Hospital Allocation API", Version = "v2"
                });

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });

            // Build the database provider configuration
            var optionsBuilder = new DbContextOptionsBuilder <AllocationContext>();

            optionsBuilder.UseSqlite(Configuration.GetConnectionString("DefaultConnection"));

            DbContextOptions <AllocationContext> dbOptions = optionsBuilder.Options;

            using (var context = new AllocationContext(dbOptions))
            {
                context.Database.Migrate();
                context.EnsureSeedData();
            }

            // Add the provider for the allocation store
            var allocationProvider = new AllocationProvider(new AllocationDatabaseStore(dbOptions));

            services.AddSingleton(allocationProvider);

            // Add the image storage provider for the image API
            var imageProvider = new DbImageProvider(dbOptions);

            services.AddSingleton <IImageProvider>(imageProvider);

            var csvfileProvider = new DbCSVFileProvider(dbOptions);

            services.AddSingleton <ICSVFileProvider>(csvfileProvider);

            // Add the staff storage provider for the staff API
            var staffProvider = new DbStaffProvider(dbOptions);

            services.AddSingleton <IStaffProvider>(staffProvider);

            // Add the skill storage provider for the skill API
            var skillProvider = new DbSkillProvider(dbOptions);

            services.AddSingleton <ISkillProvider>(skillProvider);

            // Add the designation storage provider for the designation API
            var designationProvider = new DbDesignationProvider(dbOptions);

            services.AddSingleton <IDesignationProvider>(designationProvider);

            // Add the note storage provider for the note API
            var noteProvider = new DbNoteProvider(dbOptions);

            services.AddSingleton <INoteProvider>(noteProvider);

            // Add the handover provider for the handover API
            var handoverProvider = new DbHandoverProvider(dbOptions);

            services.AddSingleton <IHandoverProvider>(handoverProvider);
        }