Esempio n. 1
0
        private static ExpectedExceptionModel CreateWithArgsExpectedExceptionModel(
            AttributeData attribute,
            SeparatedSyntaxList <AttributeArgumentSyntax> attributeArguments)
        {
            var builder = new ExpectedExceptionModelBuilder();

            foreach (var attributeArgument in attributeArguments)
            {
                var value = attributeArgument.Expression;

                var namedArgumentName = attributeArgument.NameColon?.Name
                                        ?? attributeArgument.NameEquals?.Name;

                builder = namedArgumentName?.ToString() switch
                {
                    "UserMessage" => builder.WithUserMessage(value),
                    "ExpectedException" => builder.WithExceptionType(value),
                    "ExpectedMessage" => builder.WithExpectedMessage(value),
                    "MatchType" => builder.WithMatchType(value),
                    "ExpectedExceptionName" => builder.WithExceptionName(value),
                    null => builder.WithExceptionTypeOrName(value),
                    _ => builder
                };
            }

            return(builder.Build(attribute));
        }
Esempio n. 2
0
        private static ExpectedExceptionModel CreateNoArgExpectedExceptionModel(AttributeData attribute)
        {
            var builder = new ExpectedExceptionModelBuilder();

            return(builder.WithExceptionType(TypeOfExpression(IdentifierName(nameof(Exception))))
                   .Build(attribute));
        }