本文整理汇总了C#中DiagnosticResult类的典型用法代码示例。如果您正苦于以下问题:C# DiagnosticResult类的具体用法?C# DiagnosticResult怎么用?C# DiagnosticResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DiagnosticResult类属于命名空间,在下文中一共展示了DiagnosticResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestUnspecifiedSetPropertyHasCorrectComment
public void TestUnspecifiedSetPropertyHasCorrectComment()
{
var test = @"
namespace ConsoleApplication1
{
class TypeName
{
public string VogonConstructorFleet { get; }
}
}";
var expected = new DiagnosticResult
{
Id = "SA1623D",
Message = $"property documentation: no documentation.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] { new DiagnosticResultLocation("Test0.cs", 6, 23) }
};
new DocumentationPropertyCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);
var fixtest = @"
namespace ConsoleApplication1
{
class TypeName
{
/// <summary>
/// Gets the vogon constructor fleet.
/// </summary>
public string VogonConstructorFleet { get; }
}
}";
new DocumentationPropertyCodeFixVerifier().VerifyCSharpFix(test, fixtest);
}
示例2: NestedExpressionContains2Dots_DiagnosticIsReported
public void NestedExpressionContains2Dots_DiagnosticIsReported()
{
const string code = @"
class Board {
public String boardRepresentation() {
StringBuilder buf = new StringBuilder();
for (Location loc : squares()) {
buf.append(loc.current.substring(0, 1));
}
return buf.toString();
}
}";
var expected = new DiagnosticResult
{
Id = "DaVinciOC5",
Message = "\'loc.current.substring(0, 1)\' contains more than 1 dot per line.",
Severity = DiagnosticSeverity.Info,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 7, 36) }
};
VerifyCSharpDiagnostic(code, expected);
}
示例3: MethodTakesMultiplePrimitiveAsParameter_MultipleDiagnosticReported
public void MethodTakesMultiplePrimitiveAsParameter_MultipleDiagnosticReported()
{
const string Code = @"
class SomeClass
{
public void DoSomething(int parameter1, uint parameter2)
{
}
}";
var expected1 = new DiagnosticResult
{
Id = "DaVinciOC3",
Message = "'parameter1' should be wrapped as it's a primitive.",
Severity = DiagnosticSeverity.Info,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 4, 49) }
};
var expected2 = new DiagnosticResult
{
Id = "DaVinciOC3",
Message = "'parameter2' should be wrapped as it's a primitive.",
Severity = DiagnosticSeverity.Info,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 4, 66) }
};
VerifyCSharpDiagnostic(Code, expected1, expected2);
}
示例4: DiagnosticForMethod
public void DiagnosticForMethod()
{
var source = @"
using System.Threading;
class T
{
void M(CancellationToken t, int i)
{
}
}";
var expected = new DiagnosticResult
{
Id = RoslynDiagnosticIds.CancellationTokenMustBeLastRuleId,
Message = string.Format(RoslynDiagnosticsResources.CancellationTokenMustBeLastMessage, "T.M(System.Threading.CancellationToken, int)"),
Severity = DiagnosticSeverity.Warning,
Locations = new[]
{
new DiagnosticResultLocation("Test0.cs", 5, 10)
}
};
VerifyCSharp(source, expected);
var fixedSource = @"
using System.Threading;
class T
{
void M(int i, CancellationToken t)
{
}
}";
VerifyCSharpFix(source, fixedSource);
}
示例5: MethodContainsControlStructureInElseStatement_DiagnosticIsReported
public void MethodContainsControlStructureInElseStatement_DiagnosticIsReported()
{
const string Code = @"
class SomeClass
{
public void SomeMethod()
{
if (new Random().Next(1) == 1)
{
System.Console.WriteLine(string.Empty);
}
else
{
for (int i = 0; i < 10; i++)
{
System.Console.WriteLine();
}
}
}
}";
var expected = new DiagnosticResult
{
Id = "DaVinciOC1",
Message = "\'SomeMethod\' contains more than 1 level of indentation.",
Severity = DiagnosticSeverity.Info,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 4, 29) }
};
VerifyCSharpDiagnostic(Code, expected);
}
示例6: TestThatFirstPropertyHasCorrectSpacingBefore
public void TestThatFirstPropertyHasCorrectSpacingBefore()
{
var test = @"
namespace Test
{
public class TestClass
{
private readonly int _someVariable;
}
}";
var expected = new DiagnosticResult
{
Id = "SA1600D",
Message = $"members must be correctly documented.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] { new DiagnosticResultLocation("Test0.cs", 6, 30) }
};
new DocumentationMemberCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);
var fixtest = @"
namespace Test
{
public class TestClass
{
/// <summary>
/// the some variable.
/// </summary>
private readonly int _someVariable;
}
}";
new DocumentationMemberCodeFixVerifier().VerifyCSharpFix(test, fixtest);
}
示例7: TestExpressionBodiedProperties
public void TestExpressionBodiedProperties()
{
var test = @"
namespace ConsoleApplication1
{
class TypeName
{
private IAuthenticationManager AuthenticationManager => this.HttpContext.GetOwinContext().Authentication;
}
}";
var expected = new DiagnosticResult
{
Id = "SA1623D",
Message = $"property documentation: no documentation.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] { new DiagnosticResultLocation("Test0.cs", 6, 40) }
};
new DocumentationPropertyCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);
var fixtest = @"
namespace ConsoleApplication1
{
class TypeName
{
/// <summary>
/// Gets the authentication manager.
/// </summary>
private IAuthenticationManager AuthenticationManager => this.HttpContext.GetOwinContext().Authentication;
}
}";
new DocumentationPropertyCodeFixVerifier().VerifyCSharpFix(test, fixtest);
}
示例8: TestThatMethodContainingParametersHaveParametersDetected
public void TestThatMethodContainingParametersHaveParametersDetected()
{
var test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TypeName
{
/// <summary>
/// build the vogon constructor fleet.
/// </summary>
/// <param name=""parameterOne"">parameter one</param>
public void BuildVogonConstructorFleet(string parameterOne, int parameterItemTwo)
{
}
}
}";
var expected = new DiagnosticResult
{
Id = "SA1612D",
Message = $"method documentation: missing 'parameterItemTwo'.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] { new DiagnosticResultLocation("Test0.cs", 17, 21) }
};
new DocumentationMethodCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);
}
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:34,代码来源:MethodParameterDocumentationDetectionTests.cs
示例9: ClassContainsTwoListsAndAnotherField_ReportDiagnostic
public void ClassContainsTwoListsAndAnotherField_ReportDiagnostic()
{
const string Code = @"
class SomeClass
{
private System.Collections.Generic.List<int> firstList;
private System.Collections.Generic.List<int> secondList;
private int intField;
public SomeClass(int val)
{
this.firstList = new System.Collections.Generic.List<int>();
this.secondList = new System.Collections.Generic.List<int>();
this.intField = val;
}
}";
var firstExpected = new DiagnosticResult
{
Id = "DaVinciOC4",
Message = "Consider wrapping the collection into a separate class.",
Severity = DiagnosticSeverity.Info,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 4, 62)}
};
var secondExpected = new DiagnosticResult
{
Id = "DaVinciOC4",
Message = "Consider wrapping the collection into a separate class.",
Severity = DiagnosticSeverity.Info,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 5, 62) }
};
VerifyCSharpDiagnostic(Code, firstExpected, secondExpected);
}
示例10: ClassContainsListAndField_ReportDiagnostic
public void ClassContainsListAndField_ReportDiagnostic()
{
const string Code = @"
class SomeClass
{
private int someField;
private System.Collections.Generic.List<int> list;
public SomeClass()
{
this.someField = 1;
this.list = new System.Collections.Generic.List<int>();
}
}";
var expected = new DiagnosticResult
{
Id = "DaVinciOC4",
Message = "Consider wrapping the collection into a separate class.",
Severity = DiagnosticSeverity.Info,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 6, 62) }
};
VerifyCSharpDiagnostic(Code, expected);
}
示例11: MethodContainsIfWithElse_OneDiagnosticReported
public void MethodContainsIfWithElse_OneDiagnosticReported()
{
const string Code = @"
class SomeClass
{
private int firstField;
private int secondField;
public void Do()
{
if (true)
{
System.Console.WriteLine();
}
else
{
System.Console.WriteLine();
}
}
}";
var expected = new DiagnosticResult
{
Id = "DaVinciOC2",
Message = "The else keyword should be avoided.",
Severity = DiagnosticSeverity.Info,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 14, 21) }
};
VerifyCSharpDiagnostic(Code, expected);
}
示例12: ConstructorParameterDocumentationAddSingleParameterTest
public void ConstructorParameterDocumentationAddSingleParameterTest()
{
var test = @"
using System;
namespace ConsoleApplication1
{
public class TypeName
{
/// <summary>
/// a description has been provided.
/// line 2 of the description.
/// </summary>
/// <param name=""parameterOne"">there is some documentation</param>
/// <param name=""parameterTwo""></param>
public TypeName(
string parameterOne,
int parameterItemTwo,
string parameterThree)
{
}
}
}";
var expected = new DiagnosticResult
{
Id = "SA1642D",
Message = $"constructors must be correctly documented.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] { new DiagnosticResultLocation("Test0.cs", 13, 16) }
};
new DocumentationConstructorCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);
var fixtest = @"
using System;
namespace ConsoleApplication1
{
public class TypeName
{
/// <summary>
/// Initializes a new instance of the <see cref=""TypeName""/> class.
/// a description has been provided.
/// line 2 of the description.
/// </summary>
/// <param name=""parameterOne"">there is some documentation</param>
/// <param name=""parameterItemTwo"">the parameter item two.</param>
/// <param name=""parameterThree"">the parameter three.</param>
public TypeName(
string parameterOne,
int parameterItemTwo,
string parameterThree)
{
}
}
}";
new DocumentationConstructorCodeFixVerifier().VerifyCSharpFix(test, fixtest);
}
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:57,代码来源:ConstructorParameterDocumentationFixTests.cs
示例13: TestMethodBuildsCorrectMethodSummaryAfterFix
public void TestMethodBuildsCorrectMethodSummaryAfterFix()
{
var test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TypeName
{
public void BuildVogonConstructorFleet()
{
}
}
}";
var expected = new DiagnosticResult
{
Id = "SA1612D",
Message = $"method documentation: no documentation.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] { new DiagnosticResultLocation("Test0.cs", 13, 21) }
};
new DocumentationMethodCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);
var fixtest = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TypeName
{
/// <summary>
/// build the vogon constructor fleet.
/// </summary>
public void BuildVogonConstructorFleet()
{
}
}
}";
new DocumentationMethodCodeFixVerifier().VerifyCSharpFix(test, fixtest);
}
示例14: VerifyMissingQuickFixReplacesDocumentation
public void VerifyMissingQuickFixReplacesDocumentation()
{
var test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TypeName
{
public string TestProperty { get; set; }
}
}";
var expected = new DiagnosticResult
{
Id = "SA1623D",
Message = $"property documentation: no documentation.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[] { new DiagnosticResultLocation("Test0.cs", 13, 23) }
};
this.VerifyCSharpDiagnostic(test, expected);
var fixtest = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TypeName
{
/// <summary>
/// Gets or sets the test property.
/// </summary>
public string TestProperty { get; set; }
}
}";
this.VerifyCSharpFix(test, fixtest);
}
示例15: TestMethod2
public void TestMethod2()
{
var test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TypeName
{
}
}";
var expected = new DiagnosticResult
{
Id = "ConfigureAwaitAnalyzer",
Message = String.Format("Type name '{0}' contains lowercase letters", "TypeName"),
Severity = DiagnosticSeverity.Warning,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 11, 15)
}
};
this.VerifyCSharpDiagnostic(test, expected);
var fixtest = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TYPENAME
{
}
}";
this.VerifyCSharpFix(test, fixtest);
}