public async Task TestConversionCSharpToVisualBasicAsync(string csharpCode, string expectedVisualBasicCode, bool expectSurroundingMethodBlock = false, bool expectCompilationErrors = false, TextConversionOptions conversionOptions = null, bool hasLineCommentConversionIssue = false)
        {
            expectedVisualBasicCode = AddSurroundingMethodBlock(expectedVisualBasicCode, expectSurroundingMethodBlock);

            conversionOptions ??= new TextConversionOptions(DefaultReferences.NetStandard2)
            {
                ShowCompilationErrors = !expectSurroundingMethodBlock
            };
            await AssertConvertedCodeResultEqualsAsync <CSToVBConversion>(csharpCode, expectedVisualBasicCode, conversionOptions);

            if (_testCstoVbCommentsByDefault && !hasLineCommentConversionIssue)
            {
                await AssertLineCommentsConvertedInSameOrderAsync <CSToVBConversion>(csharpCode, conversionOptions, "//", LineCanHaveCSharpComment);
            }
        }
        /// <summary>
        /// Lines that already have comments aren't automatically tested, so if a line changes order in a conversion, just add a comment to that line.
        /// If there's a comment conversion issue, set the optional hasLineCommentConversionIssue to true
        /// </summary>
        private async Task AssertLineCommentsConvertedInSameOrderAsync <TLanguageConversion>(string source, TextConversionOptions conversion, string singleLineCommentStart, Func <string, bool> lineCanHaveComment) where TLanguageConversion : ILanguageConversion, new()
        {
            var(sourceLinesWithComments, lineNumbersAdded) = AddLineNumberComments(source, singleLineCommentStart, AutoTestCommentPrefix, lineCanHaveComment);
            string sourceWithComments = string.Join(Environment.NewLine, sourceLinesWithComments);
            var    convertedCode      = await ConvertAsync <TLanguageConversion>(sourceWithComments, conversion);

            var convertedCommentLineNumbers = convertedCode.Split(new[] { AutoTestCommentPrefix }, StringSplitOptions.None)
                                              .Skip(1).Select(afterPrefix => afterPrefix.Split('\n')[0].TrimEnd()).ToList();
            var missingSourceLineNumbers = lineNumbersAdded.Except(convertedCommentLineNumbers);

            if (missingSourceLineNumbers.Any())
            {
                Assert.False(true, "Comments not converted from source lines: " + string.Join(", ", missingSourceLineNumbers) + GetSourceAndConverted(sourceWithComments, convertedCode));
            }
            OurAssert.Equal(string.Join(", ", lineNumbersAdded), string.Join(", ", convertedCommentLineNumbers), () => GetSourceAndConverted(sourceWithComments, convertedCode));
        }
        protected async Task AssertConvertedCodeResultEqualsAsync <TLanguageConversion>(string inputCode, string expectedConvertedCode, TextConversionOptions conversionOptions = default) where TLanguageConversion : ILanguageConversion, new()
        {
            string convertedTextFollowedByExceptions = await ConvertAsync <TLanguageConversion>(inputCode, conversionOptions);

            AssertConvertedCodeResultEquals(convertedTextFollowedByExceptions, expectedConvertedCode, inputCode);
        }
        protected async Task <string> ConvertAsync <TLanguageConversion>(string inputCode, TextConversionOptions conversionOptions = default) where TLanguageConversion : ILanguageConversion, new()
        {
            var textConversionOptions = conversionOptions ?? new TextConversionOptions(DefaultReferences.NetStandard2)
            {
                RootNamespaceOverride = _rootNamespace, ShowCompilationErrors = true
            };
            var conversionResult = await ProjectConversion.ConvertTextAsync <TLanguageConversion>(inputCode, textConversionOptions);

            return((conversionResult.ConvertedCode ?? "") + (conversionResult.GetExceptionsAsString() ?? ""));
        }
        public async Task TestConversionCSharpToVisualBasic(string csharpCode, string expectedVisualBasicCode, bool expectSurroundingMethodBlock = false, bool expectCompilationErrors = false, TextConversionOptions conversion = null, bool hasLineCommentConversionIssue = false)
        {
            expectedVisualBasicCode = AddSurroundingMethodBlock(expectedVisualBasicCode, expectSurroundingMethodBlock);

            await TestConversionCSharpToVisualBasicWithoutComments(csharpCode, expectedVisualBasicCode, conversion);

            if (_testCstoVBCommentsByDefault && !hasLineCommentConversionIssue)
            {
                await AssertLineCommentsConvertedInSameOrder(csharpCode, conversion, "//", LineCanHaveCSharpComment);
            }
        }
        protected static async Task <string> GetConvertedCodeOrErrorString <TLanguageConversion>(string toConvert, TextConversionOptions conversionOptions = default) where TLanguageConversion : ILanguageConversion, new()
        {
            var conversionResult = await ProjectConversion.ConvertText <TLanguageConversion>(toConvert, conversionOptions ?? new TextConversionOptions(DefaultReferences.NetStandard2));

            var convertedCode = conversionResult.ConvertedCode ?? conversionResult.GetExceptionsAsString();

            return(convertedCode);
        }
 private async Task TestConversionCSharpToVisualBasicWithoutComments(string csharpCode, string expectedVisualBasicCode, TextConversionOptions conversionOptions = null)
 {
     await AssertConvertedCodeResultEquals <CSToVBConversion>(csharpCode, expectedVisualBasicCode, conversionOptions);
 }