Example #1
0
        public void AddCore_ThrowsAnExceptionForNullConfiguration()
        {
            // Arrange
            var services = new ServiceCollection();
            var builder  = new OpenIddictBuilder(services);

            // Act and assert
            var exception = Assert.Throws <ArgumentNullException>(() => builder.AddCore(configuration: null));

            Assert.Equal("configuration", exception.ParamName);
        }
Example #2
0
    public void AddCore_RegistersDefaultManagers(Type type)
    {
        // Arrange
        var services = new ServiceCollection();
        var builder  = new OpenIddictBuilder(services);

        // Act
        builder.AddCore();

        // Assert
        Assert.Contains(services, service => service.ServiceType == type && service.ImplementationType == type);
    }
Example #3
0
    public void AddCore_RegistersOptionsServices()
    {
        // Arrange
        var services = new ServiceCollection();
        var builder  = new OpenIddictBuilder(services);

        // Act
        builder.AddCore();

        // Assert
        Assert.Contains(services, service => service.ServiceType == typeof(IOptions <>));
    }
Example #4
0
    public void AddCore_RegistersUntypedProxies(Type type)
    {
        // Arrange
        var services = new ServiceCollection();
        var builder  = new OpenIddictBuilder(services);

        // Act
        builder.AddCore();

        // Assert
        Assert.Contains(services, service => service.ServiceType == type && service.ImplementationFactory is not null);
    }
Example #5
0
    public void AddCore_ResolvingUntypedTokenManagerThrowsAnExceptionWhenDefaultEntityIsNotSet()
    {
        // Arrange
        var services = new ServiceCollection();
        var builder  = new OpenIddictBuilder(services);

        // Act
        builder.AddCore();

        // Assert
        var provider = services.BuildServiceProvider();

        var exception = Assert.Throws <InvalidOperationException>(provider.GetRequiredService <IOpenIddictTokenManager>);

        Assert.Equal(SR.GetResourceString(SR.ID0276), exception.Message);
    }
Example #6
0
    public void AddCore_ResolvingUntypedTokenManagerReturnsGenericManager()
    {
        // Arrange
        var services = new ServiceCollection();
        var builder  = new OpenIddictBuilder(services);

        // Act
        builder.AddCore(options =>
        {
            options.SetDefaultTokenEntity <OpenIddictToken>();
            options.Services.AddSingleton(Mock.Of <IOpenIddictTokenStore <OpenIddictToken> >());
        });

        var provider = services.BuildServiceProvider();
        var manager  = provider.GetRequiredService <IOpenIddictTokenManager>();

        // Assert
        Assert.IsType <OpenIddictTokenManager <OpenIddictToken> >(manager);
    }
Example #7
0
        public void AddCore_ResolvingUntypedTokenManagerThrowsAnExceptionWhenDefaultEntityIsNotSet()
        {
            // Arrange
            var services = new ServiceCollection();
            var builder  = new OpenIddictBuilder(services);

            // Act
            builder.AddCore();

            // Assert
            var provider = services.BuildServiceProvider();

            var exception = Assert.Throws <InvalidOperationException>(delegate
            {
                return(provider.GetRequiredService <IOpenIddictTokenManager>());
            });

            Assert.Equal(new StringBuilder()
                         .Append("No default token entity type was configured in the OpenIddict core options, ")
                         .AppendLine("which generally indicates that no token store was registered in the DI container.")
                         .Append("To register the Entity Framework Core stores, reference the 'OpenIddict.EntityFrameworkCore' ")
                         .Append("package and call 'services.AddOpenIddict().AddCore().UseEntityFrameworkCore()'.")
                         .ToString(), exception.Message);
        }