/* * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) * See https://github.com/openiddict/openiddict-core for more information concerning * the license and the contributors participating to this project. */ using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Moq; using OpenIddict.Abstractions; using OpenIddict.MongoDb.Models; using Xunit; using SR = OpenIddict.Abstractions.OpenIddictResources; namespace OpenIddict.MongoDb.Tests { public class OpenIddictMongoDbApplicationStoreResolverTests { [Fact] public void Get_ReturnsCustomStoreCorrespondingToTheSpecifiedTypeWhenAvailable() { // Arrange var services = new ServiceCollection(); services.AddSingleton(Mock.Of>()); var provider = services.BuildServiceProvider(); var resolver = new OpenIddictMongoDbApplicationStoreResolver(provider); // Act and assert Assert.NotNull(resolver.Get()); } [Fact] public void Get_ThrowsAnExceptionForInvalidEntityType() { // Arrange var services = new ServiceCollection(); var provider = services.BuildServiceProvider(); var resolver = new OpenIddictMongoDbApplicationStoreResolver(provider); // Act and assert var exception = Assert.Throws(() => resolver.Get()); Assert.Equal(SR.GetResourceString(SR.ID1256), exception.Message); } [Fact] public void Get_ReturnsDefaultStoreCorrespondingToTheSpecifiedTypeWhenAvailable() { // Arrange var services = new ServiceCollection(); services.AddSingleton(Mock.Of>()); services.AddSingleton(CreateStore()); var provider = services.BuildServiceProvider(); var resolver = new OpenIddictMongoDbApplicationStoreResolver(provider); // Act and assert Assert.NotNull(resolver.Get()); } private static OpenIddictMongoDbApplicationStore CreateStore() => new Mock>( Mock.Of(), Mock.Of>()).Object; public class CustomApplication { } public class MyApplication : OpenIddictMongoDbApplication { } } }