Monday, 16 March 2026

Run XUnit - Code Coverage in visual studio

Right Click Solution => Open Terminal & Run below steps one by one

 1.  #Run tests with coverage

dotnet test --collect:"XPlat Code Coverage"

 

2. #Install reportgenerator tool
dotnet tool install -g dotnet-reportgenerator-globaltool

 

3. # Clean and Generate HTML report
Remove-Item -Path "TestResults" -Recurse -Force -ErrorAction SilentlyContinue ; Remove-Item -Path "coveragereport" -Recurse -Force -ErrorAction SilentlyContinue ; dotnet test --collect:"XPlat Code Coverage" ; reportgenerator -reports:"**/coverage.cobertura.xml" -targetdir:"coveragereport" -reporttypes:Html ; Invoke-Item "coveragereport\index.html"

4. After execution it will open report

Sunday, 15 March 2026

Configure Google Authentication in ASP.NET Core (.NET 8)

Configure Google Authentication in ASP.NET Core (.NET 8)

This guide explains how to register a project and enable Google login using OAuth.

Step 1: Create Google Cloud Project

  1. Open Google Cloud Console
  2. Click Select Project → New Project
  3. Enter a Project Name
  4. Click Create

Step 2: Configure OAuth Consent Screen

  1. Navigate to APIs & Services → OAuth Consent Screen
  2. Select External
  3. Enter App Name and Email
  4. Save and Continue

OAuth consent screen shows the permissions your app requests from users. :contentReference[oaicite:1]{index=1}

Step 3: Create OAuth Client

  1. Go to APIs & Services → Credentials
  2. Click Create Credentials
  3. Select OAuth Client ID
  4. Choose Web Application

Step 4: Add Redirect URI

Add the redirect URI used by ASP.NET authentication:

https://localhost:7250/signin-google
We Can add multiple url environment basis
Example: https://dev-xyz.com/signin-google 

This URI is required so Google knows where to send the authentication response. :contentReference[oaicite:2]{index=2}

Step 5: Copy Credentials

After creating the client, Google will generate:

  • Client ID
  • Client Secret

Use these values in your ASP.NET Core configuration.

Example Configuration

builder.Services.AddAuthentication()
.AddCookie()
.AddGoogle(options =>
{
    options.ClientId = "CLIENT_ID";
    options.ClientSecret = "CLIENT_SECRET";
});

Login Flow

User clicks Google Login
→ Redirect to Google
→ User signs in
→ Google redirects to /signin-google
→ ASP.NET validates token
→ Redirect to application