public void ThrowsArgumentNullException_When_ParentIsNull() { INamedTypeSymbol child = GetSymbol <INamedTypeSymbol, ClassDeclarationSyntax>("class Child { }"); INamedTypeSymbol parent = null !; Assert.Throws <ArgumentNullException>(() => parent.ContainsSymbol(child)); }
public void ReturnsFalse_When_ParentDoesNotContainChild() { INamedTypeSymbol parent = GetSymbol <INamedTypeSymbol, ClassDeclarationSyntax>("class Parent { }"); INamedTypeSymbol child = GetSymbol <INamedTypeSymbol, ClassDeclarationSyntax>("class Child { }"); Assert.False(parent.ContainsSymbol(child)); }
public void ReturnsTrue_When_ParentContainsChild() { ClassDeclarationSyntax syntax = GetNode <ClassDeclarationSyntax>("class Parent { class Child { } }"); INamedTypeSymbol parent = GetSymbol <INamedTypeSymbol>(syntax); INamedTypeSymbol child = parent.GetTypeMembers("Child").First(); Assert.True(parent.ContainsSymbol(child)); }
private static bool TryGetInvalidFriendTypeDiagnostic( INamedTypeSymbol symbol, ITypeSymbol?friend, AttributeData attribute, HashSet <ITypeSymbol> friendTypes, [NotNullWhen(true)] out Diagnostic?diagnostic ) { if (friend is null || friend is not INamedTypeSymbol || !(friend.TypeKind is TypeKind.Interface or TypeKind.Class or TypeKind.Struct) ) { diagnostic = Diagnostic.Create( descriptor: DUR0308_TypeIsNotValid, location: GetFriendArgumentLocation(attribute, symbol), messageArgs: new[] { symbol, friend } ); return(true); } if (SymbolEqualityComparer.Default.Equals(friend, symbol)) { diagnostic = Diagnostic.Create( descriptor: DUR0309_TypeCannotBeFriendOfItself, location: GetFriendArgumentLocation(attribute, symbol), messageArgs: new[] { symbol } ); return(true); } if (!friendTypes.Add(friend)) { diagnostic = Diagnostic.Create( descriptor: DUR0306_FriendTypeSpecifiedByMultipleAttributes, location: GetFriendArgumentLocation(attribute, symbol), messageArgs: new[] { symbol, friend } ); return(true); } if (symbol.ContainsSymbol(friend)) { diagnostic = Diagnostic.Create( descriptor: DUR0312_InnerTypeIsImplicitFriend, location: GetFriendArgumentLocation(attribute, symbol), messageArgs: new[] { symbol } ); return(true); } diagnostic = null; return(false); }