Skip to content

Commit

Permalink
Add tests for primary error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasKenneth committed Oct 8, 2023
1 parent b46e64e commit 9517563
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,31 @@ public async void WriteRequestExecutor()
Assert.Contains("return $this->requestAdapter->sendPrimitiveAsync($requestInfo, StreamInterface::class, $errorMappings);", result);
}

[Fact]
public async Task WriteErrorMessageOverride()
{
setup();
var error401 = root.AddClass(new CodeClass
{
Name = "Error401",
IsErrorDefinition = true
}).First();
error401.AddProperty(new CodeProperty { Type = new CodeType { Name = "string" }, Name = "code", Kind = CodePropertyKind.Custom });
error401.AddProperty(new CodeProperty { Type = new CodeType { Name = "string" }, Name = "message", IsPrimaryErrorMessage = true, Kind = CodePropertyKind.Custom });

var codeMethod = new CodeMethod
{
Kind = CodeMethodKind.ErrorMessageOverride,
ReturnType = new CodeType { Name = "string" },
SimpleName = "getPrimaryErrorMessage",
};
error401.AddMethod(codeMethod);
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.PHP }, root);
_codeMethodWriter.WriteCodeElement(codeMethod, languageWriter);
var result = stringWriter.ToString();

Assert.Contains("return $primaryError->getMessage() ?? '';", result);
}
[Fact]
public async void WritesRequestExecutorForEnumTypes()
{
Expand Down

0 comments on commit 9517563

Please sign in to comment.