public void ShouldBe() { Should.Error( () => "expected".ShouldBe("actual"), "() => \"expected\" should be \"actual\" but was \"expected\"" ); Should.Error( () => 2.ShouldBe(1), "() => 2 should be 1 but was 2" ); Should.Error( () => (new[] { 1, 2, 3 }).ShouldBe(new[] { 2, 2, 3 }), "() => (new[] { 1, 2, 3 }) should be [2, 2, 3] but was [1, 2, 3] difference [*1*, 2, 3]" ); Should.Error( () => new UncomparableClass("ted").ShouldBe(new UncomparableClass("bob")), "() => new UncomparableClass(\"ted\") should be bob but was ted" ); Should.Error(() => "SamplE".ShouldBe("sAMPLe", Case.Sensitive), "'SamplE' should be 'sAMPLe' but was 'SamplE'"); Should.Error(() => new[] { 2, 1 }.ShouldBe(new[] { 1, 2 }), "new[] { 2, 1 } should be [1, 2] but was [2, 1] difference [*2*, *1*]" ); var aWidget = new Widget { Name = "Joe", Enabled = true }; var bWidget = new Widget { Name = "Joeyjojoshabadoo Jr", Enabled = true }; IEnumerable<Widget> aEnumerable = aWidget.ToEnumerable(); IEnumerable<Widget> bEnumerable = new[] { bWidget }; Should.Error(() => aEnumerable.ShouldBe(bEnumerable), "aEnumerable should be [Name(Joeyjojoshabadoo Jr) Enabled(True)] but was [Name(Joe) Enabled(True)] difference [*Name(Joe) Enabled(True)*]" ); IEnumerable<int> something = null; Should.Error( () => something.ShouldBe(new[] { 1, 2, 3 }), "() => something should be [1, 2, 3] but was null"); Action a = () => 1.ShouldBe(2); Should.Error(a, "Action a = () => 1 should be 2 but was 1"); Expression<Action> lambda = () => 1.ShouldBe(2); Should.Error(lambda.Compile(), "The provided expression should be 2 but was 1"); }
public void ShouldBe_EnumerableTypesOfDifferentRuntimeTypes_ShouldShowDifferences() { var a = new Widget { Name = "Joe", Enabled = true }; var b = new Widget { Name = "Joeyjojoshabadoo Jr", Enabled = true }; IEnumerable<Widget> aEnumerable = a.ToEnumerable(); IEnumerable<Widget> bEnumerable = new[] { b }; Should.Error(() => aEnumerable.ShouldBe(bEnumerable), "aEnumerable should be [Name(Joeyjojoshabadoo Jr) Enabled(True)] but was [Name(Joe) Enabled(True)] difference [*Name(Joe) Enabled(True)*]" ); }
public void Shouldly_ShouldThrowException() { var widget = new Widget(); Should.Throw<ArgumentOutOfRangeException>(() => widget.Twist(-1)); }
public void Shouldly_ShouldNotThrowException() { var widget = new Widget(); Should.NotThrow(() => widget.Twist(5)); }
public void Shouldly_ShouldErrorIfNoExceptionWasThrown() { var widget = new Widget(); TestHelpers.Should.Error( () => Should.Throw<ArgumentOutOfRangeException>(() => widget.Twist(5)), "`widget.Twist(5)` should throw System.ArgumentOutOfRangeException but did not"); }
public void Shouldly_ShouldErrorIfCatchingExceptionOfWrongType() { var widget = new Widget(); TestHelpers.Should.Error( () => Should.Throw<ArgumentOutOfRangeException>(() => widget.Twist(-2)), "`widget.Twist(-2)` should throw System.ArgumentOutOfRangeException but threw System.InvalidOperationException"); }