From a591b91c6c6d0ed0feddd851ca11452cb848128a Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 21 Apr 2020 04:17:19 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20ReflectionTests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- X10D.Tests/src/ReflectionTests.cs | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 X10D.Tests/src/ReflectionTests.cs diff --git a/X10D.Tests/src/ReflectionTests.cs b/X10D.Tests/src/ReflectionTests.cs new file mode 100644 index 0000000..da95110 --- /dev/null +++ b/X10D.Tests/src/ReflectionTests.cs @@ -0,0 +1,70 @@ +namespace X10D.Tests +{ + using System; + using System.ComponentModel; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests for . + /// + [TestClass] + public class ReflectionTests + { + /// + /// Test for . + /// + [TestMethod] + public void GetDefaultValue() + { + var klass = new TestClass(); + + foreach (var property in klass.GetType().GetProperties()) + { + Assert.AreEqual("Foo", property.GetDefaultValue()); + } + } + + /// + /// Test for . + /// + [TestMethod] + public void GetDescription() + { + var klass = new TestClass(); + + foreach (var property in klass.GetType().GetProperties()) + { + Assert.AreEqual("Test description", property.GetDescription()); + } + } + + /// + /// Test for . + /// + [TestMethod] + public void SelectFromCustomAttribute() + { + var klass = new TestClass(); + + foreach (var property in klass.GetType().GetProperties()) + { + var value = property.SelectFromCustomAttribute(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; } + } + } +}