Exemple #1
0
            public static void ClassLibrary1ProjectFileFieldNameMustNotBeginWithUnderscoreDisabled()
            {
                var code     = ProjectFile.Find("ClassLibrary1.csproj");
                var expected = "Expected no diagnostics, found:\r\n" +
                               "SA13090 Field \'_value\' must not begin with an underscore\r\n" +
                               $"  at line 5 and character 20 in file {code.DirectoryName}\\ClassLibrary1Class1.cs | private int ↓_value;";
                var analyzer = new FieldNameMustNotBeginWithUnderscoreDisabled();

                var exception = Assert.Throws <AssertException>(() => RoslynAssert.Valid(analyzer, code));

                StringAssert.Contains(expected, exception.Message);

                exception = Assert.Throws <AssertException>(() => RoslynAssert.Valid(typeof(FieldNameMustNotBeginWithUnderscoreDisabled), code));
                StringAssert.Contains(expected, exception.Message);

                var descriptor = FieldNameMustNotBeginWithUnderscoreDisabled.Descriptor;

                exception = Assert.Throws <AssertException>(() => RoslynAssert.Valid(typeof(FieldNameMustNotBeginWithUnderscoreDisabled), descriptor, code));
                StringAssert.Contains(expected, exception.Message);

                exception = Assert.Throws <AssertException>(() => RoslynAssert.Valid(analyzer, descriptor, code));
                StringAssert.Contains(expected, exception.Message);

                exception = Assert.Throws <AssertException>(() => RoslynAssert.Valid(analyzer, code, compilationOptions: CodeFactory.DefaultCompilationOptions(analyzer, descriptor, null)));
                StringAssert.Contains(expected, exception.Message);
            }
Exemple #2
0
            public static void ClassLibrary2ProjectFileFieldNameMustNotBeginWithUnderscoreDisabled()
            {
                var code     = ProjectFile.Find("ClassLibrary2.csproj");
                var expected = "Expected no diagnostics, found:\r\n" +
                               "SA13090 Field \'_value\' must not begin with an underscore\r\n" +
                               $"  at line 5 and character 20 in file {code.DirectoryName}\\ClassLibrary2Class1.cs | private int ↓_value;";
                var analyzer  = new FieldNameMustNotBeginWithUnderscoreDisabled();
                var exception = Assert.Throws <AssertException>(() => RoslynAssert.Valid(analyzer, code));

                StringAssert.Contains(expected, exception.Message);

                exception = Assert.Throws <AssertException>(() => RoslynAssert.Valid(analyzer.GetType(), code));
                StringAssert.Contains(expected, exception.Message);
            }
Exemple #3
0
            public static void ClassLibrary2SolutionFileFieldNameMustNotBeginWithUnderscoreDisabled()
            {
                var code     = ProjectFile.Find("ClassLibrary2.csproj");
                var expected = "Expected no diagnostics, found:\r\n" +
                               "SA13090 Field \'_value\' must not begin with an underscore\r\n" +
                               $"  at line 5 and character 20 in file {code.DirectoryName}\\ClassLibrary2Class1.cs | private int ↓_value;";
                var solution  = CodeFactory.CreateSolution(code, new[] { new FieldNameMustNotBeginWithUnderscoreDisabled() }, Gu.Roslyn.Asserts.MetadataReferences.FromAttributes());
                var analyzer  = new FieldNameMustNotBeginWithUnderscoreDisabled();
                var exception = Assert.Throws <AssertException>(() => RoslynAssert.Valid(analyzer, solution));

                StringAssert.Contains(expected, exception.Message);

                exception = Assert.Throws <AssertException>(() => RoslynAssert.Valid(analyzer.GetType(), solution));
                StringAssert.Contains(expected, exception.Message);
            }
Exemple #4
0
            public static void SingleDocumentFieldNameMustNotBeginWithUnderscoreDisabled()
            {
                var code     = @"
namespace N
{
    class C
    {
        private readonly int _value = 1;
    }
}";
                var expected = "Expected no diagnostics, found:\r\n" +
                               "SA13090 Field \'_value\' must not begin with an underscore\r\n" +
                               "  at line 5 and character 29 in file C.cs | private readonly int ↓_value = 1;\r\n";

                var analyzer  = new FieldNameMustNotBeginWithUnderscoreDisabled();
                var exception = Assert.Throws <AssertException>(() => RoslynAssert.Valid(analyzer, code));

                Assert.AreEqual(expected, exception.Message);

                exception = Assert.Throws <AssertException>(() => RoslynAssert.Valid(typeof(FieldNameMustNotBeginWithUnderscoreDisabled), code));
                Assert.AreEqual(expected, exception.Message);
            }
Exemple #5
0
            public static void TwoDocumentsTwoErrorsDefaultDisabledAnalyzer()
            {
                var c1       = @"
namespace N
{
    class C1
    {
        private readonly int ↓_value = 1;
    }
}";
                var c2       = @"
namespace N
{
    class C2
    {
        private readonly int ↓_value = 1;
    }
}";
                var analyzer = new FieldNameMustNotBeginWithUnderscoreDisabled();

                RoslynAssert.Diagnostics(analyzer, c1, c2);
            }
Exemple #6
0
            public static void IndicatedAndActualPositionDoNotMatchFieldNameMustNotBeginWithUnderscoreDisabled()
            {
                var code     = @"
namespace N
{
    class C
    {
        private ↓readonly int _value1;
    }
}";
                var expected = "Expected and actual diagnostics do not match.\r\n" +
                               "Expected:\r\n" +
                               "  SA13090 \r\n" +
                               "    at line 5 and character 16 in file C.cs | private ↓readonly int _value1;\r\n" +
                               "Actual:\r\n" +
                               "  SA13090 Field '_value1' must not begin with an underscore\r\n" +
                               "    at line 5 and character 29 in file C.cs | private readonly int ↓_value1;\r\n";
                var analyzer  = new FieldNameMustNotBeginWithUnderscoreDisabled();
                var exception = Assert.Throws <AssertException>(() => RoslynAssert.Diagnostics(analyzer, code));

                Assert.AreEqual(expected, exception.Message);
            }