Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Husqvik committed Jan 28, 2023
1 parent e78d30a commit c323364
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/GraphQlClientGenerator/GraphQlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,22 @@ public void WriteFullClientCSharpFile(GraphQlSchema schema, string @namespace, T
writer.WriteLine();
writer.WriteLine(RequiredNamespaces);
writer.Write("namespace ");
writer.Write(@namespace);

if (_configuration.FileScopedNamespaces)
{
writer.Write(@namespace);
writer.WriteLine(";");
writer.WriteLine();
Generate(new SingleFileGenerationContext(schema, writer, indentationSize: 0));
}
else
{
writer.WriteLine(@namespace);
writer.WriteLine();
writer.WriteLine("{");
Generate(new SingleFileGenerationContext(schema, writer, indentationSize: 4));
writer.WriteLine("}");
}

writer.Flush();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,17 @@ public void Dispose()
File.Delete(_fileMappingRules.Path);
}

[Fact]
public void SourceGeneration()
{
var generatedSource = GenerateSource(null, "GraphQlClientGenerator.DefaultScalarFieldTypeMappingProvider, GraphQlClientGenerator", false);

generatedSource.Encoding.ShouldBe(Encoding.UTF8);
var sourceCode = generatedSource.ToString();

var expectedSourceCode = GetExpectedSourceText("SourceGeneratorResult");
sourceCode.ShouldBe(expectedSourceCode);
}

[Fact]
public void SourceGeneration_UseFileScopedNamespaces()
[Theory]
[InlineData("GraphQlClientGenerator.DefaultScalarFieldTypeMappingProvider, GraphQlClientGenerator", false, "SourceGeneratorResult")]
[InlineData(null, true, "SourceGeneratorResultWithFileScopedNamespaces")]
public void SourceGeneration(string scalarFieldTypeMappingProviderTypeName, bool useFileScopedNamespace, string expectedResultResourceName)
{
var generatedSource = GenerateSource(null, null, true);
var generatedSource = GenerateSource(null, scalarFieldTypeMappingProviderTypeName, useFileScopedNamespace);

generatedSource.Encoding.ShouldBe(Encoding.UTF8);
var sourceCode = generatedSource.ToString();

var expectedSourceCode = GetExpectedSourceText("SourceGeneratorResultWithFileScopedNamespaces");
var expectedSourceCode = GetExpectedSourceText(expectedResultResourceName);
sourceCode.ShouldBe(expectedSourceCode);
}

Expand All @@ -73,7 +63,8 @@ public void SourceGenerationWithRegexCustomScalarFieldTypeMappingProvider()

private static string GetExpectedSourceText(string expectedResultsFile)
{
using var reader = new StreamReader(typeof(GraphQlGeneratorTest).Assembly.GetManifestResourceStream($"GraphQlClientGenerator.Test.ExpectedSingleFileGenerationContext.{expectedResultsFile}"));return reader.ReadToEnd();
using var reader = new StreamReader(typeof(GraphQlGeneratorTest).Assembly.GetManifestResourceStream($"GraphQlClientGenerator.Test.ExpectedSingleFileGenerationContext.{expectedResultsFile}"));
return reader.ReadToEnd();
}

private SourceText GenerateSource(AdditionalText additionalFile, string scalarFieldTypeMappingProviderTypeName, bool useFileScopedNamespaces)
Expand Down

0 comments on commit c323364

Please sign in to comment.