示例#1
0
        public void ShouldGenerateInterfaceStringWhenUsingNodeJS()
        {
            // Given
            var sourceFile      = "interface.ts";
            var source          = File.ReadAllText($"./SourceFiles/{sourceFile}");
            var expected        = File.ReadAllText($"./ExpectedResults/interface.Expected.txt");
            var ast             = new NodeJS_ASTWrapper(source);
            var typeOverrideMap = new Dictionary <string, string>();

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

            // Then
            actual.Should().Be(
                expected
                );
        }
        public void ShouldGenerateFormattedString()
        {
            // Given
            var sourceFile      = "CSharpTextFormatter.d.ts";
            var source          = File.ReadAllText($"./Formatter/SourceFiles/{sourceFile}");
            var expected        = File.ReadAllText($"./Formatter/ExpectedResults/CSharpTextFormatter.Expected.txt");
            var ast             = new TypeScriptAST(source, sourceFile);
            var typeOverrideMap = new Dictionary <string, string>();

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

            // Then
            actual.Should().Be(
                expected
                );
        }
        public void ShouldNotWrapValueTaskTwiceWhenMethodReturnsPromise()
        {
            // Given
            var sourceFile      = "Method.Promise.d.ts";
            var source          = File.ReadAllText($"./SourceFiles/{sourceFile}");
            var expected        = File.ReadAllText($"./ExpectedResults/Method.Promise.Expected.txt");
            var ast             = new Sdcb_TypeScriptASTWrapper(source);
            var typeOverrideMap = new Dictionary <string, string>();

            // When
            TypeStatementTemplates.TaskTemplate = "[[GENERIC_TYPES]]";
            ReadInteropTemplates.SetReadTemplates();

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

            // Then
            actual.Should().Be(
                expected
                );
        }
        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
                );
        }
示例#5
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
                );
        }