<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Text;
using Shouldly;
using Xunit;

namespace GraphQlClientGenerator.Test
{
    public class GraphQlClientSourceGeneratorTest : IDisposable
    {
        private const string TestFileName = "GraphQlClientSourceGeneratorTest";

        private readonly GraphQlSchemaFile _schemaFile;

        public GraphQlClientSourceGeneratorTest()
        {
            var resourceStream = typeof(GraphQlGeneratorTest).Assembly.GetManifestResourceStream("GraphQlClientGenerator.Test.TestSchema3");
            var fileName = Path.Combine(Path.GetTempPath(), TestFileName + ".json");
            using var fileStream = File.Create(fileName);
            resourceStream.CopyTo(fileStream);
            _schemaFile = new GraphQlSchemaFile(fileName);
        }

        public void Dispose()
        {
            if (File.Exists(_schemaFile.Path))
                File.Delete(_schemaFile.Path);
        }

        [Fact]
        public void SourceGeneration()
        {
            var sourceGenerator = new GraphQlClientSourceGenerator();
            sourceGenerator.Initialize(new GeneratorInitializationContext());

            var compilerAnalyzerConfigOptionsProvider =
                new CompilerAnalyzerConfigOptionsProvider(
                    new CompilerAnalyzerConfigOptions(
                        new Dictionary<string, string>
                        {
                            { "build_property.GraphQlClientGenerator_ClassPrefix", "SourceGenerated" },
                            { "build_property.GraphQlClientGenerator_ClassSuffix", "V2" },
                            { "build_property.GraphQlClientGenerator_IncludeDeprecatedFields", "true" },
                            { "build_property.GraphQlClientGenerator_CommentGeneration", "CodeSummary" },
                            { "build_property.GraphQlClientGenerator_FloatTypeMapping", "Double" },
                            { "build_property.GraphQlClientGenerator_BooleanTypeMapping", "Boolean" },
                            { "build_property.GraphQlClientGenerator_IdTypeMapping", "String" },
                            { "build_property.GraphQlClientGenerator_JsonPropertyGeneration", "Always" },
                            { "build_property.GraphQlClientGenerator_CustomClassMapping", "Query:Tibber|RootMutation:TibberMutation Consumption:ConsumptionEntry;Production:ProductionEntry" },
                            { "build_property.GraphQlClientGenerator_Headers", "Authorization:Basic XXX|X-REQUEST-ID:123456789" }
                        }));

            var compilation = CompilationHelper.CreateCompilation(null, "SourceGeneratorTestAssembly");

            var generatorExecutionContextType = typeof(GeneratorExecutionContext);
            var constructorInfo = generatorExecutionContextType.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)[0];
            var executionContext =
                (GeneratorExecutionContext)constructorInfo.Invoke(
                    new object[]
                    {
                        compilation,<commit_msg>include new configuration property in the test<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Text;
using Shouldly;
using Xunit;

namespace GraphQlClientGenerator.Test
{
    public class GraphQlClientSourceGeneratorTest : IDisposable
    {
        private const string TestFileName = "GraphQlClientSourceGeneratorTest";

        private readonly GraphQlSchemaFile _schemaFile;

        public GraphQlClientSourceGeneratorTest()
        {
            var resourceStream = typeof(GraphQlGeneratorTest).Assembly.GetManifestResourceStream("GraphQlClientGenerator.Test.TestSchema3");
            var fileName = Path.Combine(Path.GetTempPath(), TestFileName + ".json");
            using var fileStream = File.Create(fileName);
            resourceStream.CopyTo(fileStream);
            _schemaFile = new GraphQlSchemaFile(fileName);
        }

        public void Dispose()
        {
            if (File.Exists(_schemaFile.Path))
                File.Delete(_schemaFile.Path);
        }

        [Fact]
        public void SourceGeneration()
        {
            var sourceGenerator = new GraphQlClientSourceGenerator();
            sourceGenerator.Initialize(new GeneratorInitializationContext());

            var compilerAnalyzerConfigOptionsProvider =
                new CompilerAnalyzerConfigOptionsProvider(
                    new CompilerAnalyzerConfigOptions(
                        new Dictionary<string, string>
                        {
                            { "build_property.GraphQlClientGenerator_ClassPrefix", "SourceGenerated" },
                            { "build_property.GraphQlClientGenerator_ClassSuffix", "V2" },
                            { "build_property.GraphQlClientGenerator_IncludeDeprecatedFields", "true" },
                            { "build_property.GraphQlClientGenerator_CommentGeneration", "CodeSummary" },
                            { "build_property.GraphQlClientGenerator_FloatTypeMapping", "Double" },
                            { "build_property.GraphQlClientGenerator_BooleanTypeMapping", "Boolean" },
                            { "build_property.GraphQlClientGenerator_IdTypeMapping", "String" },
                            { "build_property.GraphQlClientGenerator_JsonPropertyGeneration", "Always" },
                            { "build_property.GraphQlClientGenerator_CustomClassMapping", "Query:Tibber|RootMutation:TibberMutation Consumption:ConsumptionEntry;Production:ProductionEntry" },
                            { "build_property.GraphQlClientGenerator_Headers", "Authorization:Basic XXX|X-REQUEST-ID:123456789" },
                            { "build_property.GraphQlClientGenerator_ScalarFieldTypeMappingProvider", "GraphQlClientGenerator.DefaultScalarFieldTypeMappingProvider, GraphQlClientGenerator" }
                        }));

            var compilation = CompilationHelper.CreateCompilation(null, "SourceGeneratorTestAssembly");

            var generatorExecutionContextType = typeof(GeneratorExecutionContext);
            var constructorInfo = generatorExecutionContextType.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)[0];
            var executionContext =
                (GeneratorExecutionContext)constructorInfo.Invoke(
                    new object[]
                    {
                        compilation,
{'fraction_non_alphanumeric': 0.07490369524896562, 'fraction_numerical': 0.0034241689256669997, 'mean_word_length': 2.5728848114169214, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1891199', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1588, 'n_words': 258}