An EqualConstraint is used to test whether an actual value is equal to the expected value supplied in its constructor.
Syntax Helper | Constructor | Operation |
---|---|---|
Is.EqualTo( object ) | EqualConstraint( null ) | tests that two objects are equal |
Assert.That(2 + 2, Is.EqualTo(4)); Assert.That(2 + 2 == 4); Assert.That(2 + 2, Is.Not.EqualTo(5)); Assert.That(2 + 2 != 5); Assert.That( 5.0, Is.EqualTo( 5 ); Assert.That( 2.1 + 1.2, Is.EqualTo( 3.3 ).Within( .0005 ); Assert.That( double.PositiveInfinity, Is.EqualTo( double.PositiveInfinity ) ); Assert.That( double.NegativeInfinity, Is.EqualTo( double.NegativeInfinity ) ); Assert.That( double.NaN, Is.EqualTo( double.NaN ) ); int[] i3 = new int[] { 1, 2, 3 }; double[] d3 = new double[] { 1.0, 2.0, 3.0 }; int[] iunequal = new int[] { 1, 3, 2 }; Assert.That(i3, Is.EqualTo(d3)); Assert.That(i3, Is.Not.EqualTo(iunequal)); int array2x2 = new int[,] { { 1, 2 } { 3, 4 } }; int array4 = new int[] { 1, 2, 3, 4 }; Assert.That( array2x2, Is.EqualTo( array4 ) ); // Fails Assert.That( array2x2, Is.EqualTo( array4 ).AsCollection ); // Succeeds Assert.That( "Hello!", Is.EqualTo( "HELLO!" ).IgnoreCase ); string[] expected = new string[] { "Hello", World" }; string[] actual = new string[] { "HELLO", "world" }; Assert.That( actual, Is.EqualTo( expected ).IgnoreCase; // Using inheritance Expect( i3, EqualTo( d3 ) ); Expect( i3, Not.EqualTo( iunequal ) );