public void ShouldEmitSystemTextJsonPropertyName()
        {
            // Arrange
            var mvcOutputFormatter = new MvcOutputFormatter(FormatterOptions.WithSystemTextJsonFormatter, new FakeLoggerFactory());
            var responseExample    = new ResponseExample(mvcOutputFormatter);
            var sut = new ServiceProviderExamplesOperationFilter(serviceProvider, null, responseExample);

            var response = new OpenApiResponse {
                Content = new Dictionary <string, OpenApiMediaType> {
                    { "application/json", new OpenApiMediaType() }
                }
            };
            var operation = new OpenApiOperation {
                OperationId = "foobar", Responses = new OpenApiResponses()
            };

            operation.Responses.Add("200", response);
            var filterContext = FilterContextFor(typeof(FakeActions), nameof(FakeActions.AnnotatedWithSwaggerResponseAttribute));

            SetSwaggerResponses(operation, filterContext);

            // Act
            sut.Apply(operation, filterContext);

            // Assert
            string jsonExample     = ((OpenApiRawString)response.Content["application/json"].Example).Value;
            var    expectedExample = new PersonResponseAutoExample().GetExamples();

            jsonExample.ShouldContain($"\"lastagain\": \"{expectedExample.LastName}\"", Case.Sensitive);
        }
        public ServiceProviderExamplesOperationFilterTests()
        {
            schemaGeneratorOptions = new SchemaGeneratorOptions();

            var mvcOutputFormatter = new MvcOutputFormatter(FormatterOptions.WithXmlAndNewtonsoftJsonFormatters, new FakeLoggerFactory());

            var requestExample  = new RequestExample(mvcOutputFormatter, Options.Create(swaggerOptions));
            var responseExample = new ResponseExample(mvcOutputFormatter);

            serviceProvider = Substitute.For <IServiceProvider>();
            serviceProvider.GetService(typeof(IExamplesProvider <PersonResponse>)).Returns(new PersonResponseAutoExample());

            sut = new ServiceProviderExamplesOperationFilter(serviceProvider, requestExample, responseExample);
        }
        public ExamplesOperationFilterTests()
        {
            var options = Options.Create(new MvcJsonOptions());
            var serializerSettingsDuplicator = new SerializerSettingsDuplicator(options);

            var jsonFormatter = new JsonFormatter();

            var serviceProvider = Substitute.For <IServiceProvider>();

            var requestExample  = new RequestExample(jsonFormatter, serializerSettingsDuplicator);
            var responseExample = new ResponseExample(jsonFormatter, serializerSettingsDuplicator);

            sut = new ExamplesOperationFilter(serviceProvider, requestExample, responseExample);
        }
        public ServiceProviderExamplesOperationFilterTests()
        {
            var options = Options.Create(new MvcJsonOptions());
            var serializerSettingsDuplicator = new SerializerSettingsDuplicator(options);

            var jsonFormatter = new JsonFormatter();

            var requestExample  = new RequestExample(jsonFormatter, serializerSettingsDuplicator);
            var responseExample = new ResponseExample(jsonFormatter, serializerSettingsDuplicator);

            serviceProvider = Substitute.For <IServiceProvider>();
            serviceProvider.GetService(typeof(IExamplesProvider <PersonResponse>)).Returns(new PersonResponseAutoExample());

            sut = new ServiceProviderExamplesOperationFilter(serviceProvider, requestExample, responseExample);
        }
        public ServiceProviderExamplesOperationFilterTests()
        {
            var mvcJsonOptions = Options.Create(new MvcJsonOptions());

            schemaGeneratorOptions = new SchemaGeneratorOptions();
            var serializerSettingsDuplicator = new SerializerSettingsDuplicator(mvcJsonOptions, Options.Create(schemaGeneratorOptions));

            var jsonFormatter      = new JsonFormatter();
            var mvcOutputFormatter = new MvcOutputFormatter(FormatterOptions.WithoutFormatters, new FakeLoggerFactory());

            var requestExample  = new RequestExample(jsonFormatter, serializerSettingsDuplicator, mvcOutputFormatter, Options.Create(swaggerOptions));
            var responseExample = new ResponseExample(jsonFormatter, serializerSettingsDuplicator, mvcOutputFormatter);

            serviceProvider = Substitute.For <IServiceProvider>();
            serviceProvider.GetService(typeof(IExamplesProvider <PersonResponse>)).Returns(new PersonResponseAutoExample());

            sut = new ServiceProviderExamplesOperationFilter(serviceProvider, requestExample, responseExample);
        }
        public ExamplesOperationFilterTests()
        {
            var mvcJsonOptions = Options.Create(new MvcJsonOptions());

            schemaGeneratorOptions = new SchemaGeneratorOptions();
            var serializerSettingsDuplicator = new SerializerSettingsDuplicator(mvcJsonOptions, Options.Create(schemaGeneratorOptions));

            var jsonFormatter = new JsonFormatter();

            var serviceProvider = Substitute.For <IServiceProvider>();

            serviceProvider.GetService(typeof(PersonResponseExample)).Returns(new PersonResponseExample());
            serviceProvider.GetService(typeof(PersonRequestExample)).Returns(new PersonRequestExample());
            serviceProvider.GetService(typeof(DictionaryRequestExample)).Returns(new DictionaryRequestExample());

            var requestExample  = new RequestExample(jsonFormatter, serializerSettingsDuplicator);
            var responseExample = new ResponseExample(jsonFormatter, serializerSettingsDuplicator);

            sut = new ExamplesOperationFilter(serviceProvider, requestExample, responseExample);
        }