Skip to content

Commit

Permalink
Added tests to enforce header behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
samarthasthana committed Aug 1, 2023
1 parent e3a6703 commit 1795579
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Kiota.Builder.Tests.Writers.CSharp;
public class CodeClassDeclarationWriterTests : IDisposable
{
private const string AutoGenerationHeader = "// <auto-generated/>";
private const string DefaultPath = "./";
private const string DefaultName = "name";
private readonly StringWriter tw;
Expand All @@ -30,18 +31,29 @@ public CodeClassDeclarationWriterTests()
};
root.AddClass(parentClass);
}

public void Dispose()
{
tw?.Dispose();
GC.SuppressFinalize(this);
}

[Fact]
public void WritesAutoGeneratedHeader()
{
codeElementWriter.WriteCodeElement(parentClass.StartBlock, writer);
var result = tw.ToString();
Assert.Contains(AutoGenerationHeader, result);
}

[Fact]
public void WritesSimpleDeclaration()
{
codeElementWriter.WriteCodeElement(parentClass.StartBlock, writer);
var result = tw.ToString();
Assert.Contains("public class", result);
}

[Fact]
public void WritesImplementation()
{
Expand All @@ -54,6 +66,7 @@ public void WritesImplementation()
var result = tw.ToString();
Assert.Contains(":", result);
}

[Fact]
public void WritesInheritance()
{
Expand All @@ -66,6 +79,7 @@ public void WritesInheritance()
var result = tw.ToString();
Assert.Contains(":", result);
}

[Fact]
public void WritesImports()
{
Expand Down
11 changes: 11 additions & 0 deletions tests/Kiota.Builder.Tests/Writers/CSharp/CodeEnumWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Kiota.Builder.Tests.Writers.CSharp;
public class CodeEnumWriterTests : IDisposable
{
private const string AutoGenerationHeader = "// <auto-generated/>";
private const string DefaultPath = "./";
private const string DefaultName = "name";
private readonly StringWriter tw;
Expand All @@ -37,6 +38,7 @@ public void Dispose()
tw?.Dispose();
GC.SuppressFinalize(this);
}

[Fact]
public void WritesEnum()
{
Expand All @@ -48,6 +50,15 @@ public void WritesEnum()
Assert.Contains(Option.Name, result);
}

[Fact]
public void WritesAutoGeneratedHeader()
{
currentEnum.AddOption(Option);
writer.Write(currentEnum);
var result = tw.ToString();
Assert.Contains(AutoGenerationHeader, result);
}

[Fact]
public void NamesDiffer_WritesEnumMember()
{
Expand Down

0 comments on commit 1795579

Please sign in to comment.