public async Task HasHeadersIsFalseWhenNoneIsInRequest() { using var request = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/users"); request.Headers.Add("Host", "graph.microsoft.com"); var snippetModel = new SnippetModel(request, ServiceRootUrl, await GetV1TreeNode()); var result = new SnippetCodeGraph(snippetModel); Assert.False(result.HasHeaders()); }
private static void writeSnippet(SnippetCodeGraph codeGraph, StringBuilder builder) { writeHeadersAndOptions(codeGraph, builder); WriteBody(codeGraph, builder); builder.AppendLine(""); WriteExecutionStatement( codeGraph, builder, codeGraph.HasHeaders() || codeGraph.HasOptions() || codeGraph.HasParameters(), codeGraph.HasBody() ? requestBodyVarName : default,
private static void WriteRequestExecutionPath(SnippetCodeGraph codeGraph, StringBuilder payloadSb, IndentManager indentManager) { var method = codeGraph.HttpMethod.Method.ToLower(); var configParameter = codeGraph.HasHeaders() || codeGraph.HasParameters() ? $"{RequestConfigurationVarName}" : string.Empty; var bodyParameter = codeGraph.HasBody() ? $"{RequestBodyVarName}" : string.Empty; var optionsParameter = codeGraph.HasOptions() ? "options" : string.Empty; var returnVar = codeGraph.HasReturnedBody() ? "$requestResult = " : string.Empty; var parameterList = GetActionParametersList(bodyParameter, configParameter, optionsParameter); payloadSb.AppendLine(GetRequestConfiguration(codeGraph, indentManager)); payloadSb.AppendLine($"{returnVar}{ClientVarName}->{GetFluentApiPath(codeGraph.Nodes)}->{method}({parameterList});"); }
public async Task ParsesHeaders() { using var request = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/users"); request.Headers.Add("Host", "graph.microsoft.com"); request.Headers.Add("Prefer", "outlook.timezone=\"Pacific Standard Time\""); var snippetModel = new SnippetModel(request, ServiceRootUrl, await GetV1TreeNode()); var result = new SnippetCodeGraph(snippetModel); var header = result.Headers.First(); Assert.True(result.HasHeaders()); Assert.Single(result.Headers); // host should be ignored in headers Assert.Equal("outlook.timezone=\"Pacific Standard Time\"", header.Value); Assert.Equal("Prefer", header.Name); Assert.Equal(PropertyType.String, header.PropertyType); }