public void ShouldCallWriterWithGeneratedClassStatement()
        {
            // Given
            var projectAssembly = "ProjectAssembly";
            var sourceDirectory = "";
            var sourceFileName  = "MultipleGeneration.d.ts";
            var sourceFile      = Path.Combine(
                ".",
                "SourceFiles",
                sourceFileName
                );
            var sourceFiles = new List <string>
            {
                sourceFile
            };
            var generationList = new List <string>
            {
                "Vector3",
            };
            var typeOverrideMap = new Dictionary <string, string>();

            var writerMock = new Mock <IWriter>();

            // When
            var generateSource = new GenerateSource();
            var actual         = default(IList <GeneratedStatement>);

            writerMock.Setup(
                mock => mock.Write(
                    It.IsAny <IList <GeneratedStatement> >()
                    )
                ).Callback <IList <GeneratedStatement> >(
                (generatedStatement) =>
            {
                actual = generatedStatement;
            }
                );

            generateSource.Run(
                projectAssembly,
                sourceDirectory,
                sourceFiles,
                generationList,
                writerMock.Object,
                new NoFormattingTextFormatter(),
                typeOverrideMap
                );


            // Then
            actual.Should().NotBeNull();
            actual.Should().HaveCount(5);
        }
        public void ValidateGenerateStrings(
            string path,
            string sourceFile,
            string expectedFile,
            string classIdentifier = "ExampleClass"
            )
        {
            // Given
            ReadInteropTemplates.SetReadTemplates();
            GenerateSource.DisableCache();
            var sourcePath = Path.Combine(
                ".",
                "GenerateClassStatementStringTests",
                path
                );
            string expected = File.ReadAllText(Path.Combine(
                                                   sourcePath,
                                                   expectedFile
                                                   ));
            var source = File.ReadAllText(Path.Combine(
                                              sourcePath,
                                              sourceFile
                                              ));
            var ast = new TypeScriptAST(
                source,
                sourceFile
                );
            var typeOverrideMap = new Dictionary <string, string>();

            // When
            var generated = GenerateInteropClassStatement.Generate(
                "ProjectAssembly",
                classIdentifier,
                ast,
                typeOverrideMap
                );
            var actual = GenerateClassStatementString.Generate(
                generated,
                new NoFormattingTextFormatter()
                );

            // Then
            actual.Should().Be(
                expected
                );
        }
Exemplo n.º 3
0
        public void ValidateGenerateWithTypeOverrideStrings(
            string path,
            string sourceFile,
            IDictionary <string, string> typeOverrideMap,
            string expectedFile,
            ASTParserType parserType = ASTParserType.Sdcb
            )
        {
            // Given
            GenerateSource.DisableCache();
            var sourcePath = Path.Combine(
                ".",
                "GenerateClassStatementStringTests",
                path
                );
            string expected = File.ReadAllText(Path.Combine(
                                                   sourcePath,
                                                   expectedFile
                                                   ));
            var source = File.ReadAllText(Path.Combine(
                                              sourcePath,
                                              sourceFile
                                              ));
            var ast = CreateParser(
                parserType,
                source
                );

            // When
            var generated = GenerateInteropClassStatement.Generate(
                "ProjectAssembly",
                "ExampleClass",
                ast,
                typeOverrideMap
                );
            var actual = GenerateClassStatementString.Generate(
                generated,
                new NoFormattingTextFormatter()
                );

            // Then
            actual.Should().Be(
                expected
                );
        }
        public void ShouldGenerateSourceForEverythingDefinition()
        {
            // Given
            ReadInteropTemplates.SetReadTemplates();
            var projectAssembly = "ProjectAssembly";
            var sourceDirectory = "";
            var sourceFileName  = "MultipleGeneration.d.ts";
            var sourceFile      = Path.Combine(
                ".",
                "SourceFiles",
                sourceFileName
                );
            var sourceFiles = new List <string>
            {
                sourceFile
            };
            var generationList = new List <string>
            {
                "Mesh",
                "Mesh",
                "Engine",
                "Vector3",
            };
            var typeOverrideMap = new Dictionary <string, string>();

            var writerMock = new Mock <IWriter>();

            // When
            var generateSource = new GenerateSource();
            var actual         = generateSource.Run(
                projectAssembly,
                sourceDirectory,
                sourceFiles,
                generationList,
                writerMock.Object,
                new NoFormattingTextFormatter(),
                typeOverrideMap
                );


            // Then
            actual.Should().BeTrue();
        }
Exemplo n.º 5
0
        public void ShouldGenerateSourceForEverythingDefinitionWhenUsingTheNodeJS_AST()
        {
            // Given
            var projectAssembly = "ProjectAssembly";
            var sourceDirectory = "";
            var sourceFileName  = "Everything.ts";
            var sourceFile      = Path.Combine(
                ".",
                "SourceFiles",
                sourceFileName
                );
            var sourceFiles = new List <string>
            {
                sourceFile
            };
            var generationList = new List <string>
            {
                "Everything",
            };
            var typeOverrideMap = new Dictionary <string, string>();

            var writerMock = new Mock <IWriter>();

            // When
            var generateSource = new GenerateSource();
            var actual         = generateSource.Run(
                projectAssembly,
                sourceDirectory,
                sourceFiles,
                generationList,
                writerMock.Object,
                new NoFormattingTextFormatter(),
                typeOverrideMap,
                ASTParserType.NodeJS
                );

            // Then
            actual.Should().BeTrue();
        }