Пример #1
0
        private ValueSetRepository CreateSUT()
        {
            var dbOptions = new DbContextOptionsBuilder <VocabularyContext>()
                            .UseInMemoryDatabase(databaseName: "vocabulary1")
                            .Options;

            var context = new VocabularyContext(dbOptions);

            context.EnsureSeedDataForContext();

            return(new ValueSetRepository(context));
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            VocabularyContext vocabularyContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) =>
            {
                context.Response.Headers.Add("X-Frame-Options", "DENY");           // Prevents being loaded in a frame
                context.Response.Headers.Add("X-Content-Type-Options", "nosniff"); // Prevents Internet Explorer from MIME-sniffing a response away from the declared content-type.
                context.Response.Headers.Add("X-XSS-Protection", "1; mode=block");
                await next();
            });

            app.UseHttpsRedirection();

            app.UseDefaultFiles(); // will ensure index.html is returned when no resource is specified; this must come before the UseStaticFiles() line below
            app.UseStaticFiles();  // needed for the wwwroot folder so we can serve index.html

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", $"{API_NAME} {API_VERSION}");
            });

            app.UseRouting();

            app.UseAuthorization();

            #region Automapper
            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <ValueSet, ValueSetForRetrievalDto>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src =>
                                                               src.ValueSetID))
                .ForMember(dest => dest.Code, opt => opt.MapFrom(src =>
                                                                 src.ValueSetCode))
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src =>
                                                                 src.ValueSetName))
                .ForMember(dest => dest.Oid, opt => opt.MapFrom(src =>
                                                                src.ValueSetOID))
                .ForMember(dest => dest.Definition, opt => opt.MapFrom(src =>
                                                                       src.DefinitionText));

                cfg.CreateMap <ValueSetForInsertionDto, ValueSet>()
                .ForMember(dest => dest.DefinitionText, opt => opt.MapFrom(src =>
                                                                           src.Definition))
                .ForMember(dest => dest.ValueSetCode, opt => opt.MapFrom(src =>
                                                                         src.Code))
                .ForMember(dest => dest.ValueSetName, opt => opt.MapFrom(src =>
                                                                         src.Name))
                .ForMember(dest => dest.ValueSetOID, opt => opt.MapFrom(src =>
                                                                        src.Oid));

                cfg.CreateMap <ValueSetVersion, ValueSetVersionForRetrievalDto>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src =>
                                                               src.ValueSetVersionID))
                .ForMember(dest => dest.Oid, opt => opt.MapFrom(src =>
                                                                src.ValueSetOID))
                .ForMember(dest => dest.Code, opt => opt.MapFrom(src =>
                                                                 src.ValueSetCode))
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src =>
                                                                 src.ValueSetName))
                .ForMember(dest => dest.Definition, opt => opt.MapFrom(src =>
                                                                       src.DefinitionText))
                .ForMember(dest => dest.Description, opt => opt.MapFrom(src =>
                                                                        src.ValueSetVersionDescriptionText))
                .ForMember(dest => dest.Version, opt => opt.MapFrom(src =>
                                                                    src.ValueSetVersionNumber));

                cfg.CreateMap <ValueSet, ValueSetVersionForRetrievalDto>()
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src =>
                                                                 src.ValueSetName))
                .ForMember(dest => dest.Code, opt => opt.MapFrom(src =>
                                                                 src.ValueSetCode))
                .ForMember(dest => dest.Definition, opt => opt.MapFrom(src =>
                                                                       src.DefinitionText));

                cfg.CreateMap <ValueSetConcept, ValueSetConceptForRetrievalDto>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src =>
                                                               src.ValueSetConceptID))
                .ForMember(dest => dest.CodeSystemOid, opt => opt.MapFrom(src =>
                                                                          src.CodeSystemOID))
                .ForMember(dest => dest.ValueSetVersionId, opt => opt.MapFrom(src =>
                                                                              src.ValueSetVersionID))
                .ForMember(dest => dest.Code, opt => opt.MapFrom(src =>
                                                                 src.ConceptCode))
                .ForMember(dest => dest.ScopeNote, opt => opt.MapFrom(src =>
                                                                      src.ScopeNoteText))
                .ForMember(dest => dest.Status, opt => opt.MapFrom(src =>
                                                                   src.ValueSetConceptStatusCode))
                .ForMember(dest => dest.StatusDate, opt => opt.MapFrom(src =>
                                                                       src.ValueSetConceptStatusDate))
                .ForMember(dest => dest.CdcPreferredDesignation, opt => opt.MapFrom(src =>
                                                                                    src.CDCPreferredDesignation))
                .ForMember(dest => dest.Hl70396Identifier, opt => opt.MapFrom(src =>
                                                                              src.HL70396Identifier))
                .ForMember(dest => dest.Definition, opt => opt.MapFrom(src =>
                                                                       src.ValueSetConceptDefinitionText));
            });
            #endregion // Automapper

            vocabularyContext.EnsureSeedDataForContext();

            #region Health checks
            app.UseHealthChecks("/health/live", new HealthCheckOptions
            {
                // Exclude all checks, just return a 200.
                Predicate             = (check) => false,
                AllowCachingResponses = false
            });

            app.UseHealthChecks("/health/ready", new HealthCheckOptions
            {
                // TODO: Add check for database(s) and OAuth2 provider in here
                // TODO: Perhaps secure this endpoint?
                // TODO: Look into adding memory checks
                Predicate             = (check) => false,
                AllowCachingResponses = false
            });
            #endregion // Health checks

            app.UseResponseCaching();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }