/// <summary>
        /// Constructs <c>NUnit.Framework.TestCaseAttribute</c> model that allows for sourcing exception related
        /// properties from <c>NUnit.Framework.ExpectedExceptionAttribute</c> in case of not defining them by itself.
        /// </summary>
        public TestCaseExpectingExceptionAttribute(AttributeSyntax attribute,
                                                   ExpectedExceptionAttribute expectedException) : base(attribute)
        {
            if (expectedException == null)
            {
                return;
            }

            if (AssertedExceptionTypeName == null)
            {
                AssertedExceptionTypeName = expectedException.AssertedExceptionTypeName;
            }

            if (ExpectedMessage == null)
            {
                ExpectedMessage = expectedException.ExpectedMessage;
            }

            if (MatchType == null)
            {
                MatchType = expectedException.MatchType;
            }

            if (HandlerName == null)
            {
                HandlerName = expectedException.HandlerName;
            }

            if (UserMessage == null)
            {
                UserMessage = expectedException.UserMessage;
            }
        }
Exemplo n.º 2
0
        private static bool TryGetFirstExpectedExceptionAttribute(NUnitFramework.Symbols nunit,
                                                                  AttributeWithSymbol[] attributesWithSymbols, out ExpectedExceptionAttribute expectedException)
        {
            var expectedExceptionNode = GetExpectedExceptionAttributes(nunit, attributesWithSymbols)?.FirstOrDefault();

            if (expectedExceptionNode != null)
            {
                expectedException = new ExpectedExceptionAttribute(expectedExceptionNode);
                return(true);
            }

            expectedException = null;
            return(false);
        }
Exemplo n.º 3
0
 private static TestCaseExpectingExceptionAttribute[] GetExceptionRelatedTestCases(NUnitFramework.Symbols nunit,
                                                                                   AttributeWithSymbol[] attributesWithSymbols, bool isExpectedException,
                                                                                   ExpectedExceptionAttribute expectedException)
 {
     return(attributesWithSymbols
            .Where(x => IsTestCaseAttributeExpectingException(x.Attribute, x.Symbol, nunit, isExpectedException))
            .Select(x => new TestCaseExpectingExceptionAttribute(x.Attribute, expectedException))
            .ToArray());
 }