mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-23 00:38:47 +00:00
✅ Add ReflectionTests
This commit is contained in:
parent
1ccb8b2457
commit
a591b91c6c
70
X10D.Tests/src/ReflectionTests.cs
Normal file
70
X10D.Tests/src/ReflectionTests.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
namespace X10D.Tests
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for <see cref="ReflectionExtensions"/>.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class ReflectionTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Test for <see cref="ReflectionExtensions.GetDefaultValue{T}(System.Reflection.MemberInfo)"/>.
|
||||||
|
/// </summary>
|
||||||
|
[TestMethod]
|
||||||
|
public void GetDefaultValue()
|
||||||
|
{
|
||||||
|
var klass = new TestClass();
|
||||||
|
|
||||||
|
foreach (var property in klass.GetType().GetProperties())
|
||||||
|
{
|
||||||
|
Assert.AreEqual("Foo", property.GetDefaultValue<string>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test for <see cref="ReflectionExtensions.GetDescription(System.Reflection.MemberInfo)"/>.
|
||||||
|
/// </summary>
|
||||||
|
[TestMethod]
|
||||||
|
public void GetDescription()
|
||||||
|
{
|
||||||
|
var klass = new TestClass();
|
||||||
|
|
||||||
|
foreach (var property in klass.GetType().GetProperties())
|
||||||
|
{
|
||||||
|
Assert.AreEqual("Test description", property.GetDescription());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test for <see cref="ReflectionExtensions.GetDescription(System.Reflection.MemberInfo)"/>.
|
||||||
|
/// </summary>
|
||||||
|
[TestMethod]
|
||||||
|
public void SelectFromCustomAttribute()
|
||||||
|
{
|
||||||
|
var klass = new TestClass();
|
||||||
|
|
||||||
|
foreach (var property in klass.GetType().GetProperties())
|
||||||
|
{
|
||||||
|
var value = property.SelectFromCustomAttribute<TestAttribute, string>(a => a.TestValue);
|
||||||
|
Assert.AreEqual("Bar", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Property)]
|
||||||
|
private sealed class TestAttribute : Attribute
|
||||||
|
{
|
||||||
|
public string TestValue { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class TestClass
|
||||||
|
{
|
||||||
|
[System.ComponentModel.Description("Test description")]
|
||||||
|
[DefaultValue("Foo")]
|
||||||
|
[Test(TestValue = "Bar")]
|
||||||
|
public string TestProperty { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user