diff --git a/src/GraphQlClientGenerator/GraphQlGenerator.cs b/src/GraphQlClientGenerator/GraphQlGenerator.cs index 8a3466d..0e49406 100644 --- a/src/GraphQlClientGenerator/GraphQlGenerator.cs +++ b/src/GraphQlClientGenerator/GraphQlGenerator.cs @@ -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(); } diff --git a/test/GraphQlClientGenerator.Test/GraphQlClientSourceGeneratorTest.cs b/test/GraphQlClientGenerator.Test/GraphQlClientSourceGeneratorTest.cs index 2c2053d..51e76f9 100644 --- a/test/GraphQlClientGenerator.Test/GraphQlClientSourceGeneratorTest.cs +++ b/test/GraphQlClientGenerator.Test/GraphQlClientSourceGeneratorTest.cs @@ -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); } @@ -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)