Skip to content

Commit cf40f1b

Browse files
committed
Component Test
1 parent 9f98460 commit cf40f1b

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using CodeBeam.UltimateAuth.Tests.Integration.Infrastructure;
2+
using FluentAssertions;
3+
using Microsoft.AspNetCore.Mvc.Testing;
4+
5+
public sealed class UAuthHubSampleSmokeTests : IClassFixture<AuthServerFactory>
6+
{
7+
private readonly HttpClient _client;
8+
9+
public UAuthHubSampleSmokeTests(AuthServerFactory factory)
10+
{
11+
_client = factory.CreateClient(
12+
new WebApplicationFactoryClientOptions
13+
{
14+
AllowAutoRedirect = false
15+
});
16+
}
17+
18+
[Theory]
19+
[InlineData("/")]
20+
[InlineData("/login")]
21+
public async Task CriticalPages_ShouldRenderWithoutServerError(string path)
22+
{
23+
var response = await _client.GetAsync(path);
24+
25+
((int)response.StatusCode)
26+
.Should()
27+
.BeLessThan(500);
28+
}
29+
}

‎tests/CodeBeam.UltimateAuth.Tests.Unit/CodeBeam.UltimateAuth.Tests.Unit.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
</ItemGroup>
2727

2828
<ItemGroup>
29+
<ProjectReference Include="..\..\samples\UAuthHub\CodeBeam.UltimateAuth.Sample.UAuthHub\CodeBeam.UltimateAuth.Sample.UAuthHub.csproj" />
2930
<ProjectReference Include="..\..\src\bundle\CodeBeam.UltimateAuth.EntityFrameworkCore.Bundle\CodeBeam.UltimateAuth.EntityFrameworkCore.Bundle.csproj" />
3031
<ProjectReference Include="..\..\src\bundle\CodeBeam.UltimateAuth.InMemory.Bundle\CodeBeam.UltimateAuth.InMemory.Bundle.csproj" />
3132
<ProjectReference Include="..\..\samples\CodeBeam.UltimateAuth.Sample.Seed\CodeBeam.UltimateAuth.Sample.Seed.csproj" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Bunit;
2+
using CodeBeam.UltimateAuth.Client.Blazor.Extensions;
3+
using CodeBeam.UltimateAuth.InMemory;
4+
using CodeBeam.UltimateAuth.Server.Extensions;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using MudBlazor.Services;
8+
using MudExtensions.Services;
9+
10+
namespace CodeBeam.UltimateAuth.Tests.Unit.Samples;
11+
12+
public abstract class UAuthHubComponentTestBase : BunitContext
13+
{
14+
protected UAuthHubComponentTestBase()
15+
{
16+
JSInterop.Mode = JSRuntimeMode.Loose;
17+
18+
var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
19+
20+
Services.AddSingleton<IConfiguration>(configuration);
21+
22+
Services.AddMudServices();
23+
Services.AddMudExtensions();
24+
Services.AddUltimateAuthServer().AddUltimateAuthInMemory().AddUAuthHub();
25+
Services.AddUltimateAuthClientBlazor();
26+
}
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Bunit;
2+
using CodeBeam.UltimateAuth.Client;
3+
using CodeBeam.UltimateAuth.Sample.UAuthHub.Components.Layout;
4+
using CodeBeam.UltimateAuth.Sample.UAuthHub.Components.Pages;
5+
using FluentAssertions;
6+
using Microsoft.AspNetCore.Components;
7+
8+
namespace CodeBeam.UltimateAuth.Tests.Unit.Samples.UAuthHub;
9+
10+
public sealed class HomeTests : UAuthHubComponentTestBase
11+
{
12+
[Fact]
13+
public void Home_ShouldRender()
14+
{
15+
var state = UAuthState.Anonymous();
16+
17+
var act = () => Render<CascadingValue<UAuthState>>(parameters => parameters
18+
.Add(p => p.Value, state)
19+
.AddChildContent<Home>());
20+
21+
act.Should().NotThrow();
22+
}
23+
}

0 commit comments

Comments
 (0)