1
+ namespace Microsoft . Web . Http . Description
2
+ {
3
+ using FluentAssertions ;
4
+ using System ;
5
+ using System . Collections . Generic ;
6
+ using System . Linq ;
7
+ using System . Text ;
8
+ using System . Threading . Tasks ;
9
+ using System . Web . Http ;
10
+ using System . Web . OData ;
11
+ using Xunit ;
12
+ using static System . Net . Http . HttpMethod ;
13
+
14
+ public class ODataApiExplorerTest
15
+ {
16
+ [ Theory ]
17
+ [ ClassData ( typeof ( TestConfigurations ) ) ]
18
+ public void api_descriptions_should_collate_expected_versions ( HttpConfiguration configuration )
19
+ {
20
+ // arrange
21
+ var assembliesResolver = configuration . Services . GetAssembliesResolver ( ) ;
22
+ var controllerTypes = configuration . Services . GetHttpControllerTypeResolver ( ) . GetControllerTypes ( assembliesResolver ) ;
23
+ var apiExplorer = new ODataApiExplorer ( configuration ) ;
24
+
25
+ // act
26
+ var descriptions = apiExplorer . ApiDescriptions ;
27
+
28
+ // assert
29
+ descriptions . ApiVersions . Should ( ) . Equal (
30
+ new ApiVersion ( 0 , 9 ) ,
31
+ new ApiVersion ( 1 , 0 ) ,
32
+ new ApiVersion ( 2 , 0 ) ,
33
+ new ApiVersion ( 3 , 0 ) ) ;
34
+ }
35
+
36
+ [ Theory ]
37
+ [ ClassData ( typeof ( TestConfigurations ) ) ]
38
+ public void api_descriptions_should_group_versioned_controllers ( HttpConfiguration configuration )
39
+ {
40
+ // arrange
41
+ var assembliesResolver = configuration . Services . GetAssembliesResolver ( ) ;
42
+ var controllerTypes = configuration . Services . GetHttpControllerTypeResolver ( ) . GetControllerTypes ( assembliesResolver ) ;
43
+ var apiExplorer = new ODataApiExplorer ( configuration ) ;
44
+
45
+ // act
46
+ var descriptions = apiExplorer . ApiDescriptions ;
47
+
48
+ // assert
49
+ descriptions . SelectMany ( g => g . ApiDescriptions )
50
+ . Select ( d => d . ActionDescriptor . ControllerDescriptor . ControllerType )
51
+ . Distinct ( )
52
+ . Should ( )
53
+ . Equal ( controllerTypes ) ;
54
+ }
55
+
56
+ [ Theory ]
57
+ [ ClassData ( typeof ( TestConfigurations ) ) ]
58
+ public void api_descriptions_should_flatten_versioned_controllers ( HttpConfiguration configuration )
59
+ {
60
+ // arrange
61
+ var assembliesResolver = configuration . Services . GetAssembliesResolver ( ) ;
62
+ var controllerTypes = configuration . Services . GetHttpControllerTypeResolver ( ) . GetControllerTypes ( assembliesResolver ) ;
63
+ var apiExplorer = new ODataApiExplorer ( configuration ) ;
64
+
65
+ // act
66
+ var descriptions = apiExplorer . ApiDescriptions ;
67
+
68
+ // assert
69
+ descriptions . Flatten ( )
70
+ . Select ( d => d . ActionDescriptor . ControllerDescriptor . ControllerType )
71
+ . Distinct ( )
72
+ . Should ( )
73
+ . Equal ( controllerTypes ) ;
74
+ }
75
+
76
+ [ Theory ]
77
+ [ ClassData ( typeof ( TestConfigurations ) ) ]
78
+ public void api_descriptions_should_not_contain_metadata_controllers ( HttpConfiguration configuration )
79
+ {
80
+ // arrange
81
+ var assembliesResolver = configuration . Services . GetAssembliesResolver ( ) ;
82
+ var controllerTypes = configuration . Services . GetHttpControllerTypeResolver ( ) . GetControllerTypes ( assembliesResolver ) ;
83
+ var apiExplorer = new ODataApiExplorer ( configuration ) ;
84
+
85
+ // act
86
+ var descriptions = apiExplorer . ApiDescriptions ;
87
+
88
+ // assert
89
+ descriptions . Flatten ( )
90
+ . Select ( d => d . ActionDescriptor . ControllerDescriptor . ControllerType )
91
+ . Distinct ( )
92
+ . Should ( )
93
+ . NotContain ( type => typeof ( MetadataController ) . IsAssignableFrom ( type ) ) ;
94
+ }
95
+
96
+ [ Theory ]
97
+ [ ClassData ( typeof ( TestConfigurations ) ) ]
98
+ public void api_description_group_should_explore_v3_actions ( HttpConfiguration configuration )
99
+ {
100
+ // arrange
101
+ var apiVersion = new ApiVersion ( 3 , 0 ) ;
102
+ var apiExplorer = new ODataApiExplorer ( configuration ) ;
103
+ var descriptionGroup = apiExplorer . ApiDescriptions [ apiVersion ] ;
104
+
105
+ // act
106
+ var descriptions = descriptionGroup . ApiDescriptions ;
107
+ var relativePaths = descriptions . Select ( d => d . RelativePath ) . ToArray ( ) ;
108
+
109
+ // assert
110
+ descriptions . ShouldBeEquivalentTo (
111
+ new [ ]
112
+ {
113
+ new
114
+ {
115
+ ID = $ "GET{ relativePaths [ 0 ] } ",
116
+ HttpMethod = Get ,
117
+ RelativePath = relativePaths [ 0 ] ,
118
+ Version = apiVersion
119
+ } ,
120
+ new
121
+ {
122
+ ID = $ "GET{ relativePaths [ 1 ] } ",
123
+ HttpMethod = Get ,
124
+ RelativePath = relativePaths [ 1 ] ,
125
+ Version = apiVersion
126
+ } ,
127
+ new
128
+ {
129
+ ID = $ "POST{ relativePaths [ 2 ] } ",
130
+ HttpMethod = Post ,
131
+ RelativePath = relativePaths [ 2 ] ,
132
+ Version = apiVersion
133
+ } ,
134
+ new
135
+ {
136
+ ID = $ "DELETE{ relativePaths [ 3 ] } ",
137
+ HttpMethod = Delete ,
138
+ RelativePath = relativePaths [ 3 ] ,
139
+ Version = apiVersion
140
+ }
141
+ } ,
142
+ options => options . ExcludingMissingMembers ( ) ) ;
143
+ }
144
+ }
145
+ }
0 commit comments