public void TestCanAccessNonExistentProperty() { var propertyAccessor = LightupHelpers.CreateSyntaxPropertyAccessor <SyntaxNode, object>(typeof(SyntaxNode), "NonExistentProperty"); Assert.NotNull(propertyAccessor); Assert.Null(propertyAccessor(SyntaxFactory.AccessorList())); Assert.Throws <NullReferenceException>(() => propertyAccessor(null)); var withPropertyAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor <SyntaxNode, object>(typeof(SyntaxNode), "NonExistentProperty"); Assert.NotNull(withPropertyAccessor); Assert.NotNull(withPropertyAccessor(SyntaxFactory.AccessorList(), null)); Assert.ThrowsAny <NotSupportedException>(() => withPropertyAccessor(SyntaxFactory.AccessorList(), new object())); Assert.Throws <NullReferenceException>(() => withPropertyAccessor(null, new object())); var separatedListPropertyAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor <SyntaxNode, SyntaxNode>(typeof(SyntaxNode), "NonExistentProperty"); Assert.NotNull(separatedListPropertyAccessor); Assert.NotNull(separatedListPropertyAccessor(SyntaxFactory.AccessorList())); Assert.Throws <NullReferenceException>(() => separatedListPropertyAccessor(null)); var separatedListWithPropertyAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor <SyntaxNode, SyntaxNode>(typeof(SyntaxNode), "NonExistentProperty"); Assert.NotNull(separatedListWithPropertyAccessor); Assert.NotNull(separatedListWithPropertyAccessor(SyntaxFactory.AccessorList(), null)); Assert.ThrowsAny <NotSupportedException>(() => separatedListWithPropertyAccessor(SyntaxFactory.AccessorList(), new SeparatedSyntaxListWrapper <SyntaxNode> .AutoWrapSeparatedSyntaxList <LiteralExpressionSyntax>(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression))))); Assert.Throws <NullReferenceException>(() => separatedListWithPropertyAccessor(null, SeparatedSyntaxListWrapper <SyntaxNode> .UnsupportedEmpty)); }
public void TestCreateSyntaxWithPropertyAccessor() { // The call *should* have been made with the first generic argument set to `BaseMethodDeclarationSyntax` // instead of `MethodDeclarationSyntax`. Assert.ThrowsAny <InvalidOperationException>(() => LightupHelpers.CreateSyntaxWithPropertyAccessor <MethodDeclarationSyntax, BlockSyntax>(typeof(BaseMethodDeclarationSyntax), nameof(BaseMethodDeclarationSyntax.Body))); // The call *should* have been made with the second generic argument set to `ArrowExpressionClauseSyntax` // instead of `BlockSyntax`. Assert.ThrowsAny <InvalidOperationException>(() => LightupHelpers.CreateSyntaxWithPropertyAccessor <MethodDeclarationSyntax, BlockSyntax>(typeof(MethodDeclarationSyntax), nameof(MethodDeclarationSyntax.ExpressionBody))); }
public void TestCanAccessNonExistentSyntaxProperty(Type type) { var fallbackResult = new object(); var propertyAccessor = LightupHelpers.CreateSyntaxPropertyAccessor <SyntaxNode, object>(type, "NonExistentProperty", fallbackResult); Assert.NotNull(propertyAccessor); Assert.Same(fallbackResult, propertyAccessor(SyntaxFactory.AccessorList())); Assert.Throws <NullReferenceException>(() => propertyAccessor(null !)); var withPropertyAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor <SyntaxNode, object>(type, "NonExistentProperty", fallbackResult); Assert.NotNull(withPropertyAccessor); Assert.NotNull(withPropertyAccessor(SyntaxFactory.AccessorList(), fallbackResult)); Assert.ThrowsAny <NotSupportedException>(() => withPropertyAccessor(SyntaxFactory.AccessorList(), new object())); Assert.Throws <NullReferenceException>(() => withPropertyAccessor(null !, new object())); }