1

Resolved

Overwriting Expectations

description

Hi,
recently came across the problem that I cannot overwrite my expectations:
[Test]
        public void Test()
        {
            var coordiante = Mock.Interface<ICoordinate>();
            Expect.PropertyGet(() => coordiante.X).Returns(0);
            Expect.PropertyGet(() => coordiante.X).Returns(1);

            Assert.AreEqual(1,coordiante.X); //fails because it returns 0
        }
Background:
I need to test a algorithm, that depend on a object with multiple properties. For most of the test cases the properties are the same, so I set them up in the SetUp method. Within a test, I only want to adjust same properties needed. So I need to overwrite the Returns() I set up in the SetUp method.

I can simply move the initialization to the test, but my test became more verbose and the SetUp method useless.

comments

mikwal wrote Jun 26, 2014 at 12:43 PM

Default expectations are matched in top down order as specified, so the call will always match the first PropertyGet of X in this case.

But you should be able to call Expect.WithHigherPrecedence.PropertyGet(() => coordiante.X).Returns(1); to put it on top of the "match list"

/Mikael