using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Catel.Test.Helpers
{
[TestClass]
public class TypeHelperTest
{
#region Test classes
private class PropertyInfoTestClass
{
private bool PrivateProperty { get; set; }
public bool PublicProperty { get; set; }
}
#endregion
#region FormatType
[TestMethod]
public void FormatType()
{
string expectedValue = "Catel.Test.Helpers.TypeHelperTest, Catel.Test";
string actualValue = TypeHelper.FormatType("Catel.Test", "Catel.Test.Helpers.TypeHelperTest");
Assert.AreEqual(expectedValue, actualValue);
}
#endregion
#region FormatInnerTypes
[TestMethod]
public void FormatInnerTypes()
{
string expectedValue = "[string],[string],[int]";
string actualValue = TypeHelper.FormatInnerTypes(new string[] {"string", "string", "int"});
Assert.AreEqual(expectedValue, actualValue);
}
#endregion
#region IsTypeNullable
[TestMethod]
public void IsTypeNullableWithNullableType()
{
Assert.IsTrue(TypeHelper.IsTypeNullable(typeof(object)));
}
[TestMethod]
public void IsTypeNullableWithValueType()
{
Assert.IsFalse(TypeHelper.IsTypeNullable(typeof(int)));
}
[TestMethod]
public void IsTypeNullableWithNullValue()
{
Assert.IsFalse(TypeHelper.IsTypeNullable(null));
}
[TestMethod]
public void IsTypeNullableWithNullableValueType()
{
Assert.IsTrue(TypeHelper.IsTypeNullable(typeof(bool?)));
}
#endregion
#region AreObjectsEqual
[TestMethod]
public void AreObjectsEqualWithBoxedEqualIntegers()
{
object obj1 = 5;
object obj2 = 5;
Assert.IsTrue(TypeHelper.AreObjectsEqual(obj1, obj2));
Assert.IsTrue(TypeHelper.AreObjectsEqual(obj2, obj1));
}
[TestMethod]
public void AreObjectsEqualWithBoxedUnequalIntegers()
{
object obj1 = 5;
object obj2 = 6;
Assert.IsFalse(TypeHelper.AreObjectsEqual(obj1, obj2));
Assert.IsFalse(TypeHelper.AreObjectsEqual(obj2, obj1));
}
[TestMethod]
public void AreObjectsEqualWithTwoNullValues()
{
object obj1 = null;
object obj2 = null;
Assert.IsTrue(TypeHelper.AreObjectsEqual(obj1, obj2));
Assert.IsTrue(TypeHelper.AreObjectsEqual(obj2, obj1));
}
[TestMethod]
public void AreObjectsEqualWithOneNullValue()
{
object obj1 = 5;
object obj2 = null;
Assert.IsFalse(TypeHelper.AreObjectsEqual(obj1, obj2));
Assert.IsFalse(TypeHelper.AreObjectsEqual(obj2, obj1));
}
#endregion
#region GetPropertyInfo
[TestMethod]
public void GetPropertyInfoForExistingPublicProperty()
{
Assert.IsNotNull(TypeHelper.GetPropertyInfo(typeof(PropertyInfoTestClass), "PublicProperty"));
}
[TestMethod]
public void GetPropertyInfoForExistingPrivateProperty()
{
Assert.IsNotNull(TypeHelper.GetPropertyInfo(typeof(PropertyInfoTestClass), "PrivateProperty"));
}
[TestMethod]
public void GetPropertyInfoForNonExistingProperty()
{
Assert.IsNull(TypeHelper.GetPropertyInfo(typeof(PropertyInfoTestClass), "NonExistingProperty"));
}
#endregion
#region SizeOf
// TODO: Write unit tests
#endregion
#region ReflectiveSizeOf
// TODO: Write unit tests
#endregion
#region TryCast
// TODO: Write unit tests
#endregion
#region Cast
// TODO: Write unit tests
#endregion
#region PropertyGet
// TODO: Write unit tests
#endregion
#region GetPropertyValue
// TODO: Write unit tests
#endregion
#region GetField
// TODO: Write unit tests
#endregion
#region SetField
// TODO: Write unit tests
#endregion
#region GetMemberValue
// TODO: Write unit tests
#endregion
#region CombineHash
// TODO: Write unit tests
#endregion
#region ClearAllEvents
// TODO: Write unit tests
#endregion
#region ClearEvent
// TODO: Write unit tests
#endregion
}
}