Exemple #1
0
        private void RunStringTest()
        {
            // If it is a String Test then load the string.
            string            xamlString = XamlString;
            XamlStringParser  loader     = StringParserDelegate;
            PostTreeValidator validator  = TreeValidatorDelegate;

            if (ExpectedExceptionType == null)
            {
                LoadAndValidate(loader, xamlString, validator);
            }
            // otherwise some sort of exception is expected
            else
            {
                try
                {
                    LoadAndValidate(loader, xamlString, validator);
                }
                catch (Exception e)
                {
                    if (ExpectedExceptionType == e.GetType())
                    {
                        if ((ExpectedInnerExceptionType == null && e.InnerException == null) || (ExpectedInnerExceptionType == e.InnerException.GetType()))
                        {
                            return;
                        }
                    }
                    throw new InvalidOperationException("Wrong Exception was thrown", e);
                }
                throw new InvalidOperationException(String.Format("Expected exception {0} was not thrown", ExpectedExceptionType.ToString()));
            }
        }
Exemple #2
0
        public static DrtTest DRT_MakeTest(XamlTestSuite suiteInstance, XamlTestInfoBlock testBlk)
        {
            DrtTest drtTest = null;
            string  name    = testBlk.Name;

            if (testBlk.TestDelegate != null)
            {
                SimpleTest test = testBlk.TestDelegate;

                drtTest = new DrtTest(() => suiteInstance.DRT_TestValidator(
                                          test,
                                          testBlk.ExpectedExceptionType));
            }
            else
            {
                string            xamlString = testBlk.XamlString;
                XamlStringParser  loader     = testBlk.StringParserDelegate;
                PostTreeValidator validator  = testBlk.TreeValidatorDelegate;
                Type expectedExceptionType   = testBlk.ExpectedExceptionType;

                drtTest = new DrtTest(() => suiteInstance.DRT_XamlLoader(
                                          name,
                                          xamlString,
                                          loader,
                                          expectedExceptionType,
                                          validator));
            }
            return(drtTest);
        }
Exemple #3
0
 public XamlTestInfoBlock(string name, string xaml, XamlStringParser loader, PostTreeValidator validator, Type expectedExceptionType, Type expectedInnerExceptionType)
 {
     _name                       = name;
     _xaml                       = xaml;
     _loader                     = loader;
     _validator                  = validator;
     _expectedExceptionType      = expectedExceptionType;
     _expectedInnerExceptionType = expectedInnerExceptionType;
 }
Exemple #4
0
        private void LoadAndValidate(XamlStringParser loader, string xamlString, PostTreeValidator validator)
        {
            object root = loader(xamlString);

            if (validator != null)
            {
                validator(root);
            }
        }
Exemple #5
0
        public static IEnumerable <XamlTestInfoBlock> TestStrings(object suiteInstance, bool excludeKnownFailures)
        {
            Type testClass = suiteInstance.GetType();

            foreach (FieldInfo field in testClass.GetFields(fieldBF))
            {
                if (IsTestXamlString(field))
                {
                    var testKnownFailureAttr = GetTestKnownFailureAttribute(field);

                    if (excludeKnownFailures && testKnownFailureAttr != null)
                    {
                        Console.WriteLine($"Excluding known failure: XamlString:{field.Name} Owner:{testKnownFailureAttr.Reason}");
                        continue;  // Exclude Known Failures
                    }
                    string            xamlString = field.GetValue(suiteInstance) as string;
                    MethodInfo        loadMethod, validateMethod;
                    XamlStringParser  loader    = null;
                    PostTreeValidator validator = null;
                    Type expectedExceptionType;

                    if (!HasAlternateXamlLoader(field, out loadMethod))
                    {
                        loadMethod = TestFinder.StandardXamlLoadMethod(suiteInstance);
                    }
                    loader = Delegate.CreateDelegate(typeof(XamlStringParser),
                                                     suiteInstance, loadMethod, true) as XamlStringParser;

                    if (HasTreeValidator(field, out validateMethod))
                    {
                        validator = Delegate.CreateDelegate(typeof(PostTreeValidator),
                                                            suiteInstance, validateMethod, true) as PostTreeValidator;
                    }

                    expectedExceptionType = GetExpectedException(field);

                    string name = String.Format("{0}.{1}", testClass.Name, field.Name);

                    var testBlock = new XamlTestInfoBlock(name, xamlString, loader, validator, expectedExceptionType);
                    if (testKnownFailureAttr != null)
                    {
                        testBlock.IsTestKnownFailure = true;
                        testBlock.OwnerName          = testKnownFailureAttr.Reason;
                    }
                    yield return(testBlock);
                }
            }
        }
Exemple #6
0
        public object DRT_XamlLoader(string name, string xamlString,
                                     XamlStringParser loader,
                                     Type expectedExceptionType,
                                     PostTreeValidator validator)
        {
            object root = null;
            bool   hasExpectedException = (expectedExceptionType != null);

            try
            {
                root = loader(xamlString);
            }
            catch (Exception ex)
            {
                if (expectedExceptionType != null && expectedExceptionType == ex.GetType())
                {
                    hasExpectedException = false;
                }
                else
                {
                    // otherwise we got the unexpected exception;
                    DRT.Assert(false, "XAML Test '{0}' failed.{1}", name, ex.ToString());
                    return(null);
                }
            }

            if (hasExpectedException)
            {
                DRT.Assert(false, "XAAML Test '{0}' did not throw expected exception of type '{1}'.", name, expectedExceptionType);
            }

            if (validator != null)
            {
                try
                {
                    validator(root);
                }
                catch (Exception ex)
                {
                    DRT.Assert(false, "XAML Test String '{0}' failed post validation.{1}", name, ex.ToString());
                }
            }
            return(root);
        }
Exemple #7
0
 public XamlTestInfoBlock(string name, string xaml, XamlStringParser loader, PostTreeValidator validator) :
     this(name, xaml, loader, validator, null)
 {
 }
Exemple #8
0
 public XamlTestInfoBlock(string name, string xaml, XamlStringParser loader, PostTreeValidator validator, Type expectedExceptionType)
     : this(name, xaml, loader, validator, expectedExceptionType, null)
 {
 }