Exemple #1
0
        public async Task ParsesQueryParametersWithSpaces()
        {
            using var request = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/roleManagement/directory/roleAssignments?$filter=roleDefinitionId eq '62e90394-69f5-4237-9190-012177145e10'&$expand=principal");

            var snippetModel = new SnippetModel(request, ServiceRootUrl, await GetV1TreeNode());
            var result       = new SnippetCodeGraph(snippetModel);

            Assert.True(result.HasParameters());
            Assert.Equal(2, result.Parameters.Count());

            var expectedProperty1 = new CodeProperty {
                Name = "filter", Value = "roleDefinitionId eq '62e90394-69f5-4237-9190-012177145e10'", PropertyType = PropertyType.String
            };
            var actualParam1 = result.Parameters.First();

            Assert.Equal(expectedProperty1, actualParam1);

            var expectedProperty2 = new CodeProperty {
                Value = "principal", PropertyType = PropertyType.String
            };
            var actualParam2 = result.Parameters.Skip(1).First();

            Assert.Equal("expand", actualParam2.Name);
            Assert.Equal(expectedProperty2, actualParam2.Children[0]);
        }
    private static string GetRequestQueryParameters(SnippetCodeGraph model, IndentManager indentManager)
    {
        var payloadSb = new StringBuilder();

        if (!model.HasParameters())
        {
            return(default);
Exemple #3
0
        public async Task ParsesParameters()
        {
            using var request = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/users/19:4b6bed8d24574f6a9e436813cb2617d8?$select=displayName,givenName,postalCode,identities");

            var snippetModel = new SnippetModel(request, ServiceRootUrl, await GetV1TreeNode());
            var result       = new SnippetCodeGraph(snippetModel);
            var parameter    = result.Parameters.First();

            Assert.True(result.HasParameters());
            Assert.Single(result.Parameters);

            // creates an array of nested properties
            var children = new List <CodeProperty>();

            children.Add(new CodeProperty {
                Value = "displayName", PropertyType = PropertyType.String
            });
            children.Add(new CodeProperty {
                Value = "givenName", PropertyType = PropertyType.String
            });
            children.Add(new CodeProperty {
                Value = "postalCode", PropertyType = PropertyType.String
            });
            children.Add(new CodeProperty {
                Value = "identities", PropertyType = PropertyType.String
            });

            Assert.Equal(children[0], parameter.Children[0]);
            Assert.Equal(children[1], parameter.Children[1]);
            Assert.Equal(children[2], parameter.Children[2]);
            Assert.Equal(children[3], parameter.Children[3]);

            Assert.Equal("select", parameter.Name);
            Assert.Equal(PropertyType.Array, parameter.PropertyType);
        }
Exemple #4
0
        public async Task ArrayParametersSplitOnExternalCommas()
        {
            using var requestPayload = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/groups?$expand=members($select=id,displayName),teams($select=id,displayName)");
            var result = new SnippetCodeGraph(requestPayload, ServiceRootUrl, await GetV1TreeNode());

            Assert.True(result.HasParameters());
            Assert.Single(result.Parameters);

            var param = result.Parameters.First();

            Assert.Equal("expand", param.Name);
            Assert.Equal(PropertyType.Array, param.PropertyType);
            Assert.Equal(2, param.Children.Count);

            var expectedProperty1 = new CodeProperty {
                Value = "members($select=id,displayName)", PropertyType = PropertyType.String
            };

            Assert.Equal(param.Children.First(), expectedProperty1);

            var expectedProperty2 = new CodeProperty {
                Value = "teams($select=id,displayName)", PropertyType = PropertyType.String
            };

            Assert.Equal(param.Children.Skip(1).First(), expectedProperty2);
        }
Exemple #5
0
        public async Task HasParametersIsFalseWhenNoParameterExists()
        {
            using var request = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/users/19:4b6bed8d24574f6a9e436813cb2617d8");

            var snippetModel = new SnippetModel(request, ServiceRootUrl, await GetV1TreeNode());
            var result       = new SnippetCodeGraph(snippetModel);

            Assert.False(result.HasParameters());
        }
        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,
Exemple #7
0
        public async Task SkipParametersAreIntegers()
        {
            using var requestPayload = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/users?$skip=10");
            var result = new SnippetCodeGraph(requestPayload, ServiceRootUrl, await GetV1TreeNode());

            Assert.True(result.HasParameters());
            var param = result.Parameters.First();

            Assert.Equal("skip", param.Name);
            Assert.Equal("10", param.Value);
        }
Exemple #8
0
        public async Task ParsesParametersWithExpressionsCorrectly()
        {
            using var request = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/groups?$filter=groupTypes/any(c:c+eq+'Unified')");
            request.Headers.Add("Host", "graph.microsoft.com");

            var snippetModel = new SnippetModel(request, ServiceRootUrl, await GetV1TreeNode());
            var result       = new SnippetCodeGraph(snippetModel);

            Assert.True(result.HasParameters());
            var param = result.Parameters.First();

            Assert.Equal("filter", param.Name);
            Assert.Equal("groupTypes/any", param.Value); // TODO check if result should be `groupTypes/any(c:c+eq+'Unified')`
        }
    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});");
    }
Exemple #10
0
        public async Task CountParameterIsBoolean()
        {
            using var requestPayload = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/users?$count=true&$select=displayName,id");
            var result = new SnippetCodeGraph(requestPayload, ServiceRootUrl, await GetV1TreeNode());

            Assert.True(result.HasParameters());
            var paramCount = result.Parameters.Count();

            Assert.Equal(2, paramCount);

            var param = result.Parameters.First();

            Assert.Equal("count", param.Name);
            Assert.Equal(PropertyType.Boolean, param.PropertyType);
            Assert.Equal("true", param.Value);
        }