Пример #1
0
        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"));
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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"));
        }