chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using NUnit.Framework;
using OpenTap.Plugins.BasicSteps;
 
namespace OpenTap.UnitTests
{
    public class ReflectionTest
    {
        public double Member1 { get; set; }
        public double Member2 { get; set; }
 
        [Test]
        public void TestDisplayAttribute()
        {
            { // dialog step
                var dialogStep = new DialogStep();
                var dialogStepType = TypeData.GetTypeData(dialogStep);
                var dialogStepDisplay = dialogStepType.GetDisplayAttribute();
                Assert.IsFalse(dialogStepDisplay.IsDefaultAttribute());
                Assert.AreEqual("Dialog", dialogStepDisplay.Name);
                Assert.AreEqual("Basic Steps", dialogStepDisplay.Group[0]);
                Assert.AreEqual(DisplayAttribute.DefaultOrder, dialogStepDisplay.Order);
            }
            { 
                var otherClass = TypeData.FromType(typeof(ReflectionTest));
                var otherClassDisplay = otherClass.GetDisplayAttribute();
                Assert.IsTrue(otherClassDisplay.IsDefaultAttribute());
                Assert.AreEqual(nameof(ReflectionTest), otherClassDisplay.Name);
                Assert.AreEqual(0, otherClassDisplay.Group.Length);
                Assert.AreEqual(DisplayAttribute.DefaultOrder, otherClassDisplay.Order);
            }
        }
 
        [Test]
        public void DisplayAttributeEqualityCheck()
        {
            var otherClass = TypeData.FromType(typeof(ReflectionTest));
            var mem1Display = otherClass.GetMember(nameof(Member1)).GetDisplayAttribute();
            var mem2Display = otherClass.GetMember(nameof(Member2)).GetDisplayAttribute();
            var mem1Display2 = otherClass.GetMember(nameof(Member1)).GetDisplayAttribute();
            Assert.AreEqual(nameof(Member1), mem1Display.Name);
            Assert.AreEqual(nameof(Member2), mem2Display.Name);
            Assert.AreNotEqual(mem1Display, mem2Display);
            Assert.AreEqual(mem1Display, mem1Display2);
        }
 
        [Test]
        public void IntTriviaTest()
        {
            // let's test some basic sanity.
            int x = 5;
            var xType = (TypeData)TypeData.GetTypeData(x);
            Assert.IsTrue(xType.IsNumeric());
            Assert.IsTrue(xType.IsValueType);
            Assert.IsTrue(xType.IsBrowsable());
            Assert.IsFalse(xType.IsString);
            Assert.IsTrue(xType.CanCreateInstance);
            Assert.AreEqual(0, xType.CreateInstance());
        }
    }
}