11using NUnit . Framework ;
22using System ;
3- using System . Collections . Generic ;
43using System . Linq ;
5- using System . Text ;
6- using System . Threading . Tasks ;
7- using Mono . Documentation . Util ;
84using Windows . UI . Xaml ;
5+ using Mono . Documentation . Util ;
96using Mono . Documentation . Updater ;
107using Mono . Documentation . Updater . Formatters ;
118
@@ -26,7 +23,7 @@ public void Test_NoEntities()
2623 [ TestCase ]
2724 public void Test_AttachedProperty ( )
2825 {
29- var type = GetTypeDef < AttachedTestClass > ( ) ;
26+ var type = GetTypeDef < AttachedPropertyTestClass > ( ) ;
3027 var list = AttachedEntitiesHelper . GetAttachedEntities ( type ) ;
3128
3229 Assert . AreEqual ( 3 , list . Count ( ) ) ;
@@ -37,7 +34,7 @@ public void Test_AttachedProperty_Formatter()
3734 {
3835 string expected = "see GetSome, and SetSome" ;
3936
40- var type = GetTypeDef < AttachedTestClass > ( ) ;
37+ var type = GetTypeDef < AttachedPropertyTestClass > ( ) ;
4138 var list = AttachedEntitiesHelper . GetAttachedEntities ( type ) ;
4239
4340 MemberFormatter formatter = new CSharpMemberFormatter ( ) ;
@@ -50,7 +47,7 @@ public void Test_AttachedProperty_Formatter_GetOnly()
5047 {
5148 string expected = "see GetSomeGet" ;
5249
53- var type = GetTypeDef < AttachedTestClass > ( ) ;
50+ var type = GetTypeDef < AttachedPropertyTestClass > ( ) ;
5451 var list = AttachedEntitiesHelper . GetAttachedEntities ( type ) ;
5552
5653 MemberFormatter formatter = new CSharpMemberFormatter ( ) ;
@@ -63,7 +60,7 @@ public void Test_AttachedProperty_Formatter_SetOnly()
6360 {
6461 string expected = "see SetSomeSet" ;
6562
66- var type = GetTypeDef < AttachedTestClass > ( ) ;
63+ var type = GetTypeDef < AttachedPropertyTestClass > ( ) ;
6764 var list = AttachedEntitiesHelper . GetAttachedEntities ( type ) ;
6865
6966 MemberFormatter formatter = new CSharpMemberFormatter ( ) ;
@@ -72,17 +69,56 @@ public void Test_AttachedProperty_Formatter_SetOnly()
7269 }
7370
7471 [ TestCase ]
75- public void Test_AttachedProperty_Property ( )
72+ public void Test_AttachedEntities ( )
7673 {
77- var type = GetTypeDef < AttachedPropertyTestClass > ( ) ;
78- Assert . AreEqual ( 1 , type . Properties . Count ( t => t . Name == "AttributeAttachProperty" ) ) ;
74+ var type = GetTypeDef < AttachedEntitiesTestClass > ( ) ;
75+ Assert . IsTrue ( type . Fields . Any ( t => t . Name == "TestingEvent" ) ) ;
76+ Assert . IsTrue ( type . Fields . Any ( t => t . Name == "TargetProperty" ) ) ;
77+ Assert . IsTrue ( type . Fields . Any ( t => t . Name == "TargetPropertyProperty" ) ) ;
78+ Assert . IsTrue ( type . Properties . Any ( t => t . Name == "AttributeAttachProperty" ) ) ;
79+
80+ var list = AttachedEntitiesHelper . GetAttachedEntities ( type ) ;
81+ Assert . AreEqual ( 4 , list . Count ( ) ) ;
82+ Assert . IsTrue ( list . Any ( t => t . Name == "Testing" && t is AttachedEventReference ) ) ;
83+ Assert . IsTrue ( list . Any ( t => t . Name == "Target" && t is AttachedPropertyReference ) ) ;
84+ Assert . IsTrue ( list . Any ( t => t . Name == "TargetProperty" && t is AttachedPropertyReference ) ) ;
85+ Assert . IsTrue ( list . Any ( t => t . Name == "AttributeAttach" && t is AttachedPropertyReference ) ) ;
86+ }
87+
88+ [ TestCase ( IncludePlatform = "Win32NT" ) ]
89+ public void Test_AttachedEntities_NetFramework ( )
90+ {
91+ var os = Environment . OSVersion ;
92+ Console . WriteLine ( "OS platform is: {0}" , os . Platform . ToString ( ) ) ;
93+
94+ var type = GetTypeDef < System . Windows . Media . Animation . Storyboard > ( ) ;
7995 var list = AttachedEntitiesHelper . GetAttachedEntities ( type ) ;
80- Assert . AreEqual ( "AttributeAttach" , list . FirstOrDefault ( t => t . Name == "AttributeAttach" ) . Name ) ;
96+ Assert . AreEqual ( 3 , list . Count ( ) ) ;
97+ Assert . IsTrue ( type . Fields . Any ( t => t . Name == "TargetProperty" ) ) ;
98+ Assert . IsTrue ( type . Fields . Any ( t => t . Name == "TargetPropertyProperty" ) ) ;
99+ Assert . IsTrue ( list . Any ( t => t . Name == "Target" && t is AttachedPropertyReference ) ) ;
100+ Assert . IsTrue ( list . Any ( t => t . Name == "TargetProperty" && t is AttachedPropertyReference ) ) ;
101+
102+ type = GetTypeDef < System . Windows . Controls . Primitives . Selector > ( ) ;
103+ list = AttachedEntitiesHelper . GetAttachedEntities ( type ) ;
104+ Assert . AreEqual ( 4 , list . Count ( ) ) ;
105+ Assert . IsTrue ( list . Any ( t => t . Name == "IsSelected" && t is AttachedPropertyReference ) ) ;
106+ Assert . IsTrue ( list . Any ( t => t . Name == "IsSelectionActive" && t is AttachedPropertyReference ) ) ;
107+ Assert . IsTrue ( list . Any ( t => t . Name == "Selected" && t is AttachedEventReference ) ) ;
108+ Assert . IsTrue ( list . Any ( t => t . Name == "Unselected" && t is AttachedEventReference ) ) ;
109+
110+ type = GetTypeDef < Windows . UI . Xaml . Media . Animation . Storyboard > ( ) ;
111+ list = AttachedEntitiesHelper . GetAttachedEntities ( type ) ;
112+ Assert . AreEqual ( 2 , list . Count ( ) ) ;
113+ Assert . IsTrue ( type . Properties . Any ( t => t . Name == "TargetNameProperty" ) ) ;
114+ Assert . IsTrue ( type . Properties . Any ( t => t . Name == "TargetPropertyProperty" ) ) ;
115+ Assert . IsTrue ( list . Any ( t => t . Name == "TargetName" && t is AttachedPropertyReference ) ) ;
116+ Assert . IsTrue ( list . Any ( t => t . Name == "TargetProperty" && t is AttachedPropertyReference ) ) ;
81117 }
82118
83119 public class AttachedTestClassNoAttachedEntities { }
84120
85- public class AttachedTestClass
121+ public class AttachedPropertyTestClass
86122 {
87123 public static readonly DependencyProperty SomeProperty ;
88124 public static bool GetSome ( DependencyObject obj ) { return false ; }
@@ -102,11 +138,32 @@ public static void SetSomeSet(DependencyObject obj, bool val) { }
102138 public static void SetSomeNotReadOnly ( DependencyObject obj , bool val ) { }
103139 }
104140
105- public class AttachedPropertyTestClass
141+ public class AttachedEntitiesTestClass
106142 {
107143 public DependencyProperty AttributeAttachProperty { get ; set ; }
108144 public static bool GetAttributeAttach ( DependencyObject obj ) { return false ; }
109145 public static void SetAttributeAttach ( DependencyObject obj , bool val ) { }
146+
147+ public static readonly DependencyProperty TargetProperty ;
148+ public static bool GetTarget ( DependencyObject obj ) { return false ; }
149+ public static void SetTarget ( DependencyObject obj , bool val ) { }
150+
151+ public delegate void EventHandler ( object sender , EventArgs e ) ;
152+ public static readonly RoutedEvent TestingEvent ;
153+ public static void AddTestingHandler ( DependencyObject element , EventHandler handler ) { }
154+ public static void RemoveTestingHandler ( DependencyObject element , EventHandler handler ) { }
155+
156+ public static readonly DependencyProperty TargetPropertyProperty ;
157+ public static string GetTargetProperty ( DependencyObject obj )
158+ {
159+ if ( obj == null ) { throw new ArgumentNullException ( "obj" ) ; }
160+ return ( string ) obj . GetValue ( TargetPropertyProperty ) ;
161+ }
162+ public static void SetTargetProperty ( DependencyObject obj , string val )
163+ {
164+ if ( obj == null ) { throw new ArgumentNullException ( "obj" ) ; }
165+ obj . SetValue ( TargetPropertyProperty , val ) ;
166+ }
110167 }
111168 }
112169}
0 commit comments