public void GetApplicableContentTypes_WithPath_ReturnsCorrectOne() { DirectoryStructure parentDirectoryStructure = new DirectoryStructure(null); RequestInfo parentRequestInfo = new RequestInfo(); parentRequestInfo.SetRequestBody("GET", "application/json", ""); parentDirectoryStructure.RequestInfo = parentRequestInfo; DirectoryStructure childDirectoryStructure = parentDirectoryStructure.DeclareDirectory("child"); RequestInfo childRequestInfo = new RequestInfo(); childRequestInfo.SetRequestBody("GET", "application/xml", ""); childDirectoryStructure.RequestInfo = childRequestInfo; HttpState httpState = SetupHttpState(); httpState.BaseAddress = new Uri("https://localhost/"); ApiDefinition apiDefinition = new ApiDefinition(); apiDefinition.DirectoryStructure = parentDirectoryStructure; httpState.ApiDefinition = apiDefinition; IEnumerable <string> result = httpState.GetApplicableContentTypes("GET", "child"); Assert.Single(result); Assert.Contains("application/xml", result, StringComparer.OrdinalIgnoreCase); }
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]); }
private static HttpState SetupHttpState() { IFileSystem fileSystem = new FileSystemStub(); IUserProfileDirectoryProvider userProfileDirectoryProvider = new UserProfileDirectoryProvider(); IPreferences preferences = new UserFolderPreferences(fileSystem, userProfileDirectoryProvider, null); HttpClient httpClient = new HttpClient(); HttpState httpState = new HttpState(fileSystem, preferences, httpClient); DirectoryStructure structure = new DirectoryStructure(null); DirectoryStructure child1 = structure.DeclareDirectory("child1"); structure.DeclareDirectory("child2"); child1.DeclareDirectory("grandchild1"); child1.DeclareDirectory("grandchild2"); httpState.Structure = structure; return(httpState); }
private static void FillDirectoryInfo(DirectoryStructure parent, string endpoint) { string[] parts = endpoint.Split('/'); foreach (string part in parts) { if (!string.IsNullOrEmpty(part)) { parent = parent.DeclareDirectory(part); } } }
private IDirectoryStructure GetDirectoryStructure(string method, string contentType, string body) { RequestInfo requestInfo = new RequestInfo(); requestInfo.SetRequestBody(method, contentType, body); DirectoryStructure directoryStructure = new DirectoryStructure(null); DirectoryStructure childDirectoryStructure = directoryStructure.DeclareDirectory(contentType); childDirectoryStructure.RequestInfo = requestInfo; return(childDirectoryStructure); }
public void ExecuteAsync_KnownEndpointWithSubdirectory_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"); DirectoryStructure grandchildDirectory = childDirectory.DeclareDirectory("AnotherEndpoint"); httpState.Structure = directoryStructure; string expectedOutput = "/AnEndpoint []"; 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 (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; } }
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; } }
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; } }