From 56b0ea5c43075b7abb0b970cf03477b5dce0ce30 Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Mon, 16 Oct 2023 22:10:44 -0400 Subject: [PATCH] Add RegistrationTests --- .../Passwordless.AspNetCore.Tests.csproj | 1 + .../RegistrationTests.cs | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/Passwordless.AspNetCore.Tests/RegistrationTests.cs diff --git a/tests/Passwordless.AspNetCore.Tests/Passwordless.AspNetCore.Tests.csproj b/tests/Passwordless.AspNetCore.Tests/Passwordless.AspNetCore.Tests.csproj index c4bfa1e..5c7815b 100644 --- a/tests/Passwordless.AspNetCore.Tests/Passwordless.AspNetCore.Tests.csproj +++ b/tests/Passwordless.AspNetCore.Tests/Passwordless.AspNetCore.Tests.csproj @@ -9,6 +9,7 @@ + diff --git a/tests/Passwordless.AspNetCore.Tests/RegistrationTests.cs b/tests/Passwordless.AspNetCore.Tests/RegistrationTests.cs new file mode 100644 index 0000000..eebabd1 --- /dev/null +++ b/tests/Passwordless.AspNetCore.Tests/RegistrationTests.cs @@ -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 + { + ["ApiSecret"] = "FakeApiSecret", + ["ApiUrl"] = "https://example.org", + ["SignInScheme"] = "Cookies", + ["Register:Discoverable"] = "false" + }) + .Build(); + + var serviceCollection = new ServiceCollection(); + + serviceCollection.AddDbContext(); + + serviceCollection + .AddIdentity() + .AddEntityFrameworkStores() + .AddPasswordless(configuration); + + var provider = serviceCollection.BuildServiceProvider(); + + _ = provider.GetRequiredService(); + _ = provider.GetRequiredService>(); + var optionsAccessor = provider.GetRequiredService>(); + 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 +{ + +} \ No newline at end of file