Ejemplo n.º 1
0
            /// <exception cref="System.Exception"/>
            public override void Evaluate()
            {
                TestException testExceptionAnnotation = frameworkMethod.GetAnnotation <TestException
                                                                                       >();

                try
                {
                    statement.Evaluate();
                    if (testExceptionAnnotation != null)
                    {
                        Type klass = testExceptionAnnotation.Exception();
                        NUnit.Framework.Assert.Fail("Expected Exception: " + klass.Name);
                    }
                }
                catch (Exception ex)
                {
                    if (testExceptionAnnotation != null)
                    {
                        Type klass = testExceptionAnnotation.Exception();
                        if (klass.IsInstanceOfType(ex))
                        {
                            string          regExp  = testExceptionAnnotation.MsgRegExp();
                            Sharpen.Pattern pattern = Sharpen.Pattern.Compile(regExp);
                            if (!pattern.Matcher(ex.Message).Find())
                            {
                                NUnit.Framework.Assert.Fail("Expected Exception Message pattern: " + regExp + " got message: "
                                                            + ex.Message);
                            }
                        }
                        else
                        {
                            NUnit.Framework.Assert.Fail("Expected Exception: " + klass.Name + " got: " + ex.GetType
                                                            ().Name);
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }