diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Invocation.cs b/analyzers/tests/SonarAnalyzer.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Invocation.cs index 7a158d2caf5..7ceaeb25a75 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Invocation.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Invocation.cs @@ -750,11 +750,17 @@ public void Invocation_InformationIsNothing_NoTrackedSymbol() } [DataTestMethod] - [DataRow("arg != null")] - [DataRow("arg is not null")] - [DataRow("arg is { }")] - public void Invocation_DebugAssert_LearnsNotNull_Simple(string expression) => - DebugAssertValues(expression).Should().HaveCount(1).And.ContainSingle(x => x.HasConstraint(ObjectConstraint.NotNull)); + [DataRow("arg != null", "object")] + [DataRow("arg != null", "int?")] + [DataRow("arg != null", "bool?")] + [DataRow("arg is not null", "object")] + [DataRow("arg is not null", "int?")] + [DataRow("arg is not null", "bool?")] + [DataRow("arg is { }", "object")] + [DataRow("arg is { }", "int?")] + [DataRow("arg is { }", "bool?")] + public void Invocation_DebugAssert_LearnsNotNull_Simple(string expression, string argType) => + DebugAssertValues(expression, argType).Should().SatisfyRespectively(x => x.Should().HaveOnlyConstraint(ObjectConstraint.NotNull)); [TestMethod] public void Invocation_DebugAssert_LearnsNotNull_AndAlso() => @@ -823,6 +829,18 @@ public static void Assert() { } new SETestContext(code, AnalyzerLanguage.CSharp, Array.Empty()).Validator.ValidateTagOrder("End"); } + [DataTestMethod] + [DataRow("int?")] + [DataRow("bool?")] + public void Invocation_DebugAssert_NullableHasValue_Simple(string argType) => + DebugAssertValues("arg.HasValue", argType).Should().SatisfyRespectively(x => x.Should().HaveOnlyConstraint(ObjectConstraint.NotNull)); + + [DataTestMethod] + [DataRow("int?")] + [DataRow("bool?")] + public void Invocation_DebugAssert_NullableHasValue_Binary(string argType) => + DebugAssertValues("arg.HasValue == true", argType).Should().SatisfyRespectively(x => x.Should().HaveOnlyConstraint(ObjectConstraint.NotNull)); + private static SymbolicValue[] DebugAssertValues(string expression, string argType = "object") { var code = $@"