-
Notifications
You must be signed in to change notification settings - Fork 717
Expand file tree
/
Copy pathDefaultMetadataMatcherPolicyTest.cs
More file actions
71 lines (59 loc) · 2.49 KB
/
DefaultMetadataMatcherPolicyTest.cs
File metadata and controls
71 lines (59 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) .NET Foundation and contributors. All rights reserved.
namespace Asp.Versioning.Routing;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.OData.Routing;
using Microsoft.AspNetCore.OData.Routing.Template;
using Microsoft.Extensions.Options;
using Microsoft.OData.Edm;
public class DefaultMetadataMatcherPolicyTest
{
[Fact]
public void applies_to_endpoints_should_return_true_for_service_document()
{
// arrange
var paramSource = Mock.Of<IApiVersionParameterSource>();
var options = Options.Create( new ApiVersioningOptions() );
var policy = new DefaultMetadataMatcherPolicy( paramSource, options );
#pragma warning disable CA1825 // Avoid zero-length array allocations
var metadata = new ODataRoutingMetadata( string.Empty, EdmCoreModel.Instance, [] );
#pragma warning restore CA1825 // Avoid zero-length array allocations
var items = new object[] { metadata };
var endpoints = new Endpoint[] { new( Limbo, new( items ), default ) };
// act
var result = policy.AppliesToEndpoints( endpoints );
// assert
result.Should().BeTrue();
}
[Fact]
public void applies_to_endpoints_should_return_true_for_metadata()
{
// arrange
var paramSource = Mock.Of<IApiVersionParameterSource>();
var options = Options.Create( new ApiVersioningOptions() );
var policy = new DefaultMetadataMatcherPolicy( paramSource, options );
var metadata = new ODataRoutingMetadata(
string.Empty,
EdmCoreModel.Instance,
new ODataPathTemplate( MetadataSegmentTemplate.Instance ) );
var items = new object[] { metadata };
var endpoints = new Endpoint[] { new( Limbo, new( items ), default ) };
// act
var result = policy.AppliesToEndpoints( endpoints );
// assert
result.Should().BeTrue();
}
[Fact]
public void applies_to_endpoints_should_return_false_for_normal_endpoints()
{
// arrange
var paramSource = Mock.Of<IApiVersionParameterSource>();
var options = Options.Create( new ApiVersioningOptions() );
var policy = new DefaultMetadataMatcherPolicy( paramSource, options );
var endpoints = new Endpoint[] { new( Limbo, new(), default ) };
// act
var result = policy.AppliesToEndpoints( endpoints );
// assert
result.Should().BeFalse();
}
private static Task Limbo( HttpContext context ) => Task.CompletedTask;
}