I am running c# tests using ShouldBe and I have this code:
int x = 3;
int y = 3;
x.ShouldBeSameAs(y);
Problem is it throws exception:
An exception of type 'Shouldly.ShouldAssertException' occurred in Shouldly.dll but was not handled in user code
Additional information: x
should be same as
3
but was
3
How can I test equality of to integers with ShouldBe?
shouldly.dll
is, but it seems to be comparing references. And since those references are not the same (x is not the same object as y) your assert fails. A quick look at the docs makes me wonder why you don;t use x.ShouldBe(y) in order to compare values. – IvoryAssert.AreEqual()
? – Skidwayint value = 3; object boxX = value; object boxY = boxX; boxX.ShouldBeSameAs(boxY);
. HereboxX
andboxY
are reference to the same box (instance of a boxed value). – Chromatism