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

Change arrangement #17

Closed
anton-yashin opened this issue Feb 9, 2021 · 1 comment
Closed

Change arrangement #17

anton-yashin opened this issue Feb 9, 2021 · 1 comment

Comments

@anton-yashin
Copy link
Contributor

Hi!

LightMock can't change arrangements? Like this:

    public class ArrangementTests
    {
    //...
        [Fact]
        public void Arrange_ChangeReturnValue()
        {
            var mockContext = new MockContext<IFoo>();
            var fooMock = new FooMock(mockContext);

            mockContext.Arrange(f => f.Execute()).Returns("1");
            Assert.Equal("1", fooMock.Execute());

            mockContext.Arrange(f => f.Execute()).Returns("2");
            Assert.Equal("2", fooMock.Execute());
        }

        [Fact]
        public void Arrange_ChangeCallback()
        {
            int firstResult = 0;
            int secondResult = 0;
            var mockContext = new MockContext<IFoo>();
            var fooMock = new FooMock(mockContext);

            mockContext.Arrange(f => f.Execute(The<int>.IsAnyValue)).Callback<int>(i => firstResult = i);
            fooMock.Execute(1);
            mockContext.Arrange(f => f.Execute(The<int>.IsAnyValue)).Callback<int>(i => secondResult = i);
            fooMock.Execute(2);

            Assert.Equal(1, firstResult);
            Assert.Equal(2, secondResult);
        }

        [Fact]
        public void Arrange_ChangeException()
        {
            var mockContext = new MockContext<IFoo>();
            var fooMock = new FooMock(mockContext);

            mockContext.Arrange(f => f.Execute(The<int>.IsAnyValue)).Throws<System.ArgumentNullException>();
            Assert.Throws<System.ArgumentNullException>(() => fooMock.Execute(1));

            mockContext.Arrange(f => f.Execute(The<int>.IsAnyValue)).Throws<System.ArgumentOutOfRangeException>();
            Assert.Throws<System.ArgumentOutOfRangeException>(() => fooMock.Execute(1));
        }

        [Fact]
        public void Arrange_SimulatousReturnAndCallback()
        {
            string firstResult = "";
            var mockContext = new MockContext<IFoo>();
            var fooMock = new FooMock(mockContext);

            mockContext.Arrange(f => f.Execute(The<string>.IsAnyValue)).Returns("hi");
            mockContext.Arrange(f => f.Execute(The<string>.IsAnyValue)).Callback<string>(i => firstResult = i);

            var result = fooMock.Execute("hello");

            Assert.Equal("hi", result);
            Assert.Equal("hello", firstResult);
        }
    }

Tests abowe do not pass. Is this behavior intended? Can it be changed? I can write a pull request that changes this behavior.

Thanks.

@anton-yashin
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant