本文整理匯總了C#中TestHelper.DiagnosticResult類的典型用法代碼示例。如果您正苦於以下問題:C# DiagnosticResult類的具體用法?C# DiagnosticResult怎麽用?C# DiagnosticResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DiagnosticResult類屬於TestHelper命名空間,在下文中一共展示了DiagnosticResult類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DoNotUseValuesWhenMultipleIsFalse
public void DoNotUseValuesWhenMultipleIsFalse()
{
var testContent = @"
using Bridge.React;
namespace TestCase
{
public class Example
{
public void Go()
{
new SelectAttributes { Multiple = false, Values = new[] { ""1"" } };
}
}
}";
var expected = new DiagnosticResult
{
Id = SelectAttributesAnalyzer.DiagnosticId,
Message = SelectAttributesAnalyzer.DoNotUseValuesWhenMultipleIsFalseRule.MessageFormat.ToString(),
Severity = DiagnosticSeverity.Warning,
Locations = new[]
{
new DiagnosticResultLocation("Test0.cs", 10, 29)
}
};
VerifyCSharpDiagnostic(testContent, expected);
}
示例2: AccessWithoutChecking
public void AccessWithoutChecking()
{
var code = @"
using System;
using System.Linq;
namespace ConsoleApp1
{
public class Test0
{
public void Tested()
{
var obj = new Object();
var s = obj as String;
var toString = s.ToString();
}
}
}
";
var expected = new DiagnosticResult
{
Id = "AV1570",
Message = "Always check the result of an as operation",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 15, 52)
}
};
VerifyCSharpDiagnostic(code, expected);
}
示例3: Test1
public void Test1()
{
var test = @"
class C
{
public void M1()
{
}
public virtual void M2()
{
}
public int M3()
{
}
}";
var expected = new DiagnosticResult
{
Id = DiagnosticIds.CodeBlockAnalyzerRuleId,
Message = string.Format(Resources.CodeBlockAnalyzerMessageFormat, "M1"),
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 4, 17)
}
};
VerifyCSharpDiagnostic(test, expected);
}
示例4: UnHandle
public void UnHandle()
{
var source = @"
using System;
class Test
{
IObservable<int> GetObservable() => null;
void Hoge()
{
GetObservable();
}
}";
var expected = new DiagnosticResult
{
Id = UniRxAnalyzer.HandleObservableAnalyzer.DiagnosticId,
Message = "This call does not handle IObservable<T>.",
Severity = DiagnosticSeverity.Warning,
Locations = new[]
{
new DiagnosticResultLocation("Test0.cs", 10, 9)
}
};
this.VerifyCSharpDiagnostic(source, expected);
}
示例5: TestCSharpAtrributesPresentButEmpty
public void TestCSharpAtrributesPresentButEmpty()
{
var expected = new DiagnosticResult[4];
expected[0] = CompanyAttributeResult;
expected[1] = CopyrightAttributeResult;
expected[2] = DescriptionAttributeResult;
expected[3] = TitleAttributeResult;
VerifyCSharpDiagnostic(@"
using System;
using System.Reflection;
[assembly: AssemblyTitle("""")]
[assembly: AssemblyDescription("""")]
[assembly: AssemblyCompany("""")]
[assembly: AssemblyCopyright("""")]
namespace SomeTests
{
public class BasicClass
{
public void SomeWork(String message)
{
Console.WriteLine(message);
}
}
}
", expected);
}
示例6: ForeachSimpleStatementAssignment
public void ForeachSimpleStatementAssignment()
{
var code = @"
using System;
using System.Linq;
namespace ConsoleApp1
{
public class Test0
{
public void Tested()
{
var list = new List<int>();
foreach(var item in list)
item = null;
}
}
}
";
var expected = new DiagnosticResult
{
Id = "AV1530",
Message = "Don’t change a loop variable inside a for or foreach loop",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 13, 41)
}
};
VerifyCSharpDiagnostic(code, expected);
}
示例7: TestMethod2
public void TestMethod2()
{
var test = @"using System;
using FluentArithmetic;
class Program
{
static void Main(string[] args)
{
var x = 1.Add(2).Mul(3).Sub(1).Div(0);
Console.WriteLine(x);
}
}
";
var expected = new DiagnosticResult
{
Id = DivByZeroAnalyzer.DiagnosticId,
Message = DivByZeroAnalyzer.MessageFormat.ToString(),
Severity = DiagnosticSeverity.Error,
Locations = new[]
{
new DiagnosticResultLocation("Test0.cs", 8, 44)
}
};
VerifyCSharpDiagnostic(test, expected);
}
示例8: ValidateDiagnosticFires
public void ValidateDiagnosticFires()
{
var test = @"
using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
class TypeName
{
var a = new System.Collections.ArrayList();
}
}";
var expected = new DiagnosticResult
{
Id = DontUseArrayList.DiagnosticId,
Message = "The type ArrayList should not be used",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 9, 20)
}
};
VerifyCSharpDiagnostic(test, expected);
}
示例9: MethodNamesTest
public void MethodNamesTest()
{
string test = System.IO.File.ReadAllText(@"TestCodes\AsyncTestCode_1.cs");
var expected1 = new DiagnosticResult
{
Id = AsyncAnalyzerAnalyzer.DiagnosticId,
Message = String.Format("Async method name '{0}' does not end with Async", "Test"),
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 12, 27),
}
};
var expected2 = new DiagnosticResult
{
Id = AsyncAnalyzerAnalyzer.DiagnosticId,
Message = String.Format("Async method name '{0}' does not end with Async", "Something"),
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 28, 33),
}
};
VerifyCSharpDiagnostic(test, expected1, expected2);
string fixtest = System.IO.File.ReadAllText(@"TestCodes\AsyncTestCode_1_fix.cs");
VerifyCSharpFix(test, fixtest);
}
示例10: TestBasicEmptyComment
public void TestBasicEmptyComment()
{
var testCode = @"
class Foo
{
public void Bar()
{
//
}
}";
var expected = new DiagnosticResult
{
Id = EmptyCommentAnalyzer.DiagnosticId,
Message = EmptyCommentAnalyzer.MessageFormat.ToString(),
Severity = DiagnosticSeverity.Warning,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 6, 9)
}
};
this.VerifyCSharpDiagnostic(testCode, expected);
var expectedFixedCode = @"
class Foo
{
public void Bar()
{
}
}";
this.VerifyCSharpFix(testCode, expectedFixedCode);
}
示例11: AssertEquals_IfActualValueIsAStringLiteral_ThenItTriggersTheDiagnostic
public void AssertEquals_IfActualValueIsAStringLiteral_ThenItTriggersTheDiagnostic()
{
var test = @"
using System;
using System.Linq;
using Xunit;
namespace WongaTests
{
class WongaTest
{
[Fact]
public void MyTest()
{
var result = Testee.GetSomeData();
Assert.Equal(result.Id, ""someId"");
}
}
}";
var expected = new DiagnosticResult
{
Id = "AssertExpectedActualAnalyser",
Message = "Possible incorrect argument order in 'Assert.Equal': '\"someId\"' is likely to be the expected value",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 14, 17)
}
};
VerifyCSharpDiagnostic(test, expected);
}
示例12: TestMethod2
public void TestMethod2()
{
const String test = @"
using System;
namespace ConsoleApplication1
{
class TypeName
{
}
}";
var expected = new DiagnosticResult
{
Id = "CSharpCodeFixes",
Message = $"Type name '{"TypeName"}' contains lowercase letters",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 6, 15)
}
};
VerifyCSharpDiagnostic(test, expected);
const String fixtest = @"
using System;
namespace ConsoleApplication1
{
class TYPENAME
{
}
}";
VerifyCSharpFix(test, fixtest);
}
示例13: CorrectDiagnosticWhenAnonymousTypeInProjection
public void CorrectDiagnosticWhenAnonymousTypeInProjection()
{
// Fixture setup
var test = @"
using System;
using System.Linq;
namespace N
{
class C
{
void M()
{
var q = Enumerable.Range(0, 5)
.Select(i => new { Qux = i });
}
}
}";
var expected = new DiagnosticResult
{
Id = "ExtractAnonymousType",
Message = "Anonymous type used",
Severity = DiagnosticSeverity.Info,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 12, 30)
}
};
// Exercise system & Verify outcome
VerifyCSharpDiagnostic(test, expected);
// Teardown
}
示例14: Test1
public void Test1()
{
var test = @"
class C
{
public void M()
{
var implicitTypedLocal = 0;
int explicitTypedLocal = 1;
}
}";
var expected = new DiagnosticResult
{
Id = DiagnosticIds.SyntaxNodeAnalyzerRuleId,
Message = string.Format(Resources.SyntaxNodeAnalyzerMessageFormat, "implicitTypedLocal"),
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 6, 13)
}
};
VerifyCSharpDiagnostic(test, expected);
}
示例15: Test1
public void Test1()
{
var test = @"
namespace MyInterfaces
{
public interface Interface {}
class MyInterfaceImpl : Interface
{
}
class MyInterfaceImpl2 : Interface
{
}
}";
var expected = new DiagnosticResult
{
Id = DiagnosticIds.CompilationStartedAnalyzerRuleId,
Message = string.Format(Resources.CompilationStartedAnalyzerMessageFormat, "MyInterfaceImpl2", CompilationStartedAnalyzer.DontInheritInterfaceTypeName),
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 10, 11)
}
};
VerifyCSharpDiagnostic(test, expected);
}