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); }
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);
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); }
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()); }
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.HasBody() ? RequestBodyVarName : default,
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); }
public async Task ParsesBodyTypeBinary() { using var request = new HttpRequestMessage(HttpMethod.Put, $"{ServiceRootUrl}/applications/{{application-id}}/logo") { Content = new ByteArrayContent(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 }) }; request.Content.Headers.ContentType = new("application/octet-stream"); var snippetModel = new SnippetModel(request, ServiceRootUrl, await GetV1TreeNode()); var result = new SnippetCodeGraph(snippetModel); Assert.Equal(PropertyType.Binary, result.Body.PropertyType); }
public async Task ParsesBodyPropertyTypeMap() { using var request = new HttpRequestMessage(HttpMethod.Post, $"{ServiceRootUrl}/me/findMeetingTimes") { Content = new StringContent(TypesSample, Encoding.UTF8) }; var snippetModel = new SnippetModel(request, ServiceRootUrl, await GetV1TreeNode()); var snippetCodeGraph = new SnippetCodeGraph(snippetModel); var property = FindPropertyInSnippet(snippetCodeGraph.Body, "additionalData").Value; Assert.Equal(PropertyType.Map, property.PropertyType); }
public async Task ParsesBodyPropertyTypeNumber() { using var request = new HttpRequestMessage(HttpMethod.Post, $"{ServiceRootUrl}/me/findMeetingTimes") { Content = new StringContent(TypesSample, Encoding.UTF8) }; var snippetModel = new SnippetModel(request, ServiceRootUrl, await GetV1TreeNode()); var snippetCodeGraph = new SnippetCodeGraph(snippetModel); var property = FindPropertyInSnippet(snippetCodeGraph.Body, "minimumAttendeePercentage").Value; Assert.Equal(PropertyType.Int32, property.PropertyType); Assert.Equal("100", property.Value); }
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')` }
public async Task ParsesInt64Property() { const string userJsonObject = "{\r\n \"chainId\": 10\r\n\r\n}"; using var requestPayload = new HttpRequestMessage(HttpMethod.Post, $"{ServiceRootUrl}/teams/{{teamId}}/sendActivityNotification") { Content = new StringContent(userJsonObject, Encoding.UTF8, "application/json") }; var snippetCodeGraph = new SnippetCodeGraph(requestPayload, ServiceRootUrl, await GetV1TreeNode()); var property = FindPropertyInSnippet(snippetCodeGraph.Body, "chainId").Value; Assert.Equal(PropertyType.Int64, property.PropertyType); Assert.Equal("10", property.Value); }
public async Task ParsesGuidProperty() { const string userJsonObject = "{\r\n \"keyId\": \"f0b0b335-1d71-4883-8f98-567911bfdca6\"\r\n\r\n}"; using var requestPayload = new HttpRequestMessage(HttpMethod.Post, $"{ServiceRootUrl}/applications/{{id}}/removeKey") { Content = new StringContent(userJsonObject, Encoding.UTF8, "application/json") }; var snippetCodeGraph = new SnippetCodeGraph(requestPayload, ServiceRootUrl, await GetV1TreeNode()); var property = FindPropertyInSnippet(snippetCodeGraph.Body, "keyId").Value; Assert.Equal(PropertyType.Guid, property.PropertyType); Assert.Equal("f0b0b335-1d71-4883-8f98-567911bfdca6", property.Value); }
public async Task ParsesDoubleProperty() { const string userJsonObject = "{\r\n \"minimumAttendeePercentage\": 10\r\n\r\n}"; using var requestPayload = new HttpRequestMessage(HttpMethod.Post, $"{ServiceRootUrl}/me/findMeetingTimes") { Content = new StringContent(userJsonObject, Encoding.UTF8, "application/json") }; var snippetCodeGraph = new SnippetCodeGraph(requestPayload, ServiceRootUrl, await GetV1TreeNode()); var property = FindPropertyInSnippet(snippetCodeGraph.Body, "minimumAttendeePercentage").Value; Assert.Equal(PropertyType.Double, property.PropertyType); Assert.Equal("10", property.Value); }
public string GenerateCodeSnippet(SnippetModel snippetModel) { if (snippetModel == null) { throw new ArgumentNullException("Argument snippetModel cannot be null"); } var codeGraph = new SnippetCodeGraph(snippetModel); var snippetBuilder = new StringBuilder( "//THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY" + Environment.NewLine + $"const {ClientVarName} = {ClientVarType}.init({{authProvider}});{Environment.NewLine}{Environment.NewLine}"); writeSnippet(codeGraph, snippetBuilder); return(snippetBuilder.ToString()); }
public string GenerateCodeSnippet(SnippetModel snippetModel) { if (snippetModel == null) { throw new ArgumentNullException("Argument snippetModel cannot be null"); } var codeGraph = new SnippetCodeGraph(snippetModel); var snippetBuilder = new StringBuilder( "//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY" + Environment.NewLine + $"{clientVarName} := msgraphsdk.New{clientVarType}({httpCoreVarName}){Environment.NewLine}{Environment.NewLine}"); writeSnippet(codeGraph, snippetBuilder); return(snippetBuilder.ToString()); }
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 string GenerateCodeSnippet(SnippetModel snippetModel) { var indentManager = new IndentManager(); var codeGraph = new SnippetCodeGraph(snippetModel); var payloadSb = new StringBuilder( "<?php" + Environment.NewLine + Environment.NewLine + "// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY" + Environment.NewLine + $"{ClientVarName} = new {ClientVarType}({HttpCoreVarName});{Environment.NewLine}{Environment.NewLine}"); if (codeGraph.HasBody()) { WriteObjectProperty(RequestBodyVarName, payloadSb, codeGraph.Body, indentManager); } WriteRequestExecutionPath(codeGraph, payloadSb, indentManager); return(payloadSb.ToString()); }
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); }
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); }
public async Task ParsesBodyWithoutProperContentType() { var sampleBody = @" { ""createdDateTime"": ""2019-02-04T19:58:15.511Z"" } "; using var request = new HttpRequestMessage(HttpMethod.Post, $"{ServiceRootUrl}/teams/team-id/channels/19:[email protected]/messages") { Content = new StringContent(sampleBody, Encoding.UTF8) // snippet missing content type }; var snippetModel = new SnippetModel(request, ServiceRootUrl, await GetV1TreeNode()); var result = new SnippetCodeGraph(snippetModel); var expectedObject = new CodeProperty { Name = "MessagesPostRequestBody", Value = null, PropertyType = PropertyType.Object, Children = new List <CodeProperty>() }; Assert.Equal(expectedObject.Name, result.Body.Name); Assert.Equal(expectedObject.Value, result.Body.Value); Assert.Equal(expectedObject.PropertyType, result.Body.PropertyType); }