<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Xunit;

namespace XmlSchemaClassGenerator.Tests
{
    public class XsdElsterDatenabholung5
    {
        [Fact]
        public void CanGenerateClasses()
        {
            Assert.DoesNotThrow(() =>
            {
                var gen = new Generator
                {
                    UseXElementForAny = true,
                    CollectionType = typeof(IList<>),
                    CollectionImplementationType = typeof(List<>),
                    GenerateDesignerCategoryAttribute = false,
                    GenerateNullables = true,
                    GenerateSerializableAttribute = false,
                    OutputFolder = OutputPath,
                    NamingScheme = NamingScheme.Direct,
                    DataAnnotationMode = DataAnnotationMode.None,
                    NamespaceProvider = new NamespaceProvider()
                    {
                        GenerateNamespace = key =>
                        {
                            switch (Path.GetFileName(key.Source.LocalPath))
                            {
                                case "th000008_extern.xsd":
                                case "ndh000010_extern.xsd":
                                case "headerbasis000002.xsd":
                                    return "Elster.Basis";
                                case "datenabholung_5.xsd":
                                case "elster0810_datenabholung_5.xsd":
                                    switch (key.XmlSchemaNamespace)
                                    {
                                        case "http://www.elster.de/2002/XMLSchema":
                                            return "Elster.Datenabholung5";
                                        default:
                                            throw new NotSupportedException(string.Format("Namespace {0} for schema {1}", key.XmlSchemaNamespace, key.Source));
                                    }
                                default:
                                    throw new NotSupportedException(string.Format("Namespace {0} for schema {1}", key.XmlSchemaNamespace, key.Source));
                            }
                        }
                    }
                };
                var xsdFiles = new[]
                {
                    "headerbasis000002.xsd",
                    "ndh000010_extern.xsd",
                    "th000008_extern.xsd",
                    "datenabholung_5.xsd",
                    "elster0810_datenabholung_5.xsd",
                }.Select(x => Path.Combine(InputPath, x)).ToList();
                gen.Generate(xsdFiles);
            });
        }

        string InputPath
        {
            get { return Path.Combine(Directory.GetCurrentDirectory(), "xsd", "elster-xml-datenabholung5"); }
        }

        string OutputPath
        {
            get
            {
                var result = Path.Combine(Directory.GetCurrentDirectory(), "output", "elster-xml-datenabholung5");
                Directory.CreateDirectory(result);
                return result;
            }
        }
    }<commit_msg>Test if the output is compilable<commit_after>﻿using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Xunit;

namespace XmlSchemaClassGenerator.Tests
{
    public class XsdElsterDatenabholung5
    {
        private void GenerateOutput(string outputPath)
        {
            var gen = new Generator
            {
                UseXElementForAny = true,
                CollectionType = typeof(IList<>),
                CollectionImplementationType = typeof(List<>),
                GenerateDesignerCategoryAttribute = false,
                GenerateNullables = true,
                GenerateSerializableAttribute = false,
                OutputFolder = outputPath,
                NamingScheme = NamingScheme.Direct,
                DataAnnotationMode = DataAnnotationMode.None,
                NamespaceProvider = new NamespaceProvider()
                {
                    GenerateNamespace = key =>
                    {
                        switch (Path.GetFileName(key.Source.LocalPath))
                        {
                            case "th000008_extern.xsd":
                            case "ndh000010_extern.xsd":
                            case "headerbasis000002.xsd":
                                return "Elster.Basis";
                            case "datenabholung_5.xsd":
                            case "elster0810_datenabholung_5.xsd":
                                switch (key.XmlSchemaNamespace)
                                {
                                    case "http://www.elster.de/2002/XMLSchema":
                                        return "Elster.Datenabholung5";
                                    default:
                                        throw new NotSupportedException(string.Format("Namespace {0} for schema {1}", key.XmlSchemaNamespace, key.Source));
                                }
                            default:
                                throw new NotSupportedException(string.Format("Namespace {0} for schema {1}", key.XmlSchemaNamespace, key.Source));
                        }
                    }
                }
            };
            var xsdFiles = new[]
                {
                    "headerbasis000002.xsd",
                    "ndh000010_extern.xsd",
                    "th000008_extern.xsd",
                    "datenabholung_5.xsd",
                    "elster0810_datenabholung_5.xsd",
                }.Select(x => Path.Combine(InputPath, x)).ToList();
            gen.Generate(xsdFiles);
        }

        [Fact]
        public void CanGenerateClasses()
        {
            Assert.DoesNotThrow(() =>
            {
                GenerateOutput(GetOutputPath("CanGenerateClasses"));
            });
        }

        [Fact]
        public void CanCompileClasses()
        {
            var outputPath = GetOutputPath("CanCompileClasses");
            Assert.DoesNotThrow(() =>
            {
                new DirectoryInfo(outputPath).GetFiles("*.cs").ToList().ForEach(x => x.Delete());
                GenerateOutput(outputPath);
            });
            var provider = CodeDomProvider.CreateProvider("CSharp");
            var assemblies = new[]
            {
                "System.dll",
                "System.Core.dll",
                "System.Xml.dll",
                "System.Xml.Linq.dll",
                "System.Xml.Serialization.dll",
                "System.ServiceModel.dll",
            };
            var outputName = Path.Combine(outputPath, "Elster.Test.dll");
            var fileNames = new DirectoryInfo(outputPath).GetFiles("*.cs").Select(x => x.FullName).ToArray();
            var results = provider.CompileAssemblyFromFile(new CompilerParameters(assemblies, outputName), fileNames);
            Assert.Equal(0, results.Errors.Count);
            Assert.DoesNotThrow(() => results.CompiledAssembly.GetType("Elster.Datenabholung5.Elster", true));
            Assert.DoesNotThrow(() => results.CompiledAssembly.GetType("Elster.Basis.TransferHeaderCType", true));
        }

        string InputPath
        {
            get { return Path.Combine(Directory.GetCurrentDirectory(), "xsd", "elster-xml-datenabholung5"); }
        }

        private string GetOutputPath(string testCaseId)
        {
            var result = Path.Combine(Directory.GetCurrentDirectory(), "output", "elster-xml-datenabholung5", testCaseId);
            Directory.CreateDirectory(result);
            return result;
        }
    }
{'fraction_non_alphanumeric': 0.08777145811789039, 'fraction_numerical': 0.01577042399172699, 'mean_word_length': 1.2367736339982653, 'pattern_counts': {'":': 12, '<': 7, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5103992', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1741, 'n_words': 295}