< Summary

Class:MUNity.BlazorServer.Startup
Assembly:MUNity.BlazorServer
File(s):C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNity.BlazorServer\Startup.cs
Covered lines:0
Uncovered lines:69
Coverable lines:69
Total lines:132
Line coverage:0% (0 of 69)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)
Covered methods:0
Total methods:5
Method coverage:0% (0 of 5)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%10%
get_Configuration()100%10%
ConfigureServices(...)100%10%
Configure(...)0%20%
MigrateDatabase(...)100%10%

File(s)

C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNity.BlazorServer\Startup.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Builder;
 2using Microsoft.AspNetCore.Components;
 3using Microsoft.AspNetCore.Components.Authorization;
 4using Microsoft.AspNetCore.Hosting;
 5using Microsoft.AspNetCore.HttpsPolicy;
 6using Microsoft.AspNetCore.Identity;
 7using Microsoft.AspNetCore.Identity.UI;
 8using Microsoft.EntityFrameworkCore;
 9using Microsoft.Extensions.Configuration;
 10using Microsoft.Extensions.DependencyInjection;
 11using Microsoft.Extensions.Hosting;
 12using MUNity.BlazorServer.Areas.Identity;
 13using MUNity.Database.Context;
 14using MUNity.Database.Models.User;
 15using MUNity.Services;
 16using System;
 17using System.Collections.Generic;
 18using System.Linq;
 19using System.Threading.Tasks;
 20using Radzen;
 21
 22namespace MUNity.BlazorServer;
 23
 24public class Startup
 25{
 026    public Startup(IConfiguration configuration)
 027    {
 028        Configuration = configuration;
 029    }
 30
 031    public IConfiguration Configuration { get; }
 32
 33    // This method gets called by the runtime. Use this method to add services to the container.
 34    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
 35    public void ConfigureServices(IServiceCollection services)
 036    {
 37        // Blazor stuff
 038        services.AddRazorPages();
 039        services.AddServerSideBlazor();
 40
 41        //Trigger deploy
 42        // Database
 43        // To get more output add: .EnableSensitiveDataLogging().LogTo(Console.WriteLine) after Use...()
 44        // Set the Data Source to: ../../tests/MUNityDatabaseTest/bin/Debug/net6.0/testmunbw.db
 45        // For demo use the name demo.db
 46        // to use the latest result of the MUNBW test
 047        services.AddDbContext<MunityContext>(options =>
 048            options.UseSqlite("Data Source=demo.db"));
 49
 50        // Identity
 051        services.AddAuthentication();
 052        services.AddIdentity<MunityUser, MunityRole>(options =>
 053        {
 054            options.User.RequireUniqueEmail = true;
 055            options.Password.RequireDigit = true;
 056            options.Password.RequireLowercase = true;
 057            options.Password.RequireUppercase = true;
 058            options.Password.RequireNonAlphanumeric = false;
 059        })
 060            .AddEntityFrameworkStores<MunityContext>()
 061            .AddDefaultUI()
 062            .AddDefaultTokenProviders();
 63
 64
 65
 66        //services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<MunityUser>>()
 067        services.AddDatabaseDeveloperPageExceptionFilter();
 68
 69        // Radzen.Blazor
 070        services.AddScoped<DialogService>();
 071        services.AddScoped<NotificationService>();
 072        services.AddScoped<TooltipService>();
 073        services.AddScoped<ContextMenuService>();
 74
 75        // MUNity Services
 076        services.AddScoped<UserConferenceAuthService>();
 077        services.AddScoped<UserService>();
 078        services.AddScoped<OrganizationService>();
 079        services.AddScoped<ProjectService>();
 080        services.AddScoped<ConferenceService>();
 081        services.AddScoped<DelegationService>();
 082        services.AddScoped<ConferenceRoleService>();
 083        services.AddScoped<UserNotificationService>();
 084        services.AddScoped<ConferenceApplicationService>();
 085        services.AddScoped<IMailService, MailService>();
 086        services.AddScoped<ConferenceWebsiteService>();
 87
 088        services.AddLogging();
 89
 090    }
 91
 92    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 93    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
 094    {
 095        if (env.IsDevelopment())
 096        {
 097            app.UseDeveloperExceptionPage();
 098            app.UseMigrationsEndPoint();
 099        }
 100        else
 0101        {
 0102            app.UseExceptionHandler("/Error");
 103            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.
 0104            app.UseHsts();
 0105        }
 106
 0107        app.UseHttpsRedirection();
 0108        app.UseStaticFiles();
 109
 0110        app.UseRouting();
 111
 0112        app.UseAuthentication();
 0113        app.UseAuthorization();
 114
 0115        app.UseEndpoints(endpoints =>
 0116        {
 0117            endpoints.MapControllers();
 0118            endpoints.MapBlazorHub();
 0119            endpoints.MapFallbackToPage("/_Host");
 0120        });
 121
 0122        MigrateDatabase(app);
 0123    }
 124
 125    private void MigrateDatabase(IApplicationBuilder app)
 0126    {
 0127        var scope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope();
 0128        var context = scope.ServiceProvider.GetRequiredService<MunityContext>();
 0129        context.Database.EnsureCreated();
 0130        context.Database.Migrate();
 0131    }
 132}