Skip to content

Commit

Permalink
Add RegistrationTests
Browse files Browse the repository at this point in the history
  • Loading branch information
justindbaur committed Oct 17, 2023
1 parent 64299fa commit d9d6814
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageReference Include="AutoFixture" Version="4.18.0" />
<PackageReference Include="coverlet.collector" Version="3.2.0" PrivateAssets="all" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.18.4" />
Expand Down
50 changes: 50 additions & 0 deletions tests/Passwordless.AspNetCore.Tests/RegistrationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Passwordless.AspNetCore.Services;

namespace Passwordless.AspNetCore.Tests;

public class RegistrationTests
{
[Fact]
public void AllExpectedServicesAndOptionsResolve()
{
var configuration = new ConfigurationBuilder()

Check failure on line 15 in tests/Passwordless.AspNetCore.Tests/RegistrationTests.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Passwordless.AspNetCore.Tests.RegistrationTests.AllExpectedServicesAndOptionsResolve

System.InvalidOperationException : Unable to resolve service for type 'Passwordless.PasswordlessOptions' while attempting to activate 'Passwordless.PasswordlessClient'.

Check failure on line 15 in tests/Passwordless.AspNetCore.Tests/RegistrationTests.cs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Passwordless.AspNetCore.Tests.RegistrationTests.AllExpectedServicesAndOptionsResolve

System.InvalidOperationException : Unable to resolve service for type 'Passwordless.PasswordlessOptions' while attempting to activate 'Passwordless.PasswordlessClient'.
.AddInMemoryCollection(new Dictionary<string, string?>
{
["ApiSecret"] = "FakeApiSecret",
["ApiUrl"] = "https://example.org",
["SignInScheme"] = "Cookies",
["Register:Discoverable"] = "false"
})
.Build();

var serviceCollection = new ServiceCollection();

serviceCollection.AddDbContext<TestDbContext>();

serviceCollection
.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<TestDbContext>()
.AddPasswordless(configuration);

var provider = serviceCollection.BuildServiceProvider();

_ = provider.GetRequiredService<PasswordlessClient>();
_ = provider.GetRequiredService<IPasswordlessService<PasswordlessRegisterRequest>>();
var optionsAccessor = provider.GetRequiredService<IOptions<PasswordlessAspNetCoreOptions>>();
var options = optionsAccessor.Value;
Assert.Equal("FakeApiSecret", options.ApiSecret);
Assert.Equal("https://example.org", options.ApiUrl);
Assert.Equal("Cookies", options.SignInScheme);
Assert.False(options.Register.Discoverable);
}
}

public class TestDbContext : IdentityDbContext<IdentityUser>
{

}

0 comments on commit d9d6814

Please sign in to comment.