1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-09 23:25:43 +00:00

Add ReflectionTests

This commit is contained in:
Oliver Booth 2020-04-21 04:17:19 +01:00
parent 1ccb8b2457
commit a591b91c6c
No known key found for this signature in database
GPG Key ID: 0D7F2EF1C8D2B9C0

View 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; }
}
}
}