public void GetHttpRequestsReturnsNullForTargetWithoutAnnotations(string name) { // Arrange IEdmModel model = GetEdmModel("", ""); var httpRequestProvider = new HttpRequestProvider(model); IEdmNavigationSource navigationSource = model.FindDeclaredNavigationSource(name); Assert.NotNull(navigationSource); // Act & Assert var requests = httpRequestProvider.GetHttpRequests(navigationSource as IEdmVocabularyAnnotatable); // Assert Assert.Null(requests); }
public void GetHttpRequestsReturnsForEdmModelNavigationSourceWithAnnotations(string name) { // Arrange string annotation = @" <Annotation Term=""Org.OData.Core.V1.HttpRequests""> <Collection> <Record> <PropertyValue Property=""Description"" /> <PropertyValue Property=""MethodDescription"" String=""Example"" /> <PropertyValue Property=""MethodType"" String=""DELETE"" /> <PropertyValue Property=""CustomHeaders""> <Collection> <Record> <PropertyValue Property=""Name"" String=""Authorization"" /> <PropertyValue Property=""Description"" String=""String"" /> <PropertyValue Property=""Required"" Bool=""false"" /> </Record> </Collection> </PropertyValue> <PropertyValue Property=""CustomQueryOptions""> <Collection /> </PropertyValue> <PropertyValue Property=""HttpResponses""> <Collection> <Record> <PropertyValue Property=""ResponseCode"" String=""204"" /> <PropertyValue Property=""Examples""> <Record Type=""Org.OData.Core.V1.InlineExample""> <PropertyValue Property=""InlineExample"" /> <PropertyValue Property=""Description"" /> </Record> </PropertyValue> </Record> </Collection> </PropertyValue> <PropertyValue Property=""SecuritySchemes""> <Collection> <Record> <PropertyValue Property=""AuthorizationSchemeName"" String=""Delegated (work or school account)"" /> <PropertyValue Property=""RequiredScopes""> <Collection> <String>Directory.AccessAsUser.All</String> </Collection> </PropertyValue> </Record> </Collection> </PropertyValue> </Record> <Record> <PropertyValue Property=""Description"" /> <PropertyValue Property=""MethodDescription"" String=""Example"" /> <PropertyValue Property=""MethodType"" String=""GET"" /> <PropertyValue Property=""CustomHeaders""> <Collection> <Record> <PropertyValue Property=""Name"" String=""Authorization"" /> <PropertyValue Property=""Description"" String=""String"" /> <PropertyValue Property=""Required"" Bool=""false"" /> </Record> </Collection> </PropertyValue> <PropertyValue Property=""CustomQueryOptions""> <Collection /> </PropertyValue> <PropertyValue Property=""HttpResponses""> <Collection> <Record> <PropertyValue Property=""ResponseCode"" String=""200"" /> <PropertyValue Property=""Examples""> <Record Type=""Org.OData.Core.V1.InlineExample""> <PropertyValue Property=""InlineExample"" String=""{
 "accountEnabled":false,
 "deviceId":"4c299165-6e8f-4b45-a5ba-c5d250a707ff",
 "displayName":"Test device",
 "id": "id-value",
 "operatingSystem":"linux",
 "operatingSystemVersion":"1"
}
"" /> <PropertyValue Property=""Description"" String=""application/json"" /> </Record> </PropertyValue> </Record> </Collection> </PropertyValue> <PropertyValue Property=""SecuritySchemes""> <Collection> <Record> <PropertyValue Property=""AuthorizationSchemeName"" String=""Delegated (work or school account)"" /> <PropertyValue Property=""RequiredScopes""> <Collection> <String>Directory.Read.All</String> <String>Directory.ReadWrite.All</String> <String>Directory.AccessAsUser.All</String> </Collection> </PropertyValue> </Record> <Record> <PropertyValue Property=""AuthorizationSchemeName"" String=""Application"" /> <PropertyValue Property=""RequiredScopes""> <Collection> <String>Device.ReadWrite.All</String> <String>Directory.Read.All</String> <String>Directory.ReadWrite.All</String> </Collection> </PropertyValue> </Record> </Collection> </PropertyValue> </Record> <Record> <PropertyValue Property=""Description"" /> <PropertyValue Property=""MethodDescription"" String=""PATCH Example"" /> <PropertyValue Property=""MethodType"" String=""PATCH"" /> <PropertyValue Property=""CustomHeaders""> <Collection> <Record> <PropertyValue Property=""Name"" String=""Authorization"" /> <PropertyValue Property=""Description"" String=""String"" /> <PropertyValue Property=""Required"" Bool=""false"" /> </Record> </Collection> </PropertyValue> <PropertyValue Property=""CustomQueryOptions""> <Collection /> </PropertyValue> <PropertyValue Property=""HttpResponses""> <Collection> <Record> <PropertyValue Property=""ResponseCode"" String=""204"" /> <PropertyValue Property=""Examples""> <Record Type=""Org.OData.Core.V1.InlineExample""> <PropertyValue Property=""InlineExample"" /> <PropertyValue Property=""Description"" /> </Record> </PropertyValue> </Record> </Collection> </PropertyValue> <PropertyValue Property=""SecuritySchemes""> <Collection> <Record> <PropertyValue Property=""AuthorizationSchemeName"" String=""Delegated (work or school account)"" /> <PropertyValue Property=""RequiredScopes""> <Collection> <String>Directory.ReadWrite.All</String> <String>Directory.AccessAsUser.All</String> </Collection> </PropertyValue> </Record> </Collection> </PropertyValue> </Record> </Collection> </Annotation>"; IEdmModel model = GetEdmModel(annotation, annotation); var httpRequestProvider = new HttpRequestProvider(model); IEdmNavigationSource navigationSource = model.FindDeclaredNavigationSource(name); Assert.NotNull(navigationSource); // Act var requests = httpRequestProvider.GetHttpRequests(navigationSource as IEdmVocabularyAnnotatable); // Assert Assert.NotEmpty(requests); Assert.Equal(3, requests.Count()); // Act var anotherRequests = httpRequestProvider.GetHttpRequests(navigationSource as IEdmVocabularyAnnotatable); // Assert Assert.True(ReferenceEquals(requests, anotherRequests)); // Act (PATCH) var request = httpRequestProvider.GetHttpRequest(navigationSource as IEdmVocabularyAnnotatable, "PATCH"); // Assert Assert.NotNull(request); Assert.Equal("PATCH Example", request.MethodDescription); Assert.NotNull(request.SecuritySchemes); var securityScheme = Assert.Single(request.SecuritySchemes); Assert.Equal("Delegated (work or school account)", securityScheme.AuthorizationSchemeName); Assert.NotNull(securityScheme.RequiredScopes); Assert.Equal(new[] { "Directory.ReadWrite.All", "Directory.AccessAsUser.All" }, securityScheme.RequiredScopes); }