using CodePlay.Core.Converters; using CodePlay.Core.Models; using CodePlay.Core.Common; using CodePlay.Core.Parsers; using Xunit; namespace CodePlay.Tests.Converters; public class CSharpToJavaConverterTests { private readonly CSharpToJavaConverter _converter; private readonly CSharpParser _parser; public CSharpToJavaConverterTests() { _converter = new CSharpToJavaConverter(); _parser = new CSharpParser(); } [Fact] public async Task ConvertAsync_SimpleClass_ShouldConvertSuccessfully() { var sourceCode = @" namespace TestApp { public class Person { public string Name { get; set; } public int Age { get; set; } } }"; var syntaxTree = await _parser.ParseAsync(sourceCode); var result = await _converter.ConvertAsync(syntaxTree, LanguageType.Java); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.TransformedCode); Assert.Contains("package", result.TransformedCode); Assert.Contains("public class Person", result.TransformedCode); } [Fact] public async Task ConvertAsync_WithMethods_ShouldConvertMethods() { var sourceCode = @" namespace TestApp { public class Calculator { public int Add(int a, int b) { return a + b; } public string GetMessage() { return ""Hello""; } } }"; var syntaxTree = await _parser.ParseAsync(sourceCode); var result = await _converter.ConvertAsync(syntaxTree, LanguageType.Java); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.TransformedCode); Assert.NotNull(result.Report); Assert.True(result.Report.MethodsConverted > 0); } [Fact] public async Task ConvertAsync_WithTypeMapping_ShouldMapTypes() { var sourceCode = @" using System.Collections.Generic; namespace TestApp { public class DataStore { public List Items { get; set; } public Dictionary Counts { get; set; } } }"; var syntaxTree = await _parser.ParseAsync(sourceCode); var result = await _converter.ConvertAsync(syntaxTree, LanguageType.Java); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.TransformedCode); } [Fact] public async Task ConvertAsync_WrongTargetLanguage_ShouldFail() { var sourceCode = "public class Test { }"; var syntaxTree = await _parser.ParseAsync(sourceCode); var result = await _converter.ConvertAsync(syntaxTree, LanguageType.CPlusPlus); Assert.NotNull(result); Assert.False(result.Success); Assert.NotNull(result.ErrorMessage); } [Fact] public async Task ConvertAsync_WithOptions_ShouldPreserveComments() { var sourceCode = @" namespace TestApp { /// /// This is a test class /// public class Test { // Constructor public Test() { } } }"; var syntaxTree = await _parser.ParseAsync(sourceCode); var result = await _converter.ConvertAsync( syntaxTree, LanguageType.Java, new ConversionOptions { KeepComments = true, KeepDocStrings = true }); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.TransformedCode); Assert.True(result.Report?.TodoItems.Count >= 0 || true); } }