public void Get_ThrowsAnExceptionForInvalidEntityType()
        {
            // Arrange
            var services = new ServiceCollection();

            var options  = Mock.Of <IOptionsMonitor <OpenIddictEntityFrameworkCoreOptions> >();
            var provider = services.BuildServiceProvider();
            var resolver = new OpenIddictEntityFrameworkCoreApplicationStoreResolver(new TypeResolutionCache(), options, provider);

            // Act and assert
            var exception = Assert.Throws <InvalidOperationException>(() => resolver.Get <CustomApplication>());

            Assert.Equal(SR.GetResourceString(SR.ID0252), exception.Message);
        }
        public void Get_ReturnsCustomStoreCorrespondingToTheSpecifiedTypeWhenAvailable()
        {
            // Arrange
            var services = new ServiceCollection();

            services.AddSingleton(Mock.Of <IOpenIddictApplicationStore <CustomApplication> >());

            var options  = Mock.Of <IOptionsMonitor <OpenIddictEntityFrameworkCoreOptions> >();
            var provider = services.BuildServiceProvider();
            var resolver = new OpenIddictEntityFrameworkCoreApplicationStoreResolver(new TypeResolutionCache(), options, provider);

            // Act and assert
            Assert.NotNull(resolver.Get <CustomApplication>());
        }
        public void Get_ThrowsAnExceptionWhenDbContextTypeIsNotAvailable()
        {
            // Arrange
            var services = new ServiceCollection();

            var options = Mock.Of <IOptionsMonitor <OpenIddictEntityFrameworkCoreOptions> >(
                mock => mock.CurrentValue == new OpenIddictEntityFrameworkCoreOptions
            {
                DbContextType = null
            });

            var provider = services.BuildServiceProvider();
            var resolver = new OpenIddictEntityFrameworkCoreApplicationStoreResolver(new TypeResolutionCache(), options, provider);

            // Act and assert
            var exception = Assert.Throws <InvalidOperationException>(() => resolver.Get <OpenIddictEntityFrameworkCoreApplication>());

            Assert.Equal(SR.GetResourceString(SR.ID0253), exception.Message);
        }
        public void Get_ThrowsAnExceptionForInvalidEntityType()
        {
            // Arrange
            var services = new ServiceCollection();

            var options  = Mock.Of <IOptionsMonitor <OpenIddictEntityFrameworkCoreOptions> >();
            var provider = services.BuildServiceProvider();
            var resolver = new OpenIddictEntityFrameworkCoreApplicationStoreResolver(new TypeResolutionCache(), options, provider);

            // Act and assert
            var exception = Assert.Throws <InvalidOperationException>(() => resolver.Get <CustomApplication>());

            Assert.Equal(new StringBuilder()
                         .AppendLine("The specified application type is not compatible with the Entity Framework Core stores.")
                         .Append("When enabling the Entity Framework Core stores, make sure you use the built-in ")
                         .Append("'OpenIddictEntityFrameworkCoreApplication' entity or a custom entity that inherits ")
                         .Append("from the generic 'OpenIddictEntityFrameworkCoreApplication' entity.")
                         .ToString(), exception.Message);
        }
        public void Get_ThrowsAnExceptionWhenDbContextTypeIsNotAvailable()
        {
            // Arrange
            var services = new ServiceCollection();

            var options = Mock.Of <IOptionsMonitor <OpenIddictEntityFrameworkCoreOptions> >(
                mock => mock.CurrentValue == new OpenIddictEntityFrameworkCoreOptions
            {
                DbContextType = null
            });

            var provider = services.BuildServiceProvider();
            var resolver = new OpenIddictEntityFrameworkCoreApplicationStoreResolver(new TypeResolutionCache(), options, provider);

            // Act and assert
            var exception = Assert.Throws <InvalidOperationException>(() => resolver.Get <OpenIddictEntityFrameworkCoreApplication>());

            Assert.Equal(new StringBuilder()
                         .AppendLine("No Entity Framework Core context was specified in the OpenIddict options.")
                         .Append("To configure the OpenIddict Entity Framework Core stores to use a specific 'DbContext', ")
                         .Append("use 'options.UseEntityFrameworkCore().UseDbContext<TContext>()'.")
                         .ToString(), exception.Message);
        }