public void TargetArgumentSemanticAttribute() { var failingTypes = new Dictionary <Type, string> (); // Get our binding assembly var xamMac = typeof(NSObject).Assembly; foreach (Type t in xamMac.GetTypes().Where(t => !t.IsAbstract)) { // Check availability attributes. if (Asserts.SkipDueToAvailabilityAttribute(t)) { continue; } PropertyInfo target = t.GetMostDerivedProperty("Target"); if (target != null && target.PropertyType == typeof(NSObject)) { MethodInfo[] accessors = target.GetAccessors(); foreach (var accessor in accessors) { var attr = accessor.GetCustomAttributes <ExportAttribute> ().FirstOrDefault(a => a.Selector == "target"); if (attr == null) { continue; } if (attr.ArgumentSemantic == ArgumentSemantic.None) { failingTypes.Add(t, "Target has no ArgumentSemantic set"); break; } } } } if (failingTypes.Count > 0) { Console.WriteLine("{0} failing types:", failingTypes.Count); foreach (var kvp in failingTypes) { Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value); } Assert.Fail("{0} failing types", failingTypes.Count); } }
public void DelegateAndDataSourceAllowsNull() { var failingTypes = new Dictionary <Type, string> (); // Get our binding assembly var xamMac = typeof(NSObject).Assembly; // Walk all non abstract types, looking for things with zero param constructors foreach (Type t in xamMac.GetTypes().Where(t => !t.IsAbstract)) { // Check availability attributes. if (Asserts.SkipDueToAvailabilityAttribute(t) || Skip(t)) { continue; } var ctor = t.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new Type[0], null); if (Asserts.SkipDueToAvailabilityAttribute(ctor)) { continue; } // If they have one of the properites we are testing if (ctor != null) { PropertyInfo weakDelegate = t.GetMostDerivedProperty("WeakDelegate"); PropertyInfo del = t.GetMostDerivedProperty("Delegate"); PropertyInfo weakDataSource = t.GetMostDerivedProperty("WeakDataSource"); PropertyInfo dataSource = t.GetMostDerivedProperty("DataSource"); if (isValidToTest(weakDelegate) || isValidToTest(del) || isValidToTest(weakDataSource) || isValidToTest(dataSource)) { try { // Create an instance and try to set null using (var instance = (IDisposable)ctor.Invoke(null)) { if (isValidToTest(weakDelegate)) { weakDelegate.SetValue(instance, null, null); } if (isValidToTest(del)) { del.SetValue(instance, null, null); } if (isValidToTest(weakDataSource)) { weakDataSource.SetValue(instance, null, null); } if (isValidToTest(dataSource)) { dataSource.SetValue(instance, null, null); } } } catch (TargetInvocationException e) { failingTypes.Add(t, e.InnerException.Message); } catch (Exception e) { Assert.Fail("Unexpected exception {0} while testing {1}", e, t); } } } } GC.Collect(2); // Flush out random failures. Some classes only act badly when disposed if (failingTypes.Count > 0) { Console.WriteLine("{0} failing types:", failingTypes.Count); foreach (var kvp in failingTypes) { Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value); } Assert.Fail("{0} failing types", failingTypes.Count); } }
bool isValidToTest(PropertyInfo p) { return(p != null && p.CanWrite && !Asserts.SkipDueToAvailabilityAttribute(p)); }
public void DelegateAndDataSourceHaveArgumentSemanticAttribute() { var failingTypes = new Dictionary <Type, string> (); // Get our binding assembly var xamMac = typeof(NSObject).Assembly; foreach (Type t in xamMac.GetTypes().Where(t => !t.IsAbstract)) { // Check availability attributes. if (Asserts.SkipDueToAvailabilityAttribute(t)) { continue; } PropertyInfo weakDelegate = t.GetMostDerivedProperty("WeakDelegate"); PropertyInfo del = t.GetMostDerivedProperty("Delegate"); MethodInfo[] accessors = null; if (del != null) { if (weakDelegate != null) { if (!weakDelegate.CanWrite) { continue; } accessors = weakDelegate.GetAccessors(); } else { if (!del.CanWrite) { continue; } accessors = del.GetAccessors(); } foreach (var accessor in accessors) { var attr = accessor.GetCustomAttributes <ExportAttribute> ().FirstOrDefault(a => a.Selector == "delegate"); if (attr == null) { continue; } if (attr.ArgumentSemantic == ArgumentSemantic.None) { failingTypes.Add(t, "Delegate has no ArgumentSemantic set"); break; } } } PropertyInfo weakDataSource = t.GetMostDerivedProperty("WeakDataSource"); PropertyInfo dataSource = t.GetMostDerivedProperty("DataSource"); if (dataSource != null) { accessors = null; if (weakDataSource != null) { if (!weakDataSource.CanWrite) { continue; } accessors = weakDataSource.GetAccessors(); } else { if (!dataSource.CanWrite) { continue; } accessors = dataSource.GetAccessors(); } foreach (var accessor in accessors) { var attr = accessor.GetCustomAttributes <ExportAttribute> ().FirstOrDefault(a => a.Selector == "dataSource"); if (attr == null) { continue; } if (attr.ArgumentSemantic == ArgumentSemantic.None) { failingTypes.Add(t, "Data Source has no ArgumentSemantic set"); break; } } } } if (failingTypes.Count > 0) { Console.WriteLine("{0} failing types:", failingTypes.Count); foreach (var kvp in failingTypes) { Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value); } Assert.Fail("{0} failing types", failingTypes.Count); } }