public void ExecuteAsync_KnownEndpointWithRequestMethods_NoWarning() { ChangeDirectoryCommand command = new ChangeDirectoryCommand(); Setup(commandText: "cd AnEndpoint", out MockedShellState mockedShellState, out HttpState httpState, out ICoreParseResult parseResult); DirectoryStructure directoryStructure = new DirectoryStructure(null); DirectoryStructure childDirectory = directoryStructure.DeclareDirectory("AnEndpoint"); RequestInfo childRequestInfo = new RequestInfo(); childRequestInfo.AddMethod("GET"); childDirectory.RequestInfo = childRequestInfo; ApiDefinition apiDefinition = new ApiDefinition() { DirectoryStructure = directoryStructure }; httpState.ApiDefinition = apiDefinition; string expectedOutput = "/AnEndpoint [GET]"; command.ExecuteAsync(mockedShellState, httpState, parseResult, CancellationToken.None); Assert.Single(mockedShellState.Output); Assert.Equal(expectedOutput, mockedShellState.Output[0]); }
public static void FillDirectoryInfo(DirectoryStructure parent, EndpointMetadata entry) { entry = entry ?? throw new ArgumentNullException(nameof(entry)); parent = parent ?? throw new ArgumentNullException(nameof(parent)); string[] parts = entry.Path.Split('/'); foreach (string part in parts) { if (!string.IsNullOrEmpty(part) && parent is object) { parent = parent.DeclareDirectory(part); } } RequestInfo dirRequestInfo = new RequestInfo(); foreach (KeyValuePair <string, IReadOnlyDictionary <string, IReadOnlyList <Parameter> > > requestInfo in entry.AvailableRequests) { string method = requestInfo.Key; foreach (KeyValuePair <string, IReadOnlyList <Parameter> > parameterSetsByContentType in requestInfo.Value) { if (string.IsNullOrEmpty(parameterSetsByContentType.Key)) { dirRequestInfo.SetFallbackRequestBody(method, parameterSetsByContentType.Key, SchemaDataGenerator.GetBodyString(parameterSetsByContentType.Value)); } dirRequestInfo.SetRequestBody(method, parameterSetsByContentType.Key, SchemaDataGenerator.GetBodyString(parameterSetsByContentType.Value)); } dirRequestInfo.AddMethod(method); } if (dirRequestInfo.Methods.Count > 0 && parent is object) { parent.RequestInfo = dirRequestInfo; } }
public static void FillDirectoryInfo(DirectoryStructure parent, EndpointMetadata entry) { entry = entry ?? throw new ArgumentNullException(nameof(entry)); parent = parent ?? throw new ArgumentNullException(nameof(parent)); string[] parts = entry.Path.Split('/'); foreach (string part in parts) { if (!string.IsNullOrEmpty(part) && parent is object) { parent = parent.DeclareDirectory(part); } } RequestInfo dirRequestInfo = new RequestInfo(); foreach (RequestMetadata requestMetadata in entry.AvailableRequests) { string method = requestMetadata.Operation.ToString(); foreach (RequestContentMetadata content in requestMetadata.Content) { if (string.IsNullOrWhiteSpace(content.ContentType)) { dirRequestInfo.SetFallbackRequestBody(method, content.ContentType, SchemaDataGenerator.GetBodyString(content.BodySchema)); } dirRequestInfo.SetRequestBody(method, content.ContentType, SchemaDataGenerator.GetBodyString(content.BodySchema)); } dirRequestInfo.AddMethod(requestMetadata.Operation.ToString()); } if (dirRequestInfo.Methods.Count > 0 && parent is object) { parent.RequestInfo = dirRequestInfo; } }
private static void FillDirectoryInfo(DirectoryStructure parent, EndpointMetadata entry) { string[] parts = entry.Path.Split('/'); foreach (string part in parts) { if (!string.IsNullOrEmpty(part)) { parent = parent.DeclareDirectory(part); } } RequestInfo dirRequestInfo = new RequestInfo(); foreach (KeyValuePair <string, IReadOnlyDictionary <string, IReadOnlyList <Parameter> > > requestInfo in entry.AvailableRequests) { string method = requestInfo.Key; foreach (KeyValuePair <string, IReadOnlyList <Parameter> > parameterSetsByContentType in requestInfo.Value) { if (string.IsNullOrEmpty(parameterSetsByContentType.Key)) { dirRequestInfo.SetFallbackRequestBody(method, GetBodyString(null, parameterSetsByContentType.Value)); } dirRequestInfo.SetRequestBody(method, parameterSetsByContentType.Key, GetBodyString(parameterSetsByContentType.Key, parameterSetsByContentType.Value)); } dirRequestInfo.AddMethod(method); } if (dirRequestInfo.Methods.Count > 0) { parent.RequestInfo = dirRequestInfo; } }