public void PropertyAnnotator_WithInitializedAutoProperty_DoesNotAnnotateNullable(string classContent) { var(semantic, syntax) = CompiledSourceFileProvider.CompileInClass("TestClass", classContent); var annotator = new PropertyNullAnnotator(semantic); var annotated = annotator.Visit(syntax); Assert.That(annotated, Is.EqualTo(syntax)); }
public void PropertyAnnotator_WithReadonlyPropertyInInterface_DoesNotAnnotateNullable() { var(semantic, syntax) = CompiledSourceFileProvider.CompileInNameSpace("TestNamespace", @"public interface ITest { string Property { get; } }"); var annotator = new PropertyNullAnnotator(semantic); var annotated = annotator.Visit(syntax); Assert.That(annotated, Is.EqualTo(syntax)); }
public void PropertyAnnotator_WithBlockGetterReturnsNull_AnnotatesNullable(string classContent) { var(semantic, syntax) = CompiledSourceFileProvider.CompileInClass("TestClass", classContent); var annotator = new PropertyNullAnnotator(semantic); var annotated = annotator.Visit(syntax); Assert.That(annotated.DescendantNodesAndSelf().OfType <PropertyDeclarationSyntax>(), Has.One.Items); var property = annotated.DescendantNodesAndSelf().OfType <PropertyDeclarationSyntax>().Single(); Assert.That(property.Type, Is.InstanceOf <NullableTypeSyntax>()); Assert.That(((NullableTypeSyntax)property.Type).ElementType.ToString(), Is.EqualTo("string")); }
public void PropertyAnnotator_WithInitializedInMultipleCtorsAutoProperty_DoesNotAnnotateNullable() { var(semantic, syntax) = CompiledSourceFileProvider.CompileInClass( "TestClass", @"public TestClass () { A = """";} public TestClass (string s) { A = s; } public TestClass (string s, int i): this(s) { } public string A {get;}"); var annotator = new PropertyNullAnnotator(semantic); var annotated = annotator.Visit(syntax); Assert.That(annotated, Is.EqualTo(syntax)); }
public void PropertyAnnotator_WithUninitializedAutoProperty_AnnotatesNullable() { var(semantic, syntax) = CompiledSourceFileProvider.CompileInClass( "TestClass", @"public TestClass () {} public TestClass (string s) { A = s; } public string A {get;}"); var annotator = new PropertyNullAnnotator(semantic); var annotated = annotator.Visit(syntax); Assert.That(annotated.DescendantNodesAndSelf().OfType <PropertyDeclarationSyntax>(), Has.One.Items); var property = annotated.DescendantNodesAndSelf().OfType <PropertyDeclarationSyntax>().Single(); Assert.That(property.Type, Is.InstanceOf <NullableTypeSyntax>()); Assert.That(((NullableTypeSyntax)property.Type).ElementType.ToString(), Is.EqualTo("string")); }