Ejemplo n.º 1
0
        public void get_group_name_should_return_expected_text(ApiVersion version, string groupName)
        {
            // arrange
            var formatter = new DefaultApiVersionGroupNameFormatter();

            // act
            var result = formatter.GetGroupName(version);

            // assert
            result.Should().Be(groupName);
        }
        public void api_version_descriptions_should_collate_expected_versions()
        {
            // arrange
            var actionProvider      = new TestActionDescriptorCollectionProvider();
            var groupNameFormatter  = new DefaultApiVersionGroupNameFormatter();
            var descriptionProvider = new DefaultApiVersionDescriptionProvider(actionProvider, groupNameFormatter);

            // act
            var descriptions = descriptionProvider.ApiVersionDescriptions;

            // assert
            descriptions.ShouldBeEquivalentTo(
                new[]
            {
                new ApiVersionDescription(new ApiVersion(0, 9), "v0.9", true),
                new ApiVersionDescription(new ApiVersion(1, 0), "v1", false),
                new ApiVersionDescription(new ApiVersion(2, 0), "v2", false),
                new ApiVersionDescription(new ApiVersion(3, 0), "v3", false)
            });
        }
Ejemplo n.º 3
0
        public void versioned_api_explorer_should_group_and_order_descriptions_on_providers_executed()
        {
            // arrange
            var actionProvider        = new TestActionDescriptorCollectionProvider();
            var context               = new ApiDescriptionProviderContext(actionProvider.ActionDescriptors.Items);
            var groupNameFormatter    = new DefaultApiVersionGroupNameFormatter();
            var modelMetadataProvider = NewModelMetadataProvider();
            var apiExplorer           = new VersionedApiDescriptionProvider(groupNameFormatter, modelMetadataProvider);

            foreach (var action in context.Actions)
            {
                context.Results.Add(new ApiDescription()
                {
                    ActionDescriptor = action
                });
            }

            // act
            apiExplorer.OnProvidersExecuted(context);

            // assert
            context.Results.ShouldBeEquivalentTo(
                new[]
            {
                // orders
                new { GroupName = "v0.9", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(0, 9)
                      } },
                new { GroupName = "v1", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(1, 0)
                      } },
                new { GroupName = "v1", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(1, 0)
                      } },
                new { GroupName = "v2", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(2, 0)
                      } },
                new { GroupName = "v2", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(2, 0)
                      } },
                new { GroupName = "v2", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(2, 0)
                      } },
                new { GroupName = "v3", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(3, 0)
                      } },
                new { GroupName = "v3", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(3, 0)
                      } },
                new { GroupName = "v3", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(3, 0)
                      } },
                new { GroupName = "v3", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(3, 0)
                      } },

                // people
                new { GroupName = "v0.9", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(0, 9)
                      } },
                new { GroupName = "v1", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(1, 0)
                      } },
                new { GroupName = "v1", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(1, 0)
                      } },
                new { GroupName = "v2", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(2, 0)
                      } },
                new { GroupName = "v2", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(2, 0)
                      } },
                new { GroupName = "v2", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(2, 0)
                      } },
                new { GroupName = "v3", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(3, 0)
                      } },
                new { GroupName = "v3", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(3, 0)
                      } },
                new { GroupName = "v3", Properties = new Dictionary <object, object>()
                      {
                          [typeof(ApiVersion)] = new ApiVersion(3, 0)
                      } },
            },
                options => options.ExcludingMissingMembers());
        }