Skip to content

Commit

Permalink
Exclude migrations from Code Coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhiggins732 committed Mar 3, 2024
1 parent 40586b5 commit 7a7bc15
Show file tree
Hide file tree
Showing 39 changed files with 756 additions and 156 deletions.
5 changes: 5 additions & 0 deletions samples/Quickstarts/1_ClientCredentials/src/Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/

using System.Diagnostics.CodeAnalysis;

ConfigureLogger();

Console.Title = "Identity Server";
Expand Down Expand Up @@ -104,3 +106,6 @@ copies or substantial portions of the Software.
// flushToDiskInterval: TimeSpan.FromSeconds(1))
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
.CreateLogger();

[ExcludeFromCodeCoverage]
public partial class Program { }
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/

using System.Diagnostics.CodeAnalysis;

ConfigureLogger();

Console.Title = "Identity Server";
Expand Down Expand Up @@ -104,3 +106,6 @@ copies or substantial portions of the Software.
// flushToDiskInterval: TimeSpan.FromSeconds(1))
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
.CreateLogger();

[ExcludeFromCodeCoverage]
public partial class Program { }
5 changes: 5 additions & 0 deletions samples/Quickstarts/3_AspNetCoreAndApis/src/Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/

using System.Diagnostics.CodeAnalysis;

ConfigureLogger();

Console.Title = "Identity Server";
Expand Down Expand Up @@ -104,3 +106,6 @@ copies or substantial portions of the Software.
// flushToDiskInterval: TimeSpan.FromSeconds(1))
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
.CreateLogger();

[ExcludeFromCodeCoverage]
public partial class Program { }
5 changes: 5 additions & 0 deletions samples/Quickstarts/4_JavaScriptClient/src/Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ copies or substantial portions of the Software.
*/


using System.Diagnostics.CodeAnalysis;

ConfigureLogger();

Console.Title = "Identity Server";
Expand Down Expand Up @@ -107,3 +109,6 @@ copies or substantial portions of the Software.
// flushToDiskInterval: TimeSpan.FromSeconds(1))
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
.CreateLogger();

[ExcludeFromCodeCoverage]
public partial class Program { }
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/

using System.Diagnostics.CodeAnalysis;

var app = WebApplication.Create(args);
app.UseDefaultFiles();
app.UseStaticFiles();
await app.RunAsync();

[ExcludeFromCodeCoverage]
public partial class Program { }

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ copies or substantial portions of the Software.
*/

using Microsoft.EntityFrameworkCore.Migrations;
using System.Diagnostics.CodeAnalysis;

namespace IdentityServer.Data.Migrations.IdentityServer.ConfigurationDb
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ copies or substantial portions of the Software.
// <auto-generated />
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using System.Diagnostics.CodeAnalysis;

