forked from microsoft/kiota
-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
1,795 additions
and
15 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
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
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
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
88 changes: 88 additions & 0 deletions
88
tests/Kiota.Builder.Tests/Writers/Dart/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,88 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
using Kiota.Builder.CodeDOM; | ||
using Kiota.Builder.Extensions; | ||
using Kiota.Builder.Writers; | ||
|
||
using Xunit; | ||
|
||
namespace Kiota.Builder.Tests.Writers.Dart; | ||
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"; | ||
public CodeEnumWriterTests() | ||
{ | ||
writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.Dart, DefaultPath, DefaultName); | ||
tw = new StringWriter(); | ||
writer.SetTextWriter(tw); | ||
var root = CodeNamespace.InitRootNamespace(); | ||
currentEnum = root.AddEnum(new CodeEnum | ||
{ | ||
Name = EnumName, | ||
}).First(); | ||
} | ||
public void Dispose() | ||
{ | ||
tw?.Dispose(); | ||
GC.SuppressFinalize(this); | ||
} | ||
[Fact] | ||
public void WritesEnum() | ||
{ | ||
const string optionName = "option1"; | ||
currentEnum.AddOption(new CodeEnumOption { Name = optionName, SerializationName = optionName }); | ||
writer.Write(currentEnum); | ||
var result = tw.ToString(); | ||
Assert.Contains("enum", result); | ||
Assert.Contains(EnumName, result); | ||
Assert.Contains($"{optionName}(\"{optionName}\")", result); | ||
Assert.Contains($"const {EnumName}(this.value);", result); | ||
Assert.Contains("final String value;", result); | ||
} | ||
[Fact] | ||
public void DoesntWriteAnythingOnNoOption() | ||
{ | ||
writer.Write(currentEnum); | ||
var result = tw.ToString(); | ||
Assert.Empty(result); | ||
} | ||
[Fact] | ||
public void WritesEnumOptionDescription() | ||
{ | ||
var option = new CodeEnumOption | ||
{ | ||
Documentation = new() | ||
{ | ||
DescriptionTemplate = "Some option description", | ||
}, | ||
Name = "option1", | ||
}; | ||
currentEnum.AddOption(option); | ||
writer.Write(currentEnum); | ||
var result = tw.ToString(); | ||
Console.WriteLine(result); | ||
Assert.Contains($"/// {option.Documentation.DescriptionTemplate}", result); | ||
} | ||
[Fact] | ||
public void WritesEnumSerializationValue() | ||
{ | ||
var OptionName = "plus1"; | ||
var SerializationValue = "+1"; | ||
var option = new CodeEnumOption | ||
{ | ||
Name = OptionName, | ||
SerializationName = SerializationValue | ||
}; | ||
currentEnum.AddOption(option); | ||
writer.Write(currentEnum); | ||
var result = tw.ToString(); | ||
Assert.Contains($"{OptionName}(\"{SerializationValue}\")", result); | ||
} | ||
} |
Oops, something went wrong.