Shouldly
Search…
Contain

ShouldContain

1
var mrBurns = new Person { Name = "Mr.Burns", Salary = 3000000 };
2
var kentBrockman = new Person { Name = "Kent Brockman", Salary = 3000000 };
3
var homer = new Person { Name = "Homer", Salary = 30000 };
4
var millionaires = new List<Person> { kentBrockman, homer };
5
millionaires.ShouldContain(mrBurns);
Copied!
Exception
1
millionaires
2
should contain
3
Mr.Burns
4
but was actually
5
[Kent Brockman, Homer]
Copied!

With Predicate

1
var homer = new Person { Name = "Homer", Salary = 30000 };
2
var moe = new Person { Name = "Moe", Salary = 20000 };
3
var barney = new Person { Name = "Barney", Salary = 0 };
4
var millionaires = new List<Person> { homer, moe, barney };
5
millionaires.ShouldContain(m => m.Salary > 1000000);
Copied!
Exception
1
millionaires
2
should contain an element satisfying the condition
3
(m.Salary > 1000000)
4
but does not
Copied!

ShouldNotContain

1
var homerSimpson = new Person { Name = "Homer" };
2
var homerGlumplich = new Person { Name = "Homer" };
3
var lenny = new Person { Name = "Lenny" };
4
var carl = new Person { Name = "carl" };
5
var clubOfNoHomers = new List<Person> { homerSimpson, homerGlumplich, lenny, carl };
6
clubOfNoHomers.ShouldNotContain(homerSimpson);
Copied!
Exception
1
clubOfNoHomers
2
should not contain
3
Homer
4
but was actually
5
[Homer, Homer, Lenny, carl]
Copied!

With Predicate

1
var mrBurns = new Person { Name = "Mr.Burns", Salary = 3000000 };
2
var kentBrockman = new Person { Name = "Homer", Salary = 3000000 };
3
var homer = new Person { Name = "Homer", Salary = 30000 };
4
var millionaires = new List<Person> { mrBurns, kentBrockman, homer };
5
millionaires.ShouldNotContain(m => m.Salary < 1000000);
Copied!
Exception
1
millionaires
2
should not contain an element satisfying the condition
3
(m.Salary < 1000000)
4
but does
Copied!
Last modified 1yr ago