Пример #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 ShouldReturnExpectedIdentificationOfInterfaceWhenCalledMultipleTimesWithNodeJS()
        {
            // Given
            var interfaceIdentifierString = "ExampleInterface";

            var sourceFile = "interface.ts";
            var source     = File.ReadAllText($"./SourceFiles/{sourceFile}");
            var ast        = new NodeJS_ASTWrapper(source);

            // When
            var cachedInterfaceIdentifier = new InterfaceResponseTypeIdentifierCached();

            // First Identify
            cachedInterfaceIdentifier.Identify(
                interfaceIdentifierString,
                ast
                ).Should() // Then
            .BeTrue();

            // Second Identify
            cachedInterfaceIdentifier.Identify(
                interfaceIdentifierString,
                ast
                ).Should() // Then
            .BeTrue();
        }
        public void ShouldReturnExpectedIdentificationOfEnumWhenCalledMultipleTimesWithNodeJS()
        {
            // Given
            var enumIdentifierString = "EnumExport";

            var sourceFile = "enum.ts";
            var source     = File.ReadAllText($"./SourceFiles/{sourceFile}");
            var ast        = new NodeJS_ASTWrapper(source);

            // When
            var notCachedEnumIdentifier = new EnumTypeIdentifierCached();

            // First Identify
            notCachedEnumIdentifier.Identify(
                enumIdentifierString,
                ast
                ).Should() // Then
            .BeTrue();

            // Second Identify
            notCachedEnumIdentifier.Identify(
                enumIdentifierString,
                ast
                ).Should() // Then
            .BeTrue();
        }
        public void ShouldReturnExpectedIdentificationOfInterfaceWhenUsingCachedInstanceWithNodeJS()
        {
            // Given
            var expected = true;
            var interfaceIdentifierString = "ExampleInterface";

            var sourceFile = "interface.ts";
            var source     = File.ReadAllText($"./SourceFiles/{sourceFile}");
            var ast        = new NodeJS_ASTWrapper(source);

            // When
            var cachedInterfaceIdentifier = new InterfaceResponseTypeIdentifierCached();
            var actual = cachedInterfaceIdentifier.Identify(
                interfaceIdentifierString,
                ast
                );

            // Then
            actual.Should()
            .Be(expected);
        }
        public void ShouldReturnExpectedIdentificationOfEnumWhenUsingNotCachedInstanceWithNodeJS()
        {
            // Given
            var expected             = true;
            var enumIdentifierString = "EnumExport";

            var sourceFile = "enum.ts";
            var source     = File.ReadAllText($"./SourceFiles/{sourceFile}");
            var ast        = new NodeJS_ASTWrapper(source);

            // When
            var notCachedEnumIdentifier = new EnumTypeIdentifierNotCached();
            var actual = notCachedEnumIdentifier.Identify(
                enumIdentifierString,
                ast
                );

            // Then
            actual.Should()
            .Be(expected);
        }
        public void ShouldReturnExpectedIdentificationWhenTypeStatementIsUsedAndNotCachedWithNodeJS(
            string typeName,
            string genericName,
            bool isModifier,
            bool isArray,
            bool isNullable,
            bool expected
            )
        {
            // Given
            var type = new TypeStatement
            {
                Name         = typeName,
                IsModifier   = isModifier,
                IsArray      = isArray,
                IsNullable   = isNullable,
                GenericTypes = new List <TypeStatement>
                {
                    new TypeStatement
                    {
                        Name = genericName
                    }
                }
            };

            var sourceFile = "interface.ts";
            var source     = File.ReadAllText($"./SourceFiles/{sourceFile}");
            var ast        = new NodeJS_ASTWrapper(source);

            // When
            var cachedInterfaceIdentifier = new InterfaceResponseTypeIdentifierNotCached();
            var actual = cachedInterfaceIdentifier.Identify(
                type,
                ast
                );

            // Then
            actual.Should()
            .Be(expected);
        }