コード例 #1
0
        public static void WhenAdjacentWithEmptyLine()
        {
            var syntaxTree  = CSharpSyntaxTree.ParseText(@"
namespace N
{
    public class C
    {
        public C()
        {
        }

        private int f1;

        public int P1
        {
            get => this.f1;
            set => this.f1 = value;
        }
    }
}");
            var compilation = CSharpCompilation.Create("test", new[] { syntaxTree });

            Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree), out var newLineBetween));
            Assert.AreEqual(true, newLineBetween);
        }
コード例 #2
0
        public static void TwoProperties()
        {
            var editor = CreateDocumentEditor(@"
namespace N
{
    public class C
    {
        private int f1;

        public int P1
        {
            get => this.f1;
            set => this.f1 = value;
        }

        private int f2;

        public int P2
        {
            get => this.f2;
            set => this.f2 = value;
        }
    }
}");

            Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(editor, out var newLineBetween));
            Assert.AreEqual(true, newLineBetween);
        }
コード例 #3
0
        public static void WhenStyleCop()
        {
            var syntaxTree    = CSharpSyntaxTree.ParseText(@"
namespace N
{
    public class C
    {
        private int f1;

        public C()
        {
        }

        public int P1
        {
            get => this.f1;
            set => this.f1 = value;
        }
    }
}");
            var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree });
            var semanticModel = compilation.GetSemanticModel(syntaxTree);

            Assert.AreEqual(CodeStyleResult.No, CodeStyle.BackingFieldsAdjacent(semanticModel, out _));
        }
コード例 #4
0
        public static void FindsInOtherDocument()
        {
            var syntaxTree1 = CSharpSyntaxTree.ParseText(@"
namespace N
{
    public class C
    {
    }
}");

            var syntaxTree2 = CSharpSyntaxTree.ParseText(@"
namespace N
{
    public class C
    {
        private int f1;

        public C()
        {
        }

        public int P1
        {
            get => this.f1;
            set => this.f1 = value;
        }
    }
}");
            var compilation = CSharpCompilation.Create("test", new[] { syntaxTree1, syntaxTree2 });

            Assert.AreEqual(CodeStyleResult.No, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree1), out _));
            Assert.AreEqual(CodeStyleResult.No, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree2), out _));
        }
コード例 #5
0
        public static void FindsAdjacentInCompilation()
        {
            var syntaxTree1 = CSharpSyntaxTree.ParseText(@"
namespace N
{
    public class C
    {
    }
}");

            var syntaxTree2   = CSharpSyntaxTree.ParseText(@"
namespace N
{
    public class C
    {
        public C()
        {
        }

        private int f1;

        public int P1
        {
            get => this.f1;
            set => this.f1 = value;
        }
    }
}");
            var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree1, syntaxTree2 });
            var semanticModel = compilation.GetSemanticModel(syntaxTree1);

            Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(semanticModel, out var newLine));
            Assert.AreEqual(true, newLine);
        }
コード例 #6
0
        public static void TwoProperties()
        {
            var syntaxTree  = CSharpSyntaxTree.ParseText(@"
namespace N
{
    public class C
    {
        private int f1;

        public int P1
        {
            get => this.f1;
            set => this.f1 = value;
        }

        private int f2;

        public int P2
        {
            get => this.f2;
            set => this.f2 = value;
        }
    }
}");
            var compilation = CSharpCompilation.Create("test", new[] { syntaxTree });

            Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree), out _));
        }
コード例 #7
0
        public static void WhenUnknown()
        {
            var editor = CreateDocumentEditor(@"
namespace N
{
    public class C
    {
    }
}");

            Assert.AreEqual(CodeStyleResult.NotFound, CodeStyle.BackingFieldsAdjacent(editor, out _));
        }
コード例 #8
0
        public static void WhenUnknown()
        {
            var syntaxTree    = CSharpSyntaxTree.ParseText(@"
namespace N
{
    public class C
    {
    }
}");
            var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree });
            var semanticModel = compilation.GetSemanticModel(syntaxTree);

            Assert.AreEqual(CodeStyleResult.NotFound, CodeStyle.BackingFieldsAdjacent(semanticModel, out _));
        }
コード例 #9
0
        public static void TwoExpressionBodyProperties()
        {
            var editor = CreateDocumentEditor(@"
namespace N
{
    public class C
    {
        private int f1;
        public int P1 => this.f1;

        private int f2;
        public int P2 => this.f2;
    }
}");

            Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(editor, out var newLineBetween));
            Assert.AreEqual(false, newLineBetween);
        }
コード例 #10
0
        public static void WhenUnknownOneProperty()
        {
            var editor = CreateDocumentEditor(@"
namespace N
{
    public class C
    {
        private int f1;

        public int P1
        {
            get => this.f1;
            set => this.f1 = value;
        }
    }
}");

            Assert.AreEqual(CodeStyleResult.NotFound, CodeStyle.BackingFieldsAdjacent(editor, out _));
        }
コード例 #11
0
        public static void TwoExpressionBodyProperties()
        {
            var syntaxTree  = CSharpSyntaxTree.ParseText(@"
namespace N
{
    public class C
    {
        private int f1;
        public int P1 => this.f1;

        private int f2;
        public int P2 => this.f2;
    }
}");
            var compilation = CSharpCompilation.Create("test", new[] { syntaxTree });

            Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree), out var newLineBetween));
            Assert.AreEqual(false, newLineBetween);
        }
コード例 #12
0
        public static void WhenUnknownTwoDocuments()
        {
            var syntaxTree1 = CSharpSyntaxTree.ParseText(@"
namespace N
{
    public class C1
    {
    }
}");

            var syntaxTree2 = CSharpSyntaxTree.ParseText(@"
namespace N
{
    public class C2
    {
    }
}");
            var compilation = CSharpCompilation.Create("test", new[] { syntaxTree1, syntaxTree2 });

            Assert.AreEqual(CodeStyleResult.NotFound, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree1), out _));
            Assert.AreEqual(CodeStyleResult.NotFound, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree2), out _));
        }
コード例 #13
0
        public static void WhenAdjacentNoEmptyLine()
        {
            var editor = CreateDocumentEditor(@"
namespace N
{
    public class C
    {
        public C()
        {
        }

        private int f1;
        public int P1
        {
            get => this.f1;
            set => this.f1 = value;
        }
    }
}");

            Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(editor, out var newLineBetween));
            Assert.AreEqual(false, newLineBetween);
        }