public void LocateFields_LocatesOnlyUnitializedFields() { var classSource = @"public class TestClass { private string s; private object o = new object(); public TestClass() { } }"; var(semanticModel, syntax) = CompiledSourceFileProvider.CompileClass(classSource); var fieldLocator = new FieldLocator(syntax, semanticModel); var fields = fieldLocator.LocateFields(); Assert.That(fields, Has.One.Items); var field = fields.Single(); Assert.That(field.Declaration.Type.ToString(), Is.EqualTo("string")); Assert.That(field.Declaration.Variables, Has.One.Items); Assert.That(field.Declaration.Variables, Has.One.Items); var variable = field.Declaration.Variables.Single(); Assert.That(variable.Identifier.ToString(), Is.EqualTo("s")); }
public void LocateFields_LocatesNoFields() { var classSource = @"public class TestClass { public TestClass() { } }"; var(semanticModel, syntax) = CompiledSourceFileProvider.CompileClass(classSource); var fieldLocator = new FieldLocator(syntax, semanticModel); var fields = fieldLocator.LocateFields(); Assert.That(fields, Has.Exactly(0).Items); }
public void LocateFields_LocatesMultipleFields() { var classSource = @"public class TestClass { private string s; private object o; public TestClass() { s = """"; } }"; var(semanticModel, syntax) = CompiledSourceFileProvider.CompileClass(classSource); var fieldLocator = new FieldLocator(syntax, semanticModel); var fields = fieldLocator.LocateFields(); Assert.That(fields, Has.Exactly(2).Items); }
public void LocateFields_IgnoresValueTypes() { const string classSource = @"public class Test { private int i; private decimal d; private System.DayOfWeek day; private string s; public Test() {} }"; var(semantic, syntax) = CompiledSourceFileProvider.CompileClass(classSource); var fieldLocator = new FieldLocator(syntax, semantic); var fields = fieldLocator.LocateFields(); Assert.That(fields, Has.One.Items); var field = fields.Single(); Assert.That(field.Declaration.Type.ToString(), Is.EqualTo("string")); }