Пример #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)));
                }
            }
        }
Пример #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));
            }