コード例 #1
0
    public void Get_ThrowsAnExceptionWhenStoreCannotBeFound()
    {
        // Arrange
        var services = new ServiceCollection();
        var provider = services.BuildServiceProvider();
        var resolver = new OpenIddictAuthorizationStoreResolver(provider);

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

        Assert.Equal(SR.GetResourceString(SR.ID0229), exception.Message);
    }
コード例 #2
0
        public void Get_ReturnsCustomStoreCorrespondingToTheSpecifiedType()
        {
            // Arrange
            var services = new ServiceCollection();

            services.AddSingleton(Mock.Of <IOpenIddictAuthorizationStore <OpenIddictAuthorization> >());

            var provider = services.BuildServiceProvider();
            var resolver = new OpenIddictAuthorizationStoreResolver(provider);

            // Act and assert
            Assert.NotNull(resolver.Get <OpenIddictAuthorization>());
        }
コード例 #3
0
        public void Get_ReturnsCustomStoreCorrespondingToTheSpecifiedTypeWhenAvailable()
        {
            // Arrange
            var services = new ServiceCollection();

            services.AddSingleton(Mock.Of <IOpenIddictAuthorizationStore <CustomAuthorization> >());

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

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

            services.AddSingleton(Mock.Of <IOpenIddictAuthorizationStore <CustomAuthorization> >());
            services.AddSingleton(CreateStore());

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

            // Act and assert
            Assert.NotNull(resolver.Get <MyAuthorization>());
        }
コード例 #5
0
        public void Get_ThrowsAnExceptionWhenStoreCannotBeFound()
        {
            // Arrange
            var services = new ServiceCollection();
            var provider = services.BuildServiceProvider();
            var resolver = new OpenIddictAuthorizationStoreResolver(provider);

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

            Assert.Equal(new StringBuilder()
                         .AppendLine("No authorization store has been registered in the dependency injection container.")
                         .Append("To register the Entity Framework Core stores, reference the 'OpenIddict.EntityFrameworkCore' ")
                         .AppendLine("package and call 'services.AddOpenIddict().AddCore().UseEntityFrameworkCore()'.")
                         .Append("To register a custom store, create an implementation of 'IOpenIddictAuthorizationStore' and ")
                         .Append("use 'services.AddOpenIddict().AddCore().AddAuthorizationStore()' to add it to the DI container.")
                         .ToString(), exception.Message);
        }
        public void Get_ThrowsAnExceptionForInvalidEntityType()
        {
            // Arrange
            var services = new ServiceCollection();

            var provider = services.BuildServiceProvider();
            var resolver = new OpenIddictAuthorizationStoreResolver(provider);

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

            Assert.Equal(new StringBuilder()
                         .AppendLine("The specified authorization type is not compatible with the MongoDB stores.")
                         .Append("When enabling the MongoDB stores, make sure you use the built-in 'OpenIddictAuthorization' ")
                         .Append("entity (from the 'OpenIddict.MongoDb.Models' package) or a custom entity ")
                         .Append("that inherits from the 'OpenIddictAuthorization' entity.")
                         .ToString(), exception.Message);
        }
コード例 #7
0
        public void Get_ThrowsAnExceptionForInvalidEntityType()
        {
            // Arrange
            var services = new ServiceCollection();

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

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

            Assert.Equal(new StringBuilder()
                         .AppendLine("The specified authorization 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("'OpenIddictAuthorization' entity (from the 'OpenIddict.EntityFramework.Models' package) ")
                         .Append("or a custom entity that inherits from the generic 'OpenIddictAuthorization' entity.")
                         .ToString(), exception.Message);
        }
コード例 #8
0
        public void Get_ReturnsDefaultStoreCorrespondingToTheSpecifiedTypeWhenAvailable()
        {
            // Arrange
            var services = new ServiceCollection();

            services.AddSingleton(Mock.Of <IOpenIddictAuthorizationStore <CustomAuthorization> >());
            services.AddSingleton(CreateStore());

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

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

            // Act and assert
            Assert.NotNull(resolver.Get <MyAuthorization>());
        }
コード例 #9
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 OpenIddictAuthorizationStoreResolver(new TypeResolutionCache(), options, provider);

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

            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);
        }