Example #1
0
    public void GetApiConvention_ReturnsResultFromFirstMatchingConvention()
    {
        // Arrange
        var method = typeof(GetApiConvention_ReturnsResultFromFirstMatchingConventionController)
                     .GetMethod(nameof(GetApiConvention_ReturnsResultFromFirstMatchingConventionController.Get));
        var attributes = new[]
        {
            new ApiConventionTypeAttribute(typeof(GetApiConvention_ReturnsResultFromConventionType)),
            new ApiConventionTypeAttribute(typeof(DefaultApiConventions)),
        };

        // Act
        var result = ApiConventionResult.TryGetApiConvention(method, attributes, result: out var conventionResult);

        // Assert
        Assert.True(result);
        Assert.Collection(
            conventionResult.ResponseMetadataProviders.OrderBy(o => o.StatusCode),
            r => Assert.Equal(200, r.StatusCode),
            r => Assert.Equal(202, r.StatusCode),
            r => Assert.Equal(404, r.StatusCode));
    }
Example #2
0
    public void GetApiConvention_DeleteAction_MatchesDefaultConvention()
    {
        // Arrange
        var method = typeof(DefaultConventionController)
                     .GetMethod(nameof(DefaultConventionController.Delete));
        var conventions = new[]
        {
            new ApiConventionTypeAttribute(typeof(DefaultApiConventions)),
        };

        // Act
        var result = ApiConventionResult.TryGetApiConvention(method, conventions, out var conventionResult);

        // Assert
        Assert.True(result);
        Assert.Collection(
            conventionResult.ResponseMetadataProviders.OrderBy(o => o.StatusCode),
            r => Assert.IsAssignableFrom <IApiDefaultResponseMetadataProvider>(r),
            r => Assert.Equal(200, r.StatusCode),
            r => Assert.Equal(400, r.StatusCode),
            r => Assert.Equal(404, r.StatusCode));
    }