Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested property calls across different mocks #56

Open
dtchepak opened this issue Sep 5, 2011 · 1 comment
Open

Nested property calls across different mocks #56

dtchepak opened this issue Sep 5, 2011 · 1 comment
Assignees
Labels
bug Reported problem with NSubstitute behaviour

Comments

@dtchepak
Copy link
Member

dtchepak commented Sep 5, 2011


    public class Issue56_NestedPropertyCalls
    {
        public interface IFoo
        {
            string StringProperty { get; set; }
        }

        [Test]
        public void Nested_calls_to_properties()
        {
            const string expectedResult = "asldkfjdlkfj dslkfj";
            var sub0 = Substitute.For<IFoo>();
            var sub1 = Substitute.For<IFoo>();
            sub1.StringProperty = expectedResult;

            sub0.StringProperty.Returns(sub1.StringProperty);

            //FAILS: Is equal to ""
            //This is because Returns(..) can't tell it is meant to apply to sub0. Applies to last call (sub1) instead.
            Assert.That(sub0.StringProperty, Is.EqualTo(expectedResult));
        }

        [Test]
        public void Non_nested_calls()
        {
            const string expectedResult = "asldkfjdlkfj dslkfj";
            var sub0 = Substitute.For<IFoo>();
            var sub1 = Substitute.For<IFoo>();
            sub1.StringProperty = expectedResult;

            var prop = sub1.StringProperty;
            sub0.StringProperty.Returns(prop);

            //PASSES
            Assert.That(sub0.StringProperty, Is.EqualTo(expectedResult));
        }
    }
@ghost ghost assigned dtchepak Sep 5, 2011
@AlexanderSher
Copy link

I think that issue can be fixed by restoring previous values for last call router / last call at the end of ReturnConfiguredResultHandler.Handle execution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reported problem with NSubstitute behaviour
Projects
None yet
Development

No branches or pull requests

2 participants