-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
tests/Kiota.Builder.Tests/Writers/HTTP/CodeEnumWriterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
using Kiota.Builder.CodeDOM; | ||
using Kiota.Builder.Extensions; | ||
using Kiota.Builder.Writers; | ||
using Kiota.Builder.Writers.http; | ||
using Xunit; | ||
|
||
namespace Kiota.Builder.Tests.Writers.Http; | ||
public sealed class CodeEnumWriterTests : IDisposable | ||
{ | ||
private const string DefaultPath = "./"; | ||
private const string DefaultName = "name"; | ||
private readonly StringWriter tw; | ||
private readonly LanguageWriter writer; | ||
private readonly CodeEnum currentEnum; | ||
private const string EnumName = "someEnum"; | ||
private readonly CodeEnumWriter codeEnumWriter; | ||
public CodeEnumWriterTests() | ||
{ | ||
writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.HTTP, DefaultPath, DefaultName); | ||
codeEnumWriter = new CodeEnumWriter(new HttpConventionService("foo")); | ||
tw = new StringWriter(); | ||
writer.SetTextWriter(tw); | ||
var root = CodeNamespace.InitRootNamespace(); | ||
currentEnum = root.AddEnum(new CodeEnum | ||
{ | ||
Name = EnumName, | ||
}).First(); | ||
if (CodeConstant.FromCodeEnum(currentEnum) is CodeConstant constant) | ||
{ | ||
currentEnum.CodeEnumObject = constant; | ||
root.AddConstant(constant); | ||
} | ||
} | ||
public void Dispose() | ||
{ | ||
tw?.Dispose(); | ||
GC.SuppressFinalize(this); | ||
} | ||
[Fact] | ||
public void WriteCodeElement_ThrowsException_WhenCodeElementIsNull() | ||
{ | ||
Assert.Throws<ArgumentNullException>(() => codeEnumWriter.WriteCodeElement(null, writer)); | ||
} | ||
[Fact] | ||
public void WriteCodeElement_ThrowsException_WhenWriterIsNull() | ||
{ | ||
var codeElement = new CodeEnum(); | ||
Assert.Throws<ArgumentNullException>(() => codeEnumWriter.WriteCodeElement(codeElement, null)); | ||
} | ||
[Fact] | ||
public void SkipsEnum() | ||
{ | ||
const string optionName = "option1"; | ||
currentEnum.AddOption(new CodeEnumOption { Name = optionName }); | ||
codeEnumWriter.WriteCodeElement(currentEnum, writer); | ||
var result = tw.ToString(); | ||
Assert.True(string.IsNullOrEmpty(result)); | ||
} | ||
} |