コード例 #1
0
        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());
        }
コード例 #2
0
        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,
コード例 #3
0
    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});");
    }
コード例 #4
0
        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);
        }