Exemple #1
0
        public void Configure_RegistersModelMetadataDetailsProviders()
        {
            // Arrange
            var services = new ServiceCollection();

            services.AddOptions();

            var builder = new OpenIddictServerBuilder(services);

            // Act
            builder.UseMvc();

            var options = services.BuildServiceProvider().GetRequiredService <IOptions <MvcOptions> >();

            // Assert
            Assert.Contains(
                options.Value.ModelMetadataDetailsProviders.OfType <BindingSourceMetadataProvider>(),
                provider => provider.Type == typeof(OpenIdConnectRequest) &&
                provider.BindingSource == BindingSource.Special);
            Assert.Contains(
                options.Value.ModelMetadataDetailsProviders.OfType <BindingSourceMetadataProvider>(),
                provider => provider.Type == typeof(OpenIdConnectResponse) &&
                provider.BindingSource == BindingSource.Special);

            Assert.Contains(
                options.Value.ModelMetadataDetailsProviders.OfType <SuppressChildValidationMetadataProvider>(),
                provider => provider.Type == typeof(OpenIdConnectRequest));
            Assert.Contains(
                options.Value.ModelMetadataDetailsProviders.OfType <SuppressChildValidationMetadataProvider>(),
                provider => provider.Type == typeof(OpenIdConnectResponse));
        }
        public void UseMvc_ThrowsAnExceptionForNullConfiguration()
        {
            // Arrange
            var services = new ServiceCollection();
            var builder  = new OpenIddictServerBuilder(services);

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

            Assert.Equal("configuration", exception.ParamName);
        }
        public void UseMvc_RegistersConfiguration()
        {
            // Arrange
            var services = new ServiceCollection();

            services.AddOptions();

            var builder = new OpenIddictServerBuilder(services);

            // Act
            builder.UseMvc();

            // Assert
            Assert.Contains(services, service => service.ServiceType == typeof(IConfigureOptions <MvcOptions>) &&
                            service.ImplementationType == typeof(OpenIddictMvcConfiguration));
        }
Exemple #4
0
        public void Configure_RegistersModelBinderProvider()
        {
            // Arrange
            var services = new ServiceCollection();

            services.AddOptions();

            var builder = new OpenIddictServerBuilder(services);

            // Act
            builder.UseMvc();

            var options = services.BuildServiceProvider().GetRequiredService <IOptions <MvcOptions> >();

            // Assert
            Assert.Contains(options.Value.ModelBinderProviders, binder => binder is OpenIddictMvcBinderProvider);
        }