From 6d156586acdb2c60e47a0b1c09a09d51ef636622 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Oct 2025 21:11:51 +0000 Subject: [PATCH 1/2] Initial plan From 0a3ecaac649b462602148417738a960dca22bf58 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Oct 2025 21:17:26 +0000 Subject: [PATCH 2/2] Fix Color property converter and add missing category attributes Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com> --- .../Connection/AbstractConnectionRecord.cs | 6 +- .../Connection/ConnectionInfoInheritance.cs | 2 + .../Connection/ColorPropertyAttributeTests.cs | 94 +++++++++++++++++++ .../Tools/TabColorConverterTests.cs | 18 ++++ 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 mRemoteNGTests/Connection/ColorPropertyAttributeTests.cs diff --git a/mRemoteNG/Connection/AbstractConnectionRecord.cs b/mRemoteNG/Connection/AbstractConnectionRecord.cs index c354a553..5e35d375 100644 --- a/mRemoteNG/Connection/AbstractConnectionRecord.cs +++ b/mRemoteNG/Connection/AbstractConnectionRecord.cs @@ -160,13 +160,17 @@ namespace mRemoteNG.Connection LocalizedAttributes.LocalizedDisplayName(nameof(Language.Color)), LocalizedAttributes.LocalizedDescription(nameof(Language.PropertyDescriptionColor)), Editor(typeof(System.Drawing.Design.ColorEditor), typeof(System.Drawing.Design.UITypeEditor)), - TypeConverter(typeof(System.Drawing.ColorConverter))] + TypeConverter(typeof(MiscTools.TabColorConverter))] public virtual string Color { get => GetPropertyValue("Color", _color); set => SetField(ref _color, value, "Color"); + } + + [LocalizedAttributes.LocalizedCategory(nameof(Language.Display)), LocalizedAttributes.LocalizedDisplayName(nameof(Language.TabColor)), LocalizedAttributes.LocalizedDescription(nameof(Language.PropertyDescriptionTabColor)), + Editor(typeof(System.Drawing.Design.ColorEditor), typeof(System.Drawing.Design.UITypeEditor)), TypeConverter(typeof(MiscTools.TabColorConverter))] public virtual string TabColor { diff --git a/mRemoteNG/Connection/ConnectionInfoInheritance.cs b/mRemoteNG/Connection/ConnectionInfoInheritance.cs index 1e0a2848..27853152 100644 --- a/mRemoteNG/Connection/ConnectionInfoInheritance.cs +++ b/mRemoteNG/Connection/ConnectionInfoInheritance.cs @@ -55,6 +55,8 @@ namespace mRemoteNG.Connection LocalizedAttributes.LocalizedDescriptionInherit(nameof(Language.PropertyDescriptionColor)), TypeConverter(typeof(MiscTools.YesNoTypeConverter))] public bool Color { get; set; } + + [LocalizedAttributes.LocalizedCategory(nameof(Language.Display), 2), LocalizedAttributes.LocalizedDisplayNameInherit(nameof(Language.TabColor)), LocalizedAttributes.LocalizedDescriptionInherit(nameof(Language.PropertyDescriptionTabColor)), TypeConverter(typeof(MiscTools.YesNoTypeConverter))] diff --git a/mRemoteNGTests/Connection/ColorPropertyAttributeTests.cs b/mRemoteNGTests/Connection/ColorPropertyAttributeTests.cs new file mode 100644 index 00000000..320dc202 --- /dev/null +++ b/mRemoteNGTests/Connection/ColorPropertyAttributeTests.cs @@ -0,0 +1,94 @@ +using System; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using mRemoteNG.Connection; +using mRemoteNG.Tools; +using NUnit.Framework; + +namespace mRemoteNGTests.Connection +{ + [TestFixture] + public class ColorPropertyAttributeTests + { + [Test] + public void ColorPropertyHasTabColorConverter() + { + // Get the Color property + var propertyInfo = typeof(ConnectionInfo).GetProperty("Color"); + Assert.That(propertyInfo, Is.Not.Null, "Color property should exist"); + + // Get the TypeConverter attribute + var typeConverterAttr = propertyInfo.GetCustomAttributes(typeof(TypeConverterAttribute), true) + .FirstOrDefault() as TypeConverterAttribute; + + Assert.That(typeConverterAttr, Is.Not.Null, "Color property should have TypeConverter attribute"); + Assert.That(typeConverterAttr.ConverterTypeName, Does.Contain("TabColorConverter"), + "Color property should use TabColorConverter"); + } + + [Test] + public void TabColorPropertyHasTabColorConverter() + { + // Get the TabColor property + var propertyInfo = typeof(ConnectionInfo).GetProperty("TabColor"); + Assert.That(propertyInfo, Is.Not.Null, "TabColor property should exist"); + + // Get the TypeConverter attribute + var typeConverterAttr = propertyInfo.GetCustomAttributes(typeof(TypeConverterAttribute), true) + .FirstOrDefault() as TypeConverterAttribute; + + Assert.That(typeConverterAttr, Is.Not.Null, "TabColor property should have TypeConverter attribute"); + Assert.That(typeConverterAttr.ConverterTypeName, Does.Contain("TabColorConverter"), + "TabColor property should use TabColorConverter"); + } + + [Test] + public void ColorPropertyHasCategoryAttribute() + { + var propertyInfo = typeof(ConnectionInfo).GetProperty("Color"); + Assert.That(propertyInfo, Is.Not.Null); + + var categoryAttr = propertyInfo.GetCustomAttributes(typeof(CategoryAttribute), true) + .FirstOrDefault() as CategoryAttribute; + + Assert.That(categoryAttr, Is.Not.Null, "Color property should have Category attribute"); + } + + [Test] + public void TabColorPropertyHasCategoryAttribute() + { + var propertyInfo = typeof(ConnectionInfo).GetProperty("TabColor"); + Assert.That(propertyInfo, Is.Not.Null); + + var categoryAttr = propertyInfo.GetCustomAttributes(typeof(CategoryAttribute), true) + .FirstOrDefault() as CategoryAttribute; + + Assert.That(categoryAttr, Is.Not.Null, "TabColor property should have Category attribute"); + } + + [Test] + public void ColorInheritancePropertyHasCategoryAttribute() + { + var propertyInfo = typeof(ConnectionInfoInheritance).GetProperty("Color"); + Assert.That(propertyInfo, Is.Not.Null); + + var categoryAttr = propertyInfo.GetCustomAttributes(typeof(CategoryAttribute), true) + .FirstOrDefault() as CategoryAttribute; + + Assert.That(categoryAttr, Is.Not.Null, "Color inheritance property should have Category attribute"); + } + + [Test] + public void TabColorInheritancePropertyHasCategoryAttribute() + { + var propertyInfo = typeof(ConnectionInfoInheritance).GetProperty("TabColor"); + Assert.That(propertyInfo, Is.Not.Null); + + var categoryAttr = propertyInfo.GetCustomAttributes(typeof(CategoryAttribute), true) + .FirstOrDefault() as CategoryAttribute; + + Assert.That(categoryAttr, Is.Not.Null, "TabColor inheritance property should have Category attribute"); + } + } +} diff --git a/mRemoteNGTests/Tools/TabColorConverterTests.cs b/mRemoteNGTests/Tools/TabColorConverterTests.cs index 36c089d5..40a1ecec 100644 --- a/mRemoteNGTests/Tools/TabColorConverterTests.cs +++ b/mRemoteNGTests/Tools/TabColorConverterTests.cs @@ -144,5 +144,23 @@ namespace mRemoteNGTests.Tools var result = _converter.GetStandardValuesExclusive(null); Assert.That(result, Is.False); } + + [Test] + public void ConvertFromColorObjectDoesNotThrowException() + { + // This test verifies the fix for the "Object of type 'System.Drawing.Color' cannot be converted to type 'System.String'" error + var color = Color.FromArgb(255, 100, 150, 200); + Assert.DoesNotThrow(() => _converter.ConvertFrom(color)); + } + + [Test] + public void ColorPropertyUsesTabColorConverter() + { + // This test verifies that the Color property can properly handle Color objects + // by using TabColorConverter instead of System.Drawing.ColorConverter + var color = Color.Blue; + var result = _converter.ConvertFrom(color); + Assert.That(result, Is.EqualTo("Blue")); + } } }