public void CountWithPredicate() { const string assertion = "actual.Count(d => d.Message.Contains(\"a\")).Should().Be(2);"; var source = GenerateCode.EnumerableCodeBlockAssertion(assertion); DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source); }
public void PropertyOfElementAtShouldBe_ShouldNotTriggerDiagnostic() { const string assertion = "actual.ElementAt(0).Message.Should().Be(\"test\");"; var source = GenerateCode.EnumerableCodeBlockAssertion(assertion); DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source); }
public void PropertyOfIndexerShouldBe_ShouldNotThrowException() { const string assertion = "actual[0].Message.Should().Be(\"test\");"; var source = GenerateCode.EnumerableCodeBlockAssertion(assertion); DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source); }
public void AssertionCallMultipleMethodWithTheSameNameAndArguments() { const string assertion = "actual.Should().Contain(d => d.Message.Contains(\"a\")).And.Contain(d => d.Message.Contains(\"c\"));"; var source = GenerateCode.EnumerableCodeBlockAssertion(assertion); DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source); }
public void NestedAssertions_ShouldNotTrigger() { const string declaration = "var nestedList = new List<List<int>>();"; const string assertion = "nestedList.Should().NotBeNull().And.ContainSingle().Which.Should().NotBeEmpty();"; var source = GenerateCode.EnumerableCodeBlockAssertion(declaration + assertion); DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source); }
private void VerifyCSharpFixCodeBlock<TCodeFixProvider, TDiagnosticAnalyzer>(string oldSourceAssertion, string newSourceAssertion) where TCodeFixProvider : Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider, new() where TDiagnosticAnalyzer : Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, new() { var oldSource = GenerateCode.EnumerableCodeBlockAssertion(oldSourceAssertion); var newSource = GenerateCode.EnumerableCodeBlockAssertion(newSourceAssertion); DiagnosticVerifier.VerifyCSharpFix<TCodeFixProvider, TDiagnosticAnalyzer>(oldSource, newSource); }
private void VerifyCSharpDiagnosticCodeBlock<TDiagnosticAnalyzer>(string sourceAssertion) where TDiagnosticAnalyzer : Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, new() { var source = GenerateCode.EnumerableCodeBlockAssertion(sourceAssertion); var type = typeof(TDiagnosticAnalyzer); var diagnosticId = (string)type.GetField("DiagnosticId").GetValue(null); var message = (string)type.GetField("Message").GetValue(null); DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult { Id = diagnosticId, Message = message, Locations = new DiagnosticResultLocation[] { new DiagnosticResultLocation("Test0.cs", 11,13) }, Severity = DiagnosticSeverity.Info }); }
private void VerifyCSharpNoDiagnosticsCodeBlock(string assertion) { var source = GenerateCode.EnumerableCodeBlockAssertion(assertion); DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source); }