Skip to content

Commit

Permalink
Merge branch 'shem/php_snipet_imports' of github.com:microsoftgraph/m…
Browse files Browse the repository at this point in the history
…icrosoft-graph-devx-api into shem/php_snipet_imports
  • Loading branch information
shemogumbe committed Mar 20, 2024
2 parents 39737b6 + ecbe529 commit 2c91c7a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
63 changes: 63 additions & 0 deletions CodeSnippetsReflection.OpenAPI.Test/PhpGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,69 @@ public async Task GenerateForComplexMapValues()
Assert.Contains("'@odata.type' => '#microsoft.graph.identity',", result);
Assert.Contains("'id' => '+12345678901',", result);
}

[Fact]
public async Task GeneratesRequestBuilderImports()
{
using var requestPayload = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/me/calendar/events?$filter=startsWith(subject,'All')");
var snippetModel = new SnippetModel(requestPayload, ServiceRootUrl, await GetV1SnippetMetadata());
var result = _generator.GenerateCodeSnippet(snippetModel);
Assert.Contains("use Microsoft\\Graph\\Graph;", result);
Assert.Contains("use Microsoft\\Graph\\Generated\\Users\\Item\\Calendar\\Events", result);
}


[Fact]
public async Task GenerateModelImports(){
var bodyContent = @"{
""displayName"": ""New display name""
}";
using var requestPayload = new HttpRequestMessage(HttpMethod.Patch, $"{ServiceRootUrl}/applications/{{id}}")
{
Content = new StringContent(bodyContent, Encoding.UTF8, "application/json")
};
var snippetModel = new SnippetModel(requestPayload, ServiceRootUrl, await GetV1SnippetMetadata());
var result = _generator.GenerateCodeSnippet(snippetModel);
Assert.Contains("use Microsoft\\Graph\\Graph;", result);
Assert.Contains("use Microsoft\\Graph\\Generated\\Models;", result);

}

[Fact]
public async Task GenerateComplexModelImports(){
var bodyContent = @"{
""subject"": ""Annual review"",
""body"": {
""contentType"": ""HTML"",
""content"": ""You should be proud!""
},
""toRecipients"": [
{
""emailAddress"": {
""address"": ""[email protected]""
}
}
],
""extensions"": [
{
""@odata.type"": ""microsoft.graph.openTypeExtension"",
""extensionName"": ""Com.Contoso.Referral"",
""companyName"": ""Wingtip Toys"",
""expirationDate"": ""2015-12-30T11:00:00.000Z"",
""dealValue"": 10000
}
]
}";
using var requestPayload = new HttpRequestMessage(HttpMethod.Post, $"{ServiceRootUrl}/me/messages/")
{
Content = new StringContent(bodyContent, Encoding.UTF8, "application/json")
};
var snippetModel = new SnippetModel(requestPayload, ServiceRootUrl, await GetV1SnippetMetadata());
var result = _generator.GenerateCodeSnippet(snippetModel);
Assert.Contains("use Microsoft\\Graph\\Graph;", result);
Assert.Contains("use Microsoft\\Graph\\Generated\\Models;", result);

}

[Fact]
public async Task GenerateForMoreComplexMapping()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using CodeSnippetsReflection.StringExtensions;
using Microsoft.OpenApi.Services;


namespace CodeSnippetsReflection.OpenAPI.LanguageGenerators
{
public enum ImportKind
Expand Down

0 comments on commit 2c91c7a

Please sign in to comment.