コード例 #1
0
        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);
            }
        }
コード例 #2
0
 public void SetUp()
 {
     Asserts.EnsureMavericks();
 }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 bool isValidToTest(PropertyInfo p)
 {
     return(p != null && p.CanWrite && !Asserts.SkipDueToAvailabilityAttribute(p));
 }
コード例 #5
0
        public void SetUp()
        {
            Asserts.EnsureYosemite();

            controller = new NSTabViewController();
        }
コード例 #6
0
        public void SetUp()
        {
            Asserts.EnsureYosemite();

            view = new NSVisualEffectView();
        }
コード例 #7
0
 public void Setup()
 {
     Asserts.EnsureYosemite();
 }
コード例 #8
0
        public void SetUp()
        {
            Asserts.EnsureYosemite();

            item = new NSSplitViewItem();
        }
コード例 #9
0
 public void SCNGeometrySourceSemanticTest()
 {
     Asserts.EnsureMountainLion();
     Assert.IsNotNull(SCNGeometrySourceSemantic.Color, "Color");
 }