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 AssignAsyncVoidLambdaToAction_TestCodeFix(string oldAssertion, string newAssertion) { var oldSource = GenerateCode.AsyncFunctionStatement(oldAssertion); var newSource = GenerateCode.AsyncFunctionStatement(newAssertion); DiagnosticVerifier.VerifyCSharpFix <AsyncVoidCodeFix, AsyncVoidAnalyzer>(oldSource, newSource); }
public void AssignVoidLambdaToAction_TestAnalyzer() { const string statement = "Action action = () => {};"; var source = GenerateCode.AsyncFunctionStatement(statement); 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 DictionaryShouldContainPair_WhenPropertiesOfDifferentVariables_ShouldNotTrigger() { const string assertion = "actual.Should().ContainValue(pair.Value).And.ContainKey(otherPair.Key);"; var source = GenerateCode.DictionaryAssertion(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 StringShouldNotBeEmptyAndShouldNotBeNull_ShouldNotTrigger() { const string assertion = "actual.Should().NotBeEmpty().And.Should().NotBeNull();"; var source = GenerateCode.StringAssertion(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 VerifyCSharpFix <TCodeFixProvider, TDiagnosticAnalyzer>(string oldSourceAssertion, string newSourceAssertion) where TCodeFixProvider : Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider, new() where TDiagnosticAnalyzer : Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, new() { var oldSource = GenerateCode.NumericAssertion(oldSourceAssertion); var newSource = GenerateCode.NumericAssertion(newSourceAssertion); DiagnosticVerifier.VerifyCSharpFix <TCodeFixProvider, TDiagnosticAnalyzer>(oldSource, newSource); }
public void AssignAsyncVoidLambdaToAction_TestAnalyzer(string assertion) { var source = GenerateCode.AsyncFunctionStatement(assertion); DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult { Id = AsyncVoidAnalyzer.DiagnosticId, Message = AsyncVoidAnalyzer.Message, Locations = new DiagnosticResultLocation[] { new DiagnosticResultLocation("Test0.cs", 10, 13) }, Severity = DiagnosticSeverity.Warning }); }
private void VerifyCSharpDiagnostic <TDiagnosticAnalyzer>(string sourceAssertion) where TDiagnosticAnalyzer : Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, new() { var source = GenerateCode.NumericAssertion(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", 10, 13) }, Severity = DiagnosticSeverity.Info }); }
private void VerifyCSharpNoDiagnosticsCodeBlock(string assertion) { var source = GenerateCode.EnumerableCodeBlockAssertion(assertion); DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source); }
public void CollectionShouldHaveElementAt_ShouldIgnoreDictionaryTypes() { string source = GenerateCode.DictionaryAssertion("actual[\"key\"].Should().Be(expectedValue);"); DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source); }