namespace IdentityServer.Data.Migrations.IdentityServer.ConfigurationDb
{
[ExcludeFromCodeCoverage(Justification = "Code Coverage does not detect migrations in tests despite being ran.")]
[DbContext(typeof(ConfigurationDbContext))]
partial class ConfigurationDbContextModelSnapshot : ModelSnapshot
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ copies or substantial portions of the Software.
*/

using Microsoft.EntityFrameworkCore.Migrations;
using System.Diagnostics.CodeAnalysis;

namespace IdentityServer.Data.Migrations.IdentityServer.PersistedGrantDb
{
[ExcludeFromCodeCoverage(Justification = "Code Coverage does not detect migrations in tests despite being ran.")]
public partial class InitialIdentityServerPersistedGrantDbMigration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ copies or substantial portions of the Software.
// <auto-generated />
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using System.Diagnostics.CodeAnalysis;

namespace IdentityServer.Data.Migrations.IdentityServer.PersistedGrantDb
{
[ExcludeFromCodeCoverage(Justification = "Code Coverage does not detect migrations in tests despite being ran.")]
[DbContext(typeof(PersistedGrantDbContext))]
partial class PersistedGrantDbContextModelSnapshot : ModelSnapshot
{
Expand Down
4 changes: 4 additions & 0 deletions samples/Quickstarts/5_EntityFramework/src/Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
using IdentityServer.QuickStarts;
using IdentityServer.QuickStarts.EntityFramework;
using System.Diagnostics.CodeAnalysis;

ConfigureLogger();

Expand Down Expand Up @@ -115,3 +117,5 @@ copies or substantial portions of the Software.
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
.CreateLogger();

[ExcludeFromCodeCoverage]
public partial class Program { }
27 changes: 18 additions & 9 deletions samples/Quickstarts/5_EntityFramework/src/Host/StartupTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,29 @@ copies or substantial portions of the Software.
using Secret = IdentityServer8.Models.Secret;

using Microsoft.EntityFrameworkCore;
namespace IdentityServer.QuickStarts;
namespace IdentityServer.QuickStarts.EntityFramework;

public class StartupTests : StartupTest
{
public StartupTests()
{
IsTest = true;
}
}
public class StartupTest
{


public static bool IsTest = false;
public void ConfigureServices(IServiceCollection services)
{


services.AddScoped<ISignInHelper, HttpContextSignInHelper>();
services.AddControllersWithViews();

var migrationsAssembly = typeof(Program).GetTypeInfo().Assembly.GetName().Name;
const string connectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;database=IdentityServer8.Quickstart.EntityFramework-4.0.0;trusted_connection=yes;";
const string sqliteConnectionString = $"Filename=./Test.IdentityServer8.EntityFramework-3.1.0.db";
//const string sqliteConnectionString = $"Filename=./Test.IdentityServer8.EntityFramework-3.1.0.db";
services.AddIdentityServer()
.AddTestUsers(TestUsers.Users)
.AddConfigurationStore(options =>
Expand All @@ -42,7 +49,7 @@ public void ConfigureServices(IServiceCollection services)
else
{
options.ConfigureDbContext = b => b.UseInMemoryDatabase("EntityFramework");
// sql => sql.MigrationsAssembly(migrationsAssembly));
// sql => sql.MigrationsAssembly(migrationsAssembly));

}
})
Expand Down Expand Up @@ -115,12 +122,14 @@ internal static void InitializeDatabase(IApplicationBuilder app)
{
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
serviceScope.ServiceProvider.GetRequiredService<PersistedGrantDbContext>().Database.Migrate();
//if (StartupTests.IsTest)
// if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
// serviceScope.ServiceProvider.GetRequiredService<PersistedGrantDbContext>().Database.Migrate();

var context = serviceScope.ServiceProvider.GetRequiredService<ConfigurationDbContext>();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
context.Database.Migrate();
if (StartupTests.IsTest)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
context.Database.Migrate();

if (!context.Clients.Any())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ copies or substantial portions of the Software.
*/

using Microsoft.EntityFrameworkCore.Migrations;
using System.Diagnostics.CodeAnalysis;

namespace IdentityServerAspNetIdentity.Data.Migrations
{
[ExcludeFromCodeCoverage(Justification = "Code Coverage does not detect migrations in tests despite being ran.")]
public partial class CreateIdentitySchema : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ copies or substantial portions of the Software.

// <auto-generated />
using Microsoft.EntityFrameworkCore.Infrastructure;
using System.Diagnostics.CodeAnalysis;

namespace IdentityServerAspNetIdentity.Data.Migrations
{
[ExcludeFromCodeCoverage(Justification = "Code Coverage does not detect migrations in tests despite being ran.")]
[DbContext(typeof(ApplicationDbContext))]
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
{
Expand Down
5 changes: 5 additions & 0 deletions samples/Quickstarts/6_AspNetIdentity/src/Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/

using System.Diagnostics.CodeAnalysis;

ConfigureLogger();

try
Expand Down Expand Up @@ -126,3 +128,6 @@ copies or substantial portions of the Software.
// flushToDiskInterval: TimeSpan.FromSeconds(1))
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
.CreateLogger();

[ExcludeFromCodeCoverage]
public partial class Program { }
14 changes: 13 additions & 1 deletion samples/Quickstarts/6_AspNetIdentity/src/Host/SeedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/

using IdentityServer.QuickStarts.AspNetIdentity;
using System.Diagnostics.CodeAnalysis;

namespace Shared;

public class SeedData
Expand All @@ -30,7 +33,16 @@ public static void EnsureSeedData(string connectionString)
using (var scope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
var context = scope.ServiceProvider.GetService<ApplicationDbContext>();
context.Database.Migrate();
if (StartupTest.IsTest)
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
else
{
context.Database.Migrate();
}


var userMgr = scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
var alice = userMgr.FindByNameAsync("alice").Result;
Expand Down
33 changes: 22 additions & 11 deletions samples/Quickstarts/6_AspNetIdentity/src/Host/StartupTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ copies or substantial portions of the Software.



namespace IdentityServer.QuickStarts;
namespace IdentityServer.QuickStarts.AspNetIdentity;

public class StartupTests : StartupTest
{


public StartupTests(IConfiguration configuration) : base(configuration, true)
{
IsTest = true;
}
}
public class StartupTest
{
public IConfiguration Configuration { get; }

public StartupTest(IConfiguration configuration)
public StartupTest(IConfiguration configuration, bool isTest = false)
{
IsTest = isTest;
Configuration = configuration;
}

Expand Down Expand Up @@ -70,21 +80,22 @@ public void ConfigureServices(IServiceCollection services)

}

public static bool IsTest = false;
public void Configure(IApplicationBuilder app)
{
var env = app.ApplicationServices.GetRequiredService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>();


var args = Environment.GetCommandLineArgs();
//if (args.Contains("/seed"))
// {
Log.Information("Seeding database...");
var config = app.ApplicationServices.GetRequiredService<IConfiguration>();
var connectionString = config.GetConnectionString("DefaultConnection");
Shared.SeedData.EnsureSeedData(connectionString);
Log.Information("Done seeding database.");

// }
// {
Log.Information("Seeding database...");
var config = app.ApplicationServices.GetRequiredService<IConfiguration>();
var connectionString = config.GetConnectionString("DefaultConnection");
Shared.SeedData.EnsureSeedData(connectionString);
Log.Information("Done seeding database.");

// }

if (env.IsDevelopment())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ copies or substantial portions of the Software.
*/

namespace IdentityServer.QuickStarts.ClientCredentials.IntegrationTests
namespace IdentityServer.QuickStarts.IntegrationTests
{
public class ControllerTests : ControllerTests<StartupTests>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ copies or substantial portions of the Software.
*/

namespace IdentityServer.QuickStarts.ClientCredentials.IntegrationTests
namespace IdentityServer.QuickStarts.IntegrationTests
{
public class ControllerTests : ControllerTests<StartupTests>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
global using Xunit;
global using StartupTests = IdentityServer.QuickStarts.StartupTest;
global using StartupTests = IdentityServer.QuickStarts.AspNetIdentity.StartupTests;
global using IdentityServer.Samples.Shared.IntegrationTests.Tests;
global using IdentityServer.Samples.Shared.IntegrationTests.Tests.Base;
global using IdentityServer.Samples.Shared.IntegrationTests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ copies or substantial portions of the Software.



namespace IdentityServer.QuickStarts.ClientCredentials.IntegrationTests
using IdentityServerAspNetIdentity.Data;
using Microsoft.EntityFrameworkCore;

namespace IdentityServer.QuickStarts.IntegrationTests
{
public class ControllerTests : ControllerTests<StartupTests>
{
static ControllerTests()
{
StartupTests.IsTest = true;

}
public ControllerTests(TestFixture<StartupTests> fixture) : base(fixture)
{
UserMocks.SetTestUser(new() { Username = "alice", Password = "Pass123$" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ copies or substantial portions of the Software.



namespace IdentityServer.QuickStarts.ClientCredentials.IntegrationTests
using IdentityServer.QuickStarts.ClientCredentials;

namespace IdentityServer.QuickStarts.IntegrationTests
{
public class ControllerTests : ControllerTests<ClientCredentialsStartupTest>
{
Expand Down
Loading

0 comments on commit 7a7bc15

Please # to comment.