< Summary

Information
Class: EF.Blockchain.Server.Startup.ApplicationSetup
Assembly: EF.Blockchain.Server
File(s): C:\dev\@web3\web3-001-ef-blockchain\backend\EF.Blockchain\src\EF.Blockchain.Server\Startup\ApplicationSetup.cs
Line coverage
97%
Covered lines: 76
Uncovered lines: 2
Coverable lines: 78
Total lines: 79
Line coverage: 97.4%
Branch coverage
62%
Covered branches: 10
Total branches: 16
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddAppServices(...)50%6693.47%
AddAppServices(...)50%6691.89%
UseAppMiddleware(...)100%44100%
UseAppMiddleware(...)100%11100%

File(s)

C:\dev\@web3\web3-001-ef-blockchain\backend\EF.Blockchain\src\EF.Blockchain.Server\Startup\ApplicationSetup.cs

#LineLine coverage
 1using System.Reflection;
 2using EF.Blockchain.Domain;
 3using EF.Blockchain.Server.Middleware;
 4using Microsoft.AspNetCore.Http.Json;
 5using Microsoft.OpenApi.Models;
 6
 7namespace EF.Blockchain.Server.Startup;
 8
 9public static class ApplicationSetup
 10{
 11    public static IServiceCollection AddAppServices(this IServiceCollection services, IConfiguration config)
 9812    {
 11213        var miner = config["Blockchain:MinerWallet:PrivateKey"]
 11214            ?? Environment.GetEnvironmentVariable("BLOCKCHAIN_MINER")
 11215            ?? "default-miner";
 1416
 9817        var minerWallet = new Wallet(miner);
 11218        services.AddSingleton<Domain.Blockchain>(_ => new Domain.Blockchain(minerWallet.PublicKey));
 1419
 19620        services.Configure<JsonOptions>(options => options.SerializerOptions.WriteIndented = true);
 2821
 9822        services.AddEndpointsApiExplorer();
 1423
 24        // Add CORS
 11225        services.AddCors(options =>
 11226        {
 10927            options.AddPolicy("AllowAll", policy =>
 10928            {
 10929                policy.AllowAnyOrigin()
 10930                      .AllowAnyHeader()
 10931                      .AllowAnyMethod();
 20732            });
 20733        });
 1134
 10935        services.AddSwaggerGen();
 10936        services.AddSwaggerGen(options =>
 8837        {
 8838            options.SwaggerDoc("v1", new OpenApiInfo
 9139            {
 9140                Title = "EF Blockchain API",
 8841                Version = "v1",
 8842                Description = "Minimal API for educational blockchain project",
 9143                Contact = new OpenApiContact
 8844                {
 7745                    Name = "Éderson Fernandes",
 7746                    Url = new Uri("https://github.com/efernandes-tech")
 7747                }
 9148            });
 11249
 10950            // Enable XML comments if available
 10251            var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
 7752            var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFilename);
 11253
 9154            if (File.Exists(xmlPath))
 055            {
 056                options.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
 1457            }
 11258
 11259            // Enable enums as strings
 7760            options.UseInlineDefinitionsForEnums();
 17561        });
 1462
 11263        return services;
 11264    }
 1465
 1466    public static WebApplication UseAppMiddleware(this WebApplication app)
 11267    {
 1468        // Enable CORS (must be first)
 11269        app.UseCors("AllowAll");
 1470
 9871        app.UseSwagger();
 9872        app.UseSwaggerUI();
 1473
 11274        app.UseHttpsRedirection();
 11275        app.UseMiddleware<RequestLoggingMiddleware>();
 1476
 11277        return app;
 11278    }
 1479}