public void TestWithExpressionBody() { var syntax = SyntaxFactory.DestructorDeclaration(SyntaxFactory.Identifier("Anything")); var expressionBody = SyntaxFactory.ArrowExpressionClause(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)); var syntaxWithBody = DestructorDeclarationSyntaxExtensions.WithExpressionBody(syntax, expressionBody); Assert.Null(syntax.ExpressionBody); Assert.NotNull(syntaxWithBody.ExpressionBody); Assert.Equal(SyntaxKind.NullLiteralExpression, syntaxWithBody.ExpressionBody.Expression.Kind()); }
public void TestWithExpressionBody() { var syntax = SyntaxFactory.DestructorDeclaration(SyntaxFactory.Identifier("Anything")); // With default value is allowed var syntaxWithDefaultBody = DestructorDeclarationSyntaxExtensions.WithExpressionBody(syntax, null); Assert.Null(BaseMethodDeclarationSyntaxExtensions.ExpressionBody(syntaxWithDefaultBody)); // Non-default throws an exception var expressionBody = SyntaxFactory.ArrowExpressionClause(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)); Assert.Throws <NotSupportedException>(() => DestructorDeclarationSyntaxExtensions.WithExpressionBody(syntax, expressionBody)); }