コード例 #1
0
        public async Task TestMultipleErrorsMatchQuality()
        {
            var testCode = @"class TestClass {
  void IDisposable.Dispose() { }
}
";

            var exception = await Assert.ThrowsAsync <InvalidOperationException>(async() =>
            {
                await new CSharpTest
                {
                    TestCode            = testCode,
                    ExpectedDiagnostics =
                    {
                        // Test0.cs(2,8): error CS0246: The type or namespace name 'IDisposable' could not be found (are you missing a using directive or an assembly reference?)
                        DiagnosticResult.CompilerError("CS0246").WithSpan(2, 8, 2, 21).WithArguments("IDisposable"),

                        // Test0.cs(2,8): error CS0538: 'IDisposable' in explicit interface declaration is not an interface
                        DiagnosticResult.CompilerError("CS0538").WithSpan(2, 8, 2, 20).WithArguments("IDisposable"),
                    },
                }.RunAsync();
            });

            var expected =
                "Expected diagnostic to end at column \"21\" was actually at column \"19\"" + Environment.NewLine +
                Environment.NewLine +
                "Expected diagnostic:" + Environment.NewLine +
                "    // /0/Test0.cs(2,8,2,21): error CS0246" + Environment.NewLine +
                "DiagnosticResult.CompilerError(\"CS0246\").WithSpan(2, 8, 2, 21).WithArguments(\"IDisposable\")," + Environment.NewLine +
                Environment.NewLine +
                "Actual diagnostic:" + Environment.NewLine +
                "    // /0/Test0.cs(2,8): error CS0246: The type or namespace name 'IDisposable' could not be found (are you missing a using directive or an assembly reference?)" + Environment.NewLine +
                "DiagnosticResult.CompilerError(\"CS0246\").WithSpan(2, 8, 2, 19).WithArguments(\"IDisposable\")," + Environment.NewLine +
                Environment.NewLine;

            new DefaultVerifier().EqualOrDiff(expected, exception.Message);
        }
コード例 #2
0
 public void TestToStringWithoutLocationOrMessage()
 {
     Assert.Equal(
         "error CS1002",
         DiagnosticResult.CompilerError("CS1002").ToString());
 }
コード例 #3
0
 public void TestToStringWithoutLocation()
 {
     Assert.Equal(
         "error CS1002: ; expected",
         DiagnosticResult.CompilerError("CS1002").WithMessage("; expected").ToString());
 }