Hi, we have a problem (seems like a SonarCloud bug but not sure) related to this new feature.
We have a method “AddRangeToCollection” with 1 uncovered line of code. Sonar tells us that this line is partially covered by tests 4 of 24 conditions. We cannot understand what’s wrong with our unit tests, we think that our tests do cover ALL cases. What is the root cause?
Tests:
[Test]
public void AddRangeToCollectionBasedOnListTest()
{
//Arrange
ICollection<int> list = new List<int> { 1, 3, 4 };
//Act
list.AddRangeToCollection(new[] { 5, 7, 9 });
//Assert
Assert.AreEqual(6, list.Count);
}
[Test]
public void AddEmptyRangeToCollectionBasedOnListTest()
{
//Arrange
ICollection<int> list = new List<int> { 1, 3, 4 };
//Act
list.AddRangeToCollection(Enumerable.Empty<int>());
//Assert
Assert.AreEqual(3, list.Count);
}
[Test]
public void AddRangeToEmptyCollectionBasedOnListTest()
{
//Arrange
ICollection<int> list = new List<int>();
//Act
list.AddRangeToCollection(new[] { 5, 7, 9 });
//Assert
Assert.AreEqual(3, list.Count);
}
[Test]
public void AddRangeToCollectionBasedOnArrayTest()
{
//Arrange
ICollection<int> list = new Collection<int>();
list.Add(1);
//Act
list.AddRangeToCollection(new[] { 5, 7, 9 });
//Assert
Assert.AreEqual(4, list.Count);
}
[Test]
public void AddRangeToCollectionWithNullCollectionThrowsExceptionTest()
{
//Arrange
ICollection<int> list = null;
IEnumerable<int> add = new[] { 5, 7, 9 };
//Assert
Assert.Throws<ArgumentNullException>(() => list.AddRangeToCollection(add));
}
[Test]
public void AddRangeToCollectionWithNullRangeThrowsExceptionTest()
{
//Arrange
ICollection<int> list = new[] { 1, 3, 4 };
IEnumerable<int> add = null;
//Assert
Assert.Throws<ArgumentNullException>(() => list.AddRangeToCollection(add));
}