Exemple #1
0
        public void Generate_GenerationSpecGiven_AssemblyRegexTypesGenerated(string outputPath)
        {
            //arrange

            var generator = new Core.Generator(_fileSystem)
            {
                Options = { BaseOutputDirectory = outputPath, CreateIndexFile = true, StrictNullChecks = true }
            };
            var assemblyResolver = new AssemblyResolver(new FileSystem(), new Logger(), ProjectPath);
            var generationSpec   = new AssemblyRegexTypesGenerationSpec();

            //act

            assemblyResolver.Register();
            generator.Generate(generationSpec);
            assemblyResolver.Unregister();

            //assert

            _fileSystem.Received().SaveFile(outputPath + "bar.ts", Content["bar.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "c.ts", Content["c.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "d.ts", Content["d.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "e-class.ts", Content["e-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "f-class.ts", Content["f-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "foo.ts", Content["foo.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "foo-type.ts", Content["foo-type.ts"]);
        }
        public void Generate_GenerationSpecGiven_TypeScriptContentGenerated(string outputPath)
        {
            //arrange

            var generator = new Core.Generator(new GeneratorOptions {
                BaseOutputDirectory = outputPath, CreateIndexFile = true
            }, _fileSystem);
            var assemblyResolver = new AssemblyResolver(new FileSystem(), new ConsoleLogger(), ProjectPath);
            var generationSpec   = new AcceptanceTestGenerationSpec();

            //act

            assemblyResolver.Register();
            generator.Generate(generationSpec);
            assemblyResolver.Unregister();

            //assert

            _fileSystem.Received().SaveFile(outputPath + "custom-base-class.ts", Content["custom-base-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "custom-base-custom-import.ts", Content["custom-base-custom-import.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "custom-empty-base-class.ts", Content["custom-empty-base-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "extended-primitives-class.ts", Content["extended-primitives-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "external-deps-class.ts", Content["external-deps-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "generic-base-class.ts", Content["generic-base-class.ts"]);
        }
Exemple #3
0
        public void Generate_GenerationSpecGiven_IndividualTypesGenerated(string outputPath)
        {
            //arrange

            var generator = new Core.Generator(_fileSystem)
            {
                Options = { BaseOutputDirectory = outputPath, CreateIndexFile = true, StrictNullChecks = true }
            };
            var assemblyResolver = new AssemblyResolver(new FileSystem(), new Logger(), ProjectPath);
            var generationSpec   = new IndividualTypesGenerationSpec();

            //act

            assemblyResolver.Register();
            generator.Generate(generationSpec);
            assemblyResolver.Unregister();

            //assert

            _fileSystem.Received().SaveFile(outputPath + "custom-base-class.ts", Content["custom-base-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "custom-base-custom-import.ts", Content["custom-base-custom-import.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "custom-empty-base-class.ts", Content["custom-empty-base-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "extended-primitives-class.ts", Content["extended-primitives-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "external-deps-class.ts", Content["external-deps-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "generic-base-class.ts", Content["generic-base-class.ts"]);
        }
        public void Generate_AssemblyGiven_TypeScriptContentGenerated(string outputPath)
        {
            //arrange

            const string assemblyPath = ProjectPath + "bin/Debug/netcoreapp2.0/TypeGen.TestWebApp.dll";

            var generator = new Core.Generator(new GeneratorOptions {
                BaseOutputDirectory = outputPath, CreateIndexFile = true
            }, _fileSystem);

            Assembly assembly         = Assembly.LoadFrom(assemblyPath);
            var      assemblyResolver = new AssemblyResolver(new FileSystem(), new ConsoleLogger(), ProjectPath);

            //act

            assemblyResolver.Register();
            generator.Generate(assembly);
            assemblyResolver.Unregister();

            //assert

            _fileSystem.Received().SaveFile(outputPath + "foo-constants.ts", Content["foo-constants.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "bar.ts", Content["bar.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "base-class.ts", Content["base-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "base-class2.ts", Content["base-class2.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "c.ts", Content["c.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "custom-base-class.ts", Content["custom-base-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "custom-base-custom-import.ts", Content["custom-base-custom-import.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "custom-empty-base-class.ts", Content["custom-empty-base-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "d.ts", Content["d.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "default-member-values.ts", Content["default-member-values.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "e-class.ts", Content["e-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "extended-primitives-class.ts", Content["extended-primitives-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "external-deps-class.ts", Content["external-deps-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "f-class.ts", Content["f-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "foo-type.ts", Content["foo-type.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "foo.ts", Content["foo.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "generic-base-class.ts", Content["generic-base-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "generic-class.ts", Content["generic-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "generic-with-restrictions.ts", Content["generic-with-restrictions.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "index.ts", Arg.Any <string>()); // any content, because file order in index.ts is different each time
            _fileSystem.Received().SaveFile(outputPath + "lite-db-entity.ts", Content["lite-db-entity.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "readonly-interface.ts", Content["readonly-interface.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "standalone-enum.ts", Content["standalone-enum.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "enum-short-values.ts", Content["enum-short-values.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "static-readonly.ts", Content["static-readonly.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "strict-nulls-class.ts", Content["strict-nulls-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "with-generic-base-class-custom-type.ts", Content["with-generic-base-class-custom-type.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "with-ignored-base-and-custom-base.ts", Content["with-ignored-base-and-custom-base.ts"]);
            _fileSystem.Received().SaveFile(outputPath + "with-ignored-base.ts", Content["with-ignored-base.ts"]);

            _fileSystem.Received().SaveFile(outputPath + @"no/slash/output/dir/no-slash-output-dir.ts", Content[@"no\slash\output\dir\no-slash-output-dir.ts"]);

            _fileSystem.Received().SaveFile(outputPath + @"test-classes/base-class.ts", Content[@"test-classes\base-class.ts"]);
            _fileSystem.Received().SaveFile(outputPath + @"test-classes/base-class2.ts", Content[@"test-classes\base-class2.ts"]);
            _fileSystem.Received().SaveFile(outputPath + @"test-classes/circular-ref-class1.ts", Content[@"test-classes\circular-ref-class1.ts"]);
            _fileSystem.Received().SaveFile(outputPath + @"test-classes/circular-ref-class2.ts", Content[@"test-classes\circular-ref-class2.ts"]);
            _fileSystem.Received().SaveFile(outputPath + @"test-classes/test-class.ts", Content[@"test-classes\test-class.ts"]);

            _fileSystem.Received().SaveFile(outputPath + @"test-enums/test-enum.ts", Content[@"test-enums\test-enum.ts"]);

            _fileSystem.Received().SaveFile(outputPath + @"test-interfaces/test-interface.ts", Content[@"test-interfaces\test-interface.ts"]);

            _fileSystem.Received().SaveFile(outputPath + @"./very/nested/directory/nested-entity.ts", Content[@"very\nested\directory\nested-entity.ts"]);

            _fileSystem.Received().SaveFile(outputPath + @"default-export/class-with-default-export.ts", Content[@"default-export\class-with-default-export.ts"]);
            _fileSystem.Received().SaveFile(outputPath + @"default-export/generic-class-with-default-export.ts", Content[@"default-export\generic-class-with-default-export.ts"]);
            _fileSystem.Received().SaveFile(outputPath + @"default-export/class-with-imports.ts", Content[@"default-export\class-with-imports.ts"]);
            _fileSystem.Received().SaveFile(outputPath + @"default-export/class-without-default-export.ts", Content[@"default-export\class-without-default-export.ts"]);
            _fileSystem.Received().SaveFile(outputPath + @"default-export/interface-with-default-export.ts", Content[@"default-export\interface-with-default-export.ts"]);
        }