Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AttachedEntityTests.cs « Enumeration « mdoc.Test « mdoc - github.com/mono/api-doc-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 271aa81baa2d1e5c8748be10ebe457f6f930a8d8 (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using NUnit.Framework;
using System;
using System.Linq;
using Windows.UI.Xaml;
using Mono.Documentation.Util;
using Mono.Documentation.Updater;
using Mono.Documentation.Updater.Formatters;

namespace mdoc.Test.Enumeration
{
    [TestFixture]
    public class AttachedEntityTests : CecilBaseTest
    {
        [TestCase]
        public void Test_NoEntities()
        {
            var type = GetTypeDef<AttachedTestClassNoAttachedEntities>();
            var list = AttachedEntitiesHelper.GetAttachedEntities(type);

            Assert.IsFalse(list.Any());
        }

        [TestCase]
        public void Test_AttachedProperty()
        {
            var type = GetTypeDef<AttachedPropertyTestClass>();
            var list = AttachedEntitiesHelper.GetAttachedEntities(type);

            Assert.AreEqual(3, list.Count());
        }

        [TestCase]
        public void Test_AttachedProperty_Formatter()
        {
            string expected = "see GetSome, and SetSome";

            var type = GetTypeDef<AttachedPropertyTestClass>();
            var list = AttachedEntitiesHelper.GetAttachedEntities(type);

            MemberFormatter formatter = new CSharpMemberFormatter();
            string def = formatter.GetDeclaration(list.First());
            Assert.AreEqual(expected, def);
        }

        [TestCase]
        public void Test_AttachedProperty_Formatter_GetOnly()
        {
            string expected = "see GetSomeGet";

            var type = GetTypeDef<AttachedPropertyTestClass>();
            var list = AttachedEntitiesHelper.GetAttachedEntities(type);

            MemberFormatter formatter = new CSharpMemberFormatter();
            string def = formatter.GetDeclaration(list.Skip(1).First());
            Assert.AreEqual(expected, def);
        }

        [TestCase]
        public void Test_AttachedProperty_Formatter_SetOnly()
        {
            string expected = "see SetSomeSet";

            var type = GetTypeDef<AttachedPropertyTestClass>();
            var list = AttachedEntitiesHelper.GetAttachedEntities(type);

            MemberFormatter formatter = new CSharpMemberFormatter();
            string def = formatter.GetDeclaration(list.Skip(2).First());
            Assert.AreEqual(expected, def);
        }

        [TestCase]
        public void Test_AttachedEntities()
        {
            var type = GetTypeDef<AttachedEntitiesTestClass>();
            Assert.IsTrue(type.Fields.Any(t => t.Name == "TestingEvent"));
            Assert.IsTrue(type.Fields.Any(t => t.Name == "TargetProperty"));
            Assert.IsTrue(type.Fields.Any(t => t.Name == "TargetPropertyProperty"));
            Assert.IsTrue(type.Properties.Any(t => t.Name == "AttributeAttachProperty"));

            var list = AttachedEntitiesHelper.GetAttachedEntities(type);
            Assert.AreEqual(4, list.Count());
            Assert.IsTrue(list.Any(t => t.Name == "Testing" && t is AttachedEventReference));
            Assert.IsTrue(list.Any(t => t.Name == "Target" && t is AttachedPropertyReference));
            Assert.IsTrue(list.Any(t => t.Name == "TargetProperty" && t is AttachedPropertyReference));
            Assert.IsTrue(list.Any(t => t.Name == "AttributeAttach" && t is AttachedPropertyReference));
        }

        [TestCase(IncludePlatform = "Win32NT")]
        public void Test_AttachedEntities_NetFramework()
        {
            var os = Environment.OSVersion;
            Console.WriteLine("OS platform is: {0}", os.Platform.ToString());

            var type = GetTypeDef<System.Windows.Media.Animation.Storyboard>();
            var list = AttachedEntitiesHelper.GetAttachedEntities(type);
            Assert.AreEqual(3, list.Count());
            Assert.IsTrue(type.Fields.Any(t => t.Name == "TargetProperty"));
            Assert.IsTrue(type.Fields.Any(t => t.Name == "TargetPropertyProperty"));
            Assert.IsTrue(list.Any(t => t.Name == "Target" && t is AttachedPropertyReference));
            Assert.IsTrue(list.Any(t => t.Name == "TargetProperty" && t is AttachedPropertyReference));

            type = GetTypeDef<System.Windows.Controls.Primitives.Selector>();
            list = AttachedEntitiesHelper.GetAttachedEntities(type);
            Assert.AreEqual(4, list.Count());
            Assert.IsTrue(list.Any(t => t.Name == "IsSelected" && t is AttachedPropertyReference));
            Assert.IsTrue(list.Any(t => t.Name == "IsSelectionActive" && t is AttachedPropertyReference));
            Assert.IsTrue(list.Any(t => t.Name == "Selected" && t is AttachedEventReference));
            Assert.IsTrue(list.Any(t => t.Name == "Unselected" && t is AttachedEventReference));

            type = GetTypeDef<Windows.UI.Xaml.Media.Animation.Storyboard>();
            list = AttachedEntitiesHelper.GetAttachedEntities(type);
            Assert.AreEqual(2, list.Count());
            Assert.IsTrue(type.Properties.Any(t => t.Name == "TargetNameProperty"));
            Assert.IsTrue(type.Properties.Any(t => t.Name == "TargetPropertyProperty"));
            Assert.IsTrue(list.Any(t => t.Name == "TargetName" && t is AttachedPropertyReference));
            Assert.IsTrue(list.Any(t => t.Name == "TargetProperty" && t is AttachedPropertyReference));
        }

        public class AttachedTestClassNoAttachedEntities { }

        public class AttachedPropertyTestClass
        {
            public static readonly DependencyProperty SomeProperty;
            public static bool GetSome(DependencyObject obj) { return false;  }
            public static void SetSome(DependencyObject obj, bool val) { }


            public static readonly DependencyProperty SomeGetProperty;
            public static bool GetSomeGet(DependencyObject obj) { return false; }


            public static readonly DependencyProperty SomeSetProperty;
            public static void SetSomeSet(DependencyObject obj, bool val) { }


            public static DependencyProperty SomeNotReadonlyProperty;
            public static bool GetSomeNotReadOnly(DependencyObject obj) { return false; }
            public static void SetSomeNotReadOnly(DependencyObject obj, bool val) { }
        }

        public class AttachedEntitiesTestClass
        {
            public DependencyProperty AttributeAttachProperty { get; set; }
            public static bool GetAttributeAttach(DependencyObject obj) { return false; }
            public static void SetAttributeAttach(DependencyObject obj, bool val) { }

            public static readonly DependencyProperty TargetProperty;
            public static bool GetTarget(DependencyObject obj) { return false; }
            public static void SetTarget(DependencyObject obj, bool val) { }

            public delegate void EventHandler(object sender, EventArgs e);
            public static readonly RoutedEvent TestingEvent;
            public static void AddTestingHandler(DependencyObject element, EventHandler handler) { }
            public static void RemoveTestingHandler(DependencyObject element, EventHandler handler) { }

            public static readonly DependencyProperty TargetPropertyProperty;
            public static string GetTargetProperty(DependencyObject obj)
            {
                if (obj == null) { throw new ArgumentNullException("obj"); }
                return (string)obj.GetValue(TargetPropertyProperty);
            }
            public static void SetTargetProperty(DependencyObject obj, string val)
            {
                if (obj == null) { throw new ArgumentNullException("obj"); }
                obj.SetValue(TargetPropertyProperty, val);
            }
        }
    }
}