-
Notifications
You must be signed in to change notification settings - Fork 214
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
6 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/Kiota.Builder/Writers/TypeScript/CodeFileBlockEndWriter.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,17 @@ | ||
using System; | ||
using Kiota.Builder.CodeDOM; | ||
namespace Kiota.Builder.Writers.TypeScript; | ||
|
||
public class CodeFileBlockEndWriter : BaseElementWriter<CodeFileBlockEnd, TypeScriptConventionService> | ||
{ | ||
public CodeFileBlockEndWriter(TypeScriptConventionService conventionService) : base(conventionService) | ||
{ | ||
} | ||
|
||
public override void WriteCodeElement(CodeFileBlockEnd codeElement, LanguageWriter writer) | ||
{ | ||
ArgumentNullException.ThrowIfNull(codeElement); | ||
ArgumentNullException.ThrowIfNull(writer); | ||
conventions.WriteAutoGeneratedEnd(writer); | ||
} | ||
} |
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
70 changes: 70 additions & 0 deletions
70
tests/Kiota.Builder.Tests/Writers/TypeScript/CodeFileWriterTests.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,70 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Kiota.Builder.CodeDOM; | ||
using Kiota.Builder.Configuration; | ||
using Kiota.Builder.Extensions; | ||
using Kiota.Builder.Refiners; | ||
using Kiota.Builder.Writers; | ||
using Xunit; | ||
|
||
namespace Kiota.Builder.Tests.Writers.TypeScript; | ||
|
||
public class CodeFileWriterTests | ||
{ | ||
private const string DefaultPath = "./"; | ||
private const string DefaultName = "name"; | ||
private readonly StringWriter tw; | ||
private readonly LanguageWriter writer; | ||
private readonly CodeNamespace root; | ||
private const string MethodName = "methodName"; | ||
private const string ReturnTypeName = "Somecustomtype"; | ||
|
||
public CodeFileWriterTests() | ||
{ | ||
writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.TypeScript, DefaultPath, DefaultName); | ||
tw = new StringWriter(); | ||
writer.SetTextWriter(tw); | ||
root = CodeNamespace.InitRootNamespace(); | ||
} | ||
|
||
[Fact] | ||
public void Dispose() | ||
{ | ||
tw?.Dispose(); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
private void WriteCode(LanguageWriter writer, CodeElement element) | ||
{ | ||
writer.Write(element); | ||
if (element is not CodeNamespace) | ||
foreach (var childElement in element.GetChildElements() | ||
.Order(new CodeElementOrderComparer())) | ||
{ | ||
WriteCode(writer, childElement); | ||
} | ||
|
||
} | ||
|
||
[Fact] | ||
public async Task WritesAutoGenerationStart() | ||
{ | ||
var parentClass = TestHelper.CreateModelClass(root, "parentClass", true); | ||
TestHelper.AddSerializationPropertiesToModelClass(parentClass); | ||
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.TypeScript }, root); | ||
var codeFile = root.FindChildByName<CodeFile>(parentClass.Name.ToFirstCharacterUpperCase()); | ||
WriteCode(writer, codeFile); | ||
|
||
var result = tw.ToString(); | ||
Assert.Contains("// eslint-disable", result); | ||
Assert.Contains("// tslint:disable", result); | ||
Assert.Contains("export function deserializeIntoParentClass", result); | ||
Assert.Contains("export interface ParentClass", result); | ||
Assert.Contains("export function serializeParentClass", result); | ||
Assert.Contains("// eslint-enable", result); | ||
Assert.Contains("// tslint:enable", result); | ||
} | ||
|
||
} |
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