private static ApiDescriptionGroupCollection GetApiDescriptionGroups(Type controllerType)
        {
            var options = Mock.Of <IOptions <MvcOptions> >(m => m.Value == new MvcOptions());
            var applicationPartManager = new ApplicationPartManager();

            applicationPartManager.FeatureProviders.Add(new TestControllerFeatureProvider(controllerType));

            var actionDescriptorProvider = new ControllerActionDescriptorProvider(
                applicationPartManager,
                new IApplicationModelProvider[]
            {
                new DefaultApplicationModelProvider(options, new EmptyModelMetadataProvider()),
                new MakeApiExplorerVisibleProvider(),
            },
                options);

            var actionDescriptorProviderContext = new ActionDescriptorProviderContext();

            actionDescriptorProvider.OnProvidersExecuting(actionDescriptorProviderContext);

            var apiDescriptionProvider = new DefaultApiDescriptionProvider(options, Mock.Of <IInlineConstraintResolver>(),
                                                                           new EmptyModelMetadataProvider(), new ActionResultTypeMapper());

            var apiDescriptionProviderContext = new ApiDescriptionProviderContext(actionDescriptorProviderContext.Results.ToArray());

            apiDescriptionProvider.OnProvidersExecuting(apiDescriptionProviderContext);

            var groups = apiDescriptionProviderContext.Results.GroupBy(a => a.GroupName)
                         .Select(g => new ApiDescriptionGroup(g.Key, g.ToArray()))
                         .ToArray();

            return(new ApiDescriptionGroupCollection(groups, version: 1));
        }
Exemple #2
0
        private IReadOnlyList <ApiDescription> GetApiDescriptions()
        {
            var context = new ApiDescriptionProviderContext(_actionDescriptors);

            var options = new MvcOptions();

            options.InputFormatters.Add(new JsonInputFormatter(new Mock <ILogger>().Object, new JsonSerializerSettings(), ArrayPool <char> .Shared, new DefaultObjectPoolProvider()));
            options.OutputFormatters.Add(new JsonOutputFormatter(new JsonSerializerSettings(), ArrayPool <char> .Shared));

            var optionsAccessor = new Mock <IOptions <MvcOptions> >();

            optionsAccessor.Setup(o => o.Value).Returns(options);

            var constraintResolver = new Mock <IInlineConstraintResolver>();

            constraintResolver.Setup(i => i.ResolveConstraint("int")).Returns(new IntRouteConstraint());

            var provider = new DefaultApiDescriptionProvider(
                optionsAccessor.Object,
                constraintResolver.Object,
                CreateDefaultProvider()
                );

            provider.OnProvidersExecuting(context);
            provider.OnProvidersExecuted(context);
            return(new ReadOnlyCollection <ApiDescription>(context.Results));
        }
        private IReadOnlyList <ApiDescription> GetApiDescriptions()
        {
            var context = new ApiDescriptionProviderContext(_actionDescriptors);

            var options = new MvcOptions();

            options.OutputFormatters.Add(new JsonOutputFormatter());

            var optionsAccessor = new Mock <IOptions <MvcOptions> >();

            optionsAccessor.Setup(o => o.Value).Returns(options);

            var constraintResolver = new Mock <IInlineConstraintResolver>();

            constraintResolver.Setup(i => i.ResolveConstraint("int")).Returns(new IntRouteConstraint());

            var provider = new DefaultApiDescriptionProvider(
                optionsAccessor.Object,
                constraintResolver.Object,
                CreateModelMetadataProvider()
                );

            provider.OnProvidersExecuting(context);
            provider.OnProvidersExecuted(context);
            return(new ReadOnlyCollection <ApiDescription>(context.Results));
        }
        private IReadOnlyList <ApiDescription> GetApiDescriptions()
        {
            var actionDescriptors = this.CreateActionDescriptors();
            var context           = new ApiDescriptionProviderContext(actionDescriptors);

            var options = new MvcOptions();

            options.InputFormatters.Add(
                new JsonInputFormatter(Mock.Of <ILogger>(), new JsonSerializerSettings(), ArrayPool <char> .Shared, new DefaultObjectPoolProvider(), false)
                );
            options.OutputFormatters.Add(new JsonOutputFormatter(new JsonSerializerSettings(), ArrayPool <char> .Shared));

            var constraintResolver = new Mock <IInlineConstraintResolver>();

            constraintResolver.Setup(i => i.ResolveConstraint("int")).Returns(new IntRouteConstraint());

            var provider = new DefaultApiDescriptionProvider(
                Options.Create(options),
                constraintResolver.Object,
                CreateModelMetadataProvider()
                , new ActionResultTypeMapper());

            provider.OnProvidersExecuting(context);
            provider.OnProvidersExecuted(context);
            return(new ReadOnlyCollection <ApiDescription>(context.Results));
        }
        private IReadOnlyList <ApiDescription> GetApiDescriptions()
        {
            var context = new ApiDescriptionProviderContext(_actionDescriptors);

            var formattersProvider = new Mock <IOutputFormattersProvider>();

            formattersProvider.Setup(i => i.OutputFormatters).Returns(new[] { new JsonOutputFormatter() });

            var constraintResolver = new Mock <IInlineConstraintResolver>();

            constraintResolver.Setup(i => i.ResolveConstraint("int")).Returns(new IntRouteConstraint());

            var provider = new DefaultApiDescriptionProvider(
                formattersProvider.Object,
                constraintResolver.Object,
                CreateModelMetadataProvider()
                );

            provider.OnProvidersExecuting(context);
            provider.OnProvidersExecuted(context);
            return(new ReadOnlyCollection <ApiDescription>(context.Results));
        }
        private IReadOnlyList<ApiDescription> GetApiDescriptions(
            ActionDescriptor action,
            List<MockFormatter> formatters)
        {
            var context = new ApiDescriptionProviderContext(new ActionDescriptor[] { action });

            var options = new MvcOptions();
            foreach (var formatter in formatters)
            {
                options.OutputFormatters.Add(formatter);
            }

            var optionsAccessor = new Mock<IOptions<MvcOptions>>();
            optionsAccessor.SetupGet(o => o.Value)
                .Returns(options);

            var constraintResolver = new Mock<IInlineConstraintResolver>();
            constraintResolver.Setup(c => c.ResolveConstraint("int"))
                .Returns(new IntRouteConstraint());

            var modelMetadataProvider = TestModelMetadataProvider.CreateDefaultProvider();

            var provider = new DefaultApiDescriptionProvider(
                optionsAccessor.Object,
                constraintResolver.Object,
                modelMetadataProvider);

            provider.OnProvidersExecuting(context);
            provider.OnProvidersExecuted(context);

            return new ReadOnlyCollection<ApiDescription>(context.Results);
        }
        private IReadOnlyList<ApiDescription> GetApiDescriptions()
        {
            var context = new ApiDescriptionProviderContext(_actionDescriptors);

            var options = new MvcOptions();
            options.OutputFormatters.Add(new JsonOutputFormatter());

            var optionsAccessor = new Mock<IOptions<MvcOptions>>();
            optionsAccessor.Setup(o => o.Value).Returns(options);

            var constraintResolver = new Mock<IInlineConstraintResolver>();
            constraintResolver.Setup(i => i.ResolveConstraint("int")).Returns(new IntRouteConstraint());

            var provider = new DefaultApiDescriptionProvider(
                optionsAccessor.Object,
                constraintResolver.Object,
                CreateModelMetadataProvider()
            );

            provider.OnProvidersExecuting(context);
            provider.OnProvidersExecuted(context);
            return new ReadOnlyCollection<ApiDescription>(context.Results);
        }
        private IReadOnlyList<ApiDescription> GetApiDescriptions(
            ActionDescriptor action,
            List<MockFormatter> formatters)
        {
            var context = new ApiDescriptionProviderContext(new ActionDescriptor[] { action });

            var formattersProvider = new Mock<IOutputFormattersProvider>(MockBehavior.Strict);
            formattersProvider.Setup(fp => fp.OutputFormatters).Returns(formatters);

            var constraintResolver = new Mock<IInlineConstraintResolver>();
            constraintResolver.Setup(c => c.ResolveConstraint("int"))
                .Returns(new IntRouteConstraint());

            var modelMetadataProvider = TestModelMetadataProvider.CreateDefaultProvider();

            var provider = new DefaultApiDescriptionProvider(
                formattersProvider.Object,
                constraintResolver.Object,
                modelMetadataProvider);

            provider.OnProvidersExecuting(context);
            provider.OnProvidersExecuted(context);

            return new ReadOnlyCollection<ApiDescription>(context.Results);
        }