Skip to content

Commit 3e4fe46

Browse files
committed
Additional tests
1 parent a3e902b commit 3e4fe46

File tree

3 files changed

+62
-39
lines changed

3 files changed

+62
-39
lines changed

src/Identity/ApiAuthorization.IdentityServer/src/Data/ApiAuthorizationDbContext.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Threading.Tasks;
56
using IdentityServer4.EntityFramework.Entities;
67
using IdentityServer4.EntityFramework.Extensions;
@@ -49,9 +50,46 @@ public ApiAuthorizationDbContext(
4950
/// <inheritdoc />
5051
protected override void OnModelCreating(ModelBuilder builder)
5152
{
52-
5353
base.OnModelCreating(builder);
54-
builder.ConfigurePersistedGrantContext(_operationalStoreOptions.Value);
54+
ConfigureGrantContext(builder, _operationalStoreOptions.Value);
5555
}
56+
57+
private void ConfigureGrantContext(ModelBuilder modelBuilder, OperationalStoreOptions storeOptions)
58+
{
59+
if (!string.IsNullOrWhiteSpace(storeOptions.DefaultSchema)) modelBuilder.HasDefaultSchema(storeOptions.DefaultSchema);
60+
61+
modelBuilder.Entity<PersistedGrant>(grant =>
62+
{
63+
grant.ToTable("PersistedGrants");
64+
65+
grant.Property(x => x.Key).HasMaxLength(200).ValueGeneratedNever();
66+
grant.Property(x => x.Type).HasMaxLength(50).IsRequired();
67+
grant.Property(x => x.SubjectId).HasMaxLength(200);
68+
grant.Property(x => x.ClientId).HasMaxLength(200).IsRequired();
69+
grant.Property(x => x.CreationTime).IsRequired();
70+
grant.Property(x => x.Data).HasMaxLength(50000).IsRequired();
71+
72+
grant.HasKey(x => x.Key);
73+
74+
grant.HasIndex(x => new { x.SubjectId, x.ClientId, x.Type });
75+
});
76+
77+
modelBuilder.Entity<DeviceFlowCodes>(codes =>
78+
{
79+
codes.ToTable("DeviceCodes");
80+
81+
codes.Property(x => x.DeviceCode).HasMaxLength(200).IsRequired();
82+
codes.Property(x => x.UserCode).HasMaxLength(200).IsRequired();
83+
codes.Property(x => x.SubjectId).HasMaxLength(200);
84+
codes.Property(x => x.ClientId).HasMaxLength(200).IsRequired();
85+
codes.Property(x => x.CreationTime).IsRequired();
86+
codes.Property(x => x.Expiration).IsRequired();
87+
codes.Property(x => x.Data).HasMaxLength(50000).IsRequired();
88+
89+
codes.HasKey(x => new { x.UserCode });
90+
91+
codes.HasIndex(x => x.DeviceCode).IsUnique();
92+
});
93+
}
5694
}
5795
}

src/ProjectTemplates/test/ProjectTemplates.Tests.csproj

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,6 @@
2020
<Compile Include="$(SharedSourceRoot)CertificateGeneration\**\*.cs" LinkBase="shared\CertificateGeneration" />
2121
</ItemGroup>
2222

23-
<ItemGroup>
24-
<TemplateFileInput Include="$(MSBuildThisFileDirectory)..\Web.ProjectTemplates\content\**\*" />
25-
<TemplateFileInput Include="$(MSBuildThisFileDirectory)..\Web.ProjectTemplates\*.csproj.in" />
26-
<TemplateFileInput Include="$(MSBuildThisFileDirectory)..\Web.Spa.ProjectTemplates\content\**\*" />
27-
<TemplateFileInput Include="$(MSBuildThisFileDirectory)..\Web.Spa.ProjectTemplates\*.csproj.in" />
28-
<TemplateFileOutput Include="$(RepoRoot)artifacts\packages\$(Configuration)\Shipping\Microsoft.DotNet.Web*.ProjectTemplates.*.nupkg" />
29-
</ItemGroup>
30-
31-
<Target
32-
Name="EnsureTemplatesAreRebuilt"
33-
BeforeTargets="Build"
34-
Inputs="@(TemplateFileInput)"
35-
Outputs="@(TemplateFileOutput)">
36-
<Message Importance="high" Text="Template packages out of date. Rebuilding the templates" />
37-
<Exec Command="dotnet pack" WorkingDirectory="$(MSBuildThisFileDirectory)..\Web.ProjectTemplates" />
38-
<Exec Command="dotnet pack" WorkingDirectory="$(MSBuildThisFileDirectory)..\Web.Spa.ProjectTemplates" />
39-
</Target>
40-
4123
<ItemGroup>
4224
<Reference Include="AngleSharp" />
4325
<Reference Include="Microsoft.Extensions.CommandLineUtils.Sources" />
@@ -70,4 +52,4 @@
7052
<!-- Shared testing infrastructure for running E2E tests using selenium -->
7153
<Import Project="$(SharedSourceRoot)E2ETesting\E2ETesting.targets" />
7254

73-
</Project>
55+
</Project>

src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ protected void SpaTemplateImpl_IndividualAuth(string template, bool useLocalDb =
7777
Assert.Contains(".db", projectFileContents);
7878
}
7979

80-
// Project.RunDotNetEfCreateMigration(template);
80+
Project.RunDotNetEfCreateMigration(template);
8181

82-
// Project.AssertEmptyMigration(template);
82+
Project.AssertEmptyMigration(template);
8383

8484

85-
TestApplication(publish: false);
85+
TestApplication(publish: false, visitFetchData: false);
8686

8787
UpdateSettingsForPublish();
8888

89-
TestApplication(publish: true);
89+
TestApplication(publish: true, visitFetchData: false);
9090
}
9191

9292
private void UpdateSettingsForPublish()
@@ -109,7 +109,7 @@ private void UpdateSettingsForPublish()
109109
File.WriteAllText(Path.Combine(Project.TemplateOutputDir, "appsettings.json"), testAppSettings);
110110
}
111111

112-
private void TestApplication(bool publish)
112+
private void TestApplication(bool publish, bool visitFetchData = true)
113113
{
114114
using (var aspNetProcess = Project.StartAspNetProcess(publish))
115115
{
@@ -118,12 +118,12 @@ private void TestApplication(bool publish)
118118
if (BrowserFixture.IsHostAutomationSupported())
119119
{
120120
aspNetProcess.VisitInBrowser(Browser);
121-
TestBasicNavigation();
121+
TestBasicNavigation(visitFetchData);
122122
}
123123
}
124124
}
125125

126-
private void TestBasicNavigation()
126+
private void TestBasicNavigation(bool visitFetchData)
127127
{
128128
Browser.WaitForElement("ul");
129129
// <title> element gets project ID injected into it during template execution
@@ -144,16 +144,19 @@ private void TestBasicNavigation()
144144
Browser.Click(counterComponent, "button");
145145
Assert.Equal("1", counterComponent.GetText("strong"));
146146

147-
// Can navigate to the 'fetch data' page
148-
Browser.Click(By.PartialLinkText("Fetch data"));
149-
Browser.WaitForUrl("fetch-data");
150-
Assert.Equal("Weather forecast", Browser.GetText("h1"));
151-
152-
// Asynchronously loads and displays the table of weather forecasts
153-
var fetchDataComponent = Browser.FindElement("h1").Parent();
154-
Browser.WaitForElement("table>tbody>tr");
155-
var table = Browser.FindElement(fetchDataComponent, "table", timeoutSeconds: 5);
156-
Assert.Equal(5, table.FindElements(By.CssSelector("tbody tr")).Count);
147+
if (visitFetchData)
148+
{
149+
// Can navigate to the 'fetch data' page
150+
Browser.Click(By.PartialLinkText("Fetch data"));
151+
Browser.WaitForUrl("fetch-data");
152+
Assert.Equal("Weather forecast", Browser.GetText("h1"));
153+
154+
// Asynchronously loads and displays the table of weather forecasts
155+
var fetchDataComponent = Browser.FindElement("h1").Parent();
156+
Browser.WaitForElement("table>tbody>tr");
157+
var table = Browser.FindElement(fetchDataComponent, "table", timeoutSeconds: 5);
158+
Assert.Equal(5, table.FindElements(By.CssSelector("tbody tr")).Count);
159+
}
157160
}
158161
}
159162
}

0 commit comments

Comments
 (0)