Skip to content

Commit

Permalink
Add RegistrationTests (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
justindbaur authored Oct 25, 2023
1 parent 8198bd2 commit 8c962c0
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()
.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 8c962c0

Please sign in to comment.