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

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

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

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

            services.AddSingleton(Mock.Of <IOpenIddictScopeStore <CustomScope> >());

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

            // Act and assert
            Assert.NotNull(resolver.Get <CustomScope>());
        }
Пример #3
0
    public void Get_ThrowsAnExceptionWhenDbContextTypeIsNotAvailable()
    {
        // Arrange
        var services = new ServiceCollection();

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

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

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

        Assert.Equal(SR.GetResourceString(SR.ID0235), exception.Message);
    }
Пример #4
0
        public void Get_ThrowsAnExceptionForInvalidEntityType()
        {
            // Arrange
            var services = new ServiceCollection();

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

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

            Assert.Equal(new StringBuilder()
                         .AppendLine("The specified scope type is not compatible with the Entity Framework 6.x stores.")
                         .Append("When enabling the Entity Framework 6.x stores, make sure you use the built-in ")
                         .Append("'OpenIddictEntityFrameworkScope' entity or a custom entity that inherits ")
                         .Append("from the generic 'OpenIddictEntityFrameworkScope' entity.")
                         .ToString(), exception.Message);
        }
Пример #5
0
        public void Get_ThrowsAnExceptionWhenDbContextTypeIsNotAvailable()
        {
            // Arrange
            var services = new ServiceCollection();

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

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

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

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