示例#1
0
        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=""{&#xD;&#xA;  &quot;accountEnabled&quot;:false,&#xD;&#xA;  &quot;deviceId&quot;:&quot;4c299165-6e8f-4b45-a5ba-c5d250a707ff&quot;,&#xD;&#xA;  &quot;displayName&quot;:&quot;Test device&quot;,&#xD;&#xA;  &quot;id&quot;: &quot;id-value&quot;,&#xD;&#xA;  &quot;operatingSystem&quot;:&quot;linux&quot;,&#xD;&#xA;  &quot;operatingSystemVersion&quot;:&quot;1&quot;&#xD;&#xA;}&#xA;"" />
                          <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);
        }
示例#2
0
 /// <summary>
 /// Find the Org.OData.Core.V1.HttpRequest for a given target.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="method">The method name.</param>
 /// <returns>The <see cref="HttpRequest"/> or null.</returns>
 public HttpRequest FindRequest(IEdmVocabularyAnnotatable target, string method)
 {
     return(_httpRequestProvider?.GetHttpRequest(target, method));
 }