示例#1
0
    public void DefaultRazorDiagnostic_ToString()
    {
        // Arrange
        var descriptor = new RazorDiagnosticDescriptor("RZ0000", () => "this is an error", RazorDiagnosticSeverity.Error);
        var span       = new SourceSpan("test.cs", 15, 1, 8, 5);

        var diagnostic = new DefaultRazorDiagnostic(descriptor, span, new object[0]);

        // Act
        var result = diagnostic.ToString();

        // Assert
        Assert.Equal("test.cs(2,9): Error RZ0000: this is an error", result);
    }
示例#2
0
    public void DefaultRazorDiagnostic_ToString_FormatProvider()
    {
        // Arrange
        var descriptor = new RazorDiagnosticDescriptor("RZ0000", () => "this is an {0}", RazorDiagnosticSeverity.Error);
        var span       = new SourceSpan("test.cs", 15, 1, 8, 5);

        var diagnostic = new DefaultRazorDiagnostic(descriptor, span, new object[] { 1.3m });

        // Act
        var result = ((IFormattable)diagnostic).ToString("ignored", new CultureInfo("fr-FR"));

        // Assert
        Assert.Equal("test.cs(2,9): Error RZ0000: this is an 1,3", result);
    }
示例#3
0
    public void DefaultRazorDiagnostic_GetMessage_WithArgs_FormatProvider()
    {
        // Arrange
        var descriptor = new RazorDiagnosticDescriptor("RZ0000", () => "this is an {0}", RazorDiagnosticSeverity.Error);
        var span       = new SourceSpan("test.cs", 15, 1, 8, 5);

        var diagnostic = new DefaultRazorDiagnostic(descriptor, span, new object[] { 1.3m });

        // Act
        var result = diagnostic.GetMessage(new CultureInfo("fr-FR"));

        // Assert
        Assert.Equal("this is an 1,3", result);
    }
示例#4
0
    public void DefaultRazorDiagnostic_GetMessage_WithArgs()
    {
        // Arrange
        var descriptor = new RazorDiagnosticDescriptor("RZ0000", () => "this is an {0}", RazorDiagnosticSeverity.Error);
        var span       = new SourceSpan("test.cs", 15, 1, 8, 5);

        var diagnostic = new DefaultRazorDiagnostic(descriptor, span, new[] { "error" });

        // Act
        var result = diagnostic.GetMessage(CultureInfo.CurrentCulture);

        // Assert
        Assert.Equal("this is an error", result);
    }
示例#5
0
    public void DefaultRazorDiagnostic_Ctor()
    {
        // Arrange
        var descriptor = new RazorDiagnosticDescriptor("RZ0000", () => "error", RazorDiagnosticSeverity.Error);
        var span       = new SourceSpan("test.cs", 15, 1, 8, 5);

        // Act
        var diagnostic = new DefaultRazorDiagnostic(descriptor, span, new object[0]);

        // Assert
        Assert.Equal("RZ0000", diagnostic.Id);
        Assert.Equal(RazorDiagnosticSeverity.Error, diagnostic.Severity);
        Assert.Equal(span, diagnostic.Span);
    }
示例#6
0
    public void DefaultRazorDiagnostic_HashCodesEqual()
    {
        // Arrange
        var descriptor = new RazorDiagnosticDescriptor("RZ0000", () => "this is an {0}", RazorDiagnosticSeverity.Error);
        var span       = new SourceSpan("test.cs", 15, 1, 8, 5);

        var diagnostic1 = new DefaultRazorDiagnostic(descriptor, span, new object[0]);
        var diagnostic2 = new DefaultRazorDiagnostic(descriptor, span, new object[0]);

        // Act
        var result = diagnostic1.GetHashCode() == diagnostic2.GetHashCode();

        // Assert
        Assert.True(result);
    }
示例#7
0
    public void DefaultRazorDiagnostic_NotEquals_DifferentId()
    {
        // Arrange
        var descriptor1 = new RazorDiagnosticDescriptor("RZ0001", () => "this is an {0}", RazorDiagnosticSeverity.Error);
        var descriptor2 = new RazorDiagnosticDescriptor("RZ0002", () => "this is an {0}", RazorDiagnosticSeverity.Error);
        var span        = new SourceSpan("test.cs", 15, 1, 8, 5);

        var diagnostic1 = new DefaultRazorDiagnostic(descriptor1, span, new object[0]);
        var diagnostic2 = new DefaultRazorDiagnostic(descriptor2, span, new object[0]);

        // Act
        var result = diagnostic1.Equals(diagnostic2);

        // Assert
        Assert.False(result);
    }