Ejemplo n.º 1
0
        public static void AssertHierarchyFlags(UIElement element, TypeAssert assertRoot, int depth = 0)
        {
            Assert.AreEqual(element.GetType(), assertRoot.parentType);

            switch (assertRoot.flags)
            {
            case TestEnableFlags.Disabled:
                Assert.IsTrue(element.isDisabled);
                Assert.IsFalse(element.isEnabled);
                break;

            case TestEnableFlags.DisabledSelf:
                Assert.IsTrue(element.isSelfDisabled);
                Assert.IsFalse(element.isSelfEnabled);
                break;

            case TestEnableFlags.DisabledAncestor:
                Assert.IsTrue(element.isDisabled);
                Assert.IsTrue(element.isSelfEnabled);
                Assert.IsFalse(element.isEnabled);
                break;

            case TestEnableFlags.Enabled:
                Assert.IsTrue(element.isEnabled);
                Assert.IsTrue(element.isSelfEnabled);
                Assert.IsFalse(element.isSelfDisabled);
                break;

            case TestEnableFlags.EnabledAncestor:
                break;

            case TestEnableFlags.EnabledSelf:
                Assert.IsTrue(element.isSelfEnabled);
                break;
            }

            if (element.children.Count != assertRoot.childTypes.Length)
            {
                Assert.Fail("Child Count did not match at depth: " + depth);
            }

            for (int i = 0; i < element.children.Count; i++)
            {
                if (element.children[i].GetType() != assertRoot.childTypes[i].parentType)
                {
                    Assert.Fail("Types did not match for child number " + i + " at depth " + depth);
                }

                AssertHierarchy(element.children[i], assertRoot.childTypes[i], depth + 1);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes a method and asserts that the specified exception is thrown.
        /// </summary>
        /// <typeparam name="T">The type of exception to expect.</typeparam>
        /// <param name="method">The method to execute.</param>
        /// <returns>The thrown exception.</returns>
        public static void InnerException <T>(ExceptionDelegate method)  where T : Exception
        {
            try
            {
                method.Invoke();
            }
            catch (Exception ex)
            {
                TypeAssert.AreEqual(typeof(T), ex.InnerException);

                return;
            }
            Assert.Fail("Expected exception '" + typeof(T).FullName + "' wasn't thrown.");
        }
Ejemplo n.º 3
0
        public static void AssertHierarchy(UIElement element, TypeAssert assertRoot, int depth = 0)
        {
            Assert.AreEqual(element.GetType(), assertRoot.parentType);
            if (element.children.Count != assertRoot.childTypes.Length)
            {
                Assert.Fail("Child Count did not match at depth: " + depth);
            }

            for (int i = 0; i < element.children.Count; i++)
            {
                if (element.children[i].GetType() != assertRoot.childTypes[i].parentType)
                {
                    Assert.Fail($"Types did not match for child number {i} at depth {depth}. {element.children[i].GetType()} is not {assertRoot.childTypes[i].parentType}");
                }

                AssertHierarchy(element.children[i], assertRoot.childTypes[i], depth + 1);
            }
        }