mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Fix Color property converter and add missing category attributes
Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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))]
|
||||
|
||||
94
mRemoteNGTests/Connection/ColorPropertyAttributeTests.cs
Normal file
94
mRemoteNGTests/Connection/ColorPropertyAttributeTests.cs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user