public void PredicateClosureScenarioShouldFail() { var capturedOuterVar = 4; var arr = new[] { 1, 2, 3 }; Verify.ShouldFail(() => arr.ShouldNotContain(i => i < capturedOuterVar, "Some additional context"), errorWithSource: @"arr should not contain an element satisfying the condition (i < capturedOuterVar) but does Additional Info: Some additional context", errorWithoutSource: @"[1, 2, 3] should not contain an element satisfying the condition (i < capturedOuterVar) but does Additional Info: Some additional context"); }
public void CollectionWithACountOtherThanTheSpecifiedCountOfMatchingPredicatesFails() { var collection = new[] { "a", "b", "c", "c" }; Verify.ShouldFail(() => collection.ShouldContain(x => x == "c", 5), #if net35 errorWithSource: @"collection should contain 5 element(s) satisfying the condition (x = ""c"") but does not", errorWithoutSource: @"[""a"", ""b"", ""c"", ""c""] should contain 5 element(s) satisfying the condition (x = ""c"") but does not"); #else errorWithSource: @"collection should contain 5 element(s) satisfying the condition (x == ""c"") but does not", errorWithoutSource: @"[""a"", ""b"", ""c"", ""c""] should contain 5 element(s) satisfying the condition (x == ""c"") but does not"); #endif }
public void EnumerableOfDecimalScenarioShouldFail() { var firstSet = new[] { 1.23m, 2.34m, 3.45001m }; var secondSet = new[] { 1.4301m, 2.34m, 3.45m }; Verify.ShouldFail(() => firstSet.ShouldBe(secondSet, 0.1m, "Some additional context"), errorWithSource: @"firstSet should be within 0.1m of [1.4301m, 2.34m, 3.45m] but was [1.23m, 2.34m, 3.45001m] difference [*1.23m*, 2.34m, *3.45001m*] Additional Info: Some additional context", errorWithoutSource: @"[1.23m, 2.34m, 3.45001m] should be within 0.1m of [1.4301m, 2.34m, 3.45m] but was not difference [*1.23m*, 2.34m, *3.45001m*] Additional Info: Some additional context"); }
public void CollectionWithACountOtherThanTheSpecifiedCountOfMatchingPredicatesFailsWithCustomMessageFunc() { var collection = new[] { "a", "b", "c", "c" }; Verify.ShouldFail(() => collection.ShouldContain(x => x == "c", 5, () => "custom message"), errorWithSource: @"collection should contain 5 element(s) satisfying the condition (x == ""c"") but does not Additional Info: custom message", errorWithoutSource: @"[""a"", ""b"", ""c"", ""c""] should contain 5 element(s) satisfying the condition (x == ""c"") but does not Additional Info: custom message"); }
public void ShouldPass() { int result = new[] { 1 }.ShouldHaveSingleItem(); result.ShouldBe(1); }
public void ShouldPass() { var firstSet = new[] { 1.23m, 2.34m, 3.45001m }; var secondSet = new[] { 1.2301m, 2.34m, 3.45m }; firstSet.ShouldBe(secondSet, 0.01m); }