Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RegistrationTests #57

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
{

}
Loading