// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(builder => builder.Run( async context => { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; var error = context.Features.Get <IExceptionHandlerFeature>(); if (error != null) { context.Response.AddApplicationError(error.Error.Message); await context.Response.WriteAsync(error.Error.Message); } } )); } //app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(XmlConfigurationExtensions => XmlConfigurationExtensions.WithOrigins("http://localhost:4200").AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public void AddXmlFile_ThrowsIfFileDoesNotExistAtPath() { // Arrange var path = Path.Combine(Directory.GetCurrentDirectory(), "file-does-not-exist.xml"); var configurationBuilder = new ConfigurationBuilder(); // Act and Assert var ex = Assert.Throws <FileNotFoundException>(() => XmlConfigurationExtensions.AddXmlFile(configurationBuilder, path)); Assert.Equal($"The configuration file '{path}' was not found and is not optional.", ex.Message); }
public void AddXmlFile_ThrowsIfFilePathIsNullOrEmpty(string path) { // Arrange var configurationBuilder = new ConfigurationBuilder(); // Act and Assert var ex = Assert.Throws <ArgumentException>(() => XmlConfigurationExtensions.AddXmlFile(configurationBuilder, path)); Assert.Equal("path", ex.ParamName); Assert.StartsWith("File path must be a non-empty string.", ex.Message); }
/// <summary> /// Add xml format configuration by the given stream. /// </summary> /// <param name="builder"></param> /// <param name="stream"></param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> public static void AddXmlStream(this IConfigurationBuilder builder, Stream stream) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (stream is null || !stream.CanRead) { throw new ArgumentException("Stream cannot be null or cannot be read."); } XmlConfigurationExtensions.AddXmlStream(builder, stream); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(XmlConfigurationExtensions => XmlConfigurationExtensions.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1")); } app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(XmlConfigurationExtensions => XmlConfigurationExtensions.AllowAnyHeader().AllowAnyMethod().WithOrigins("https://localhost:4200")); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "tlrsCartonManager.Api v1")); } app.UseMiddleware(typeof(ErrorHandlingMiddleware)); app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(XmlConfigurationExtensions => XmlConfigurationExtensions.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin()); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <DataContext>(XmlConfigurationExtensions => XmlConfigurationExtensions.UseSqlite(Configuration.GetConnectionString("DefaultConnection"))); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddCors(); }