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

Methods Run in Incorrect Order When Using Method Naming Conventions #266

Open
mylifeandcode opened this issue May 9, 2018 · 0 comments
Open

Comments

@mylifeandcode
Copy link

In the following class, the Then method (ThenTheMessageShouldBeRetrievedFromTheContext()) runs first instead of the Given method (GivenTheContextIsValid()) (please ignore dumb debugging code in place only for breakpoints ;) ):

    public class ShouldLogMessageBodyOnPreReceive
    {
        private Core.Observers.ReceiveObserver sut;
        private Mock<ILogger> mockLog;
        private Mock<ReceiveContext> context;

        public ShouldLogMessageBodyOnPreReceive()
        {
            sut = new Core.Observers.ReceiveObserver();
            mockLog = new Mock<ILogger>();
            Core.Observers.ReceiveObserver.Log = mockLog.Object;
        }

        void GivenTheContextIsValid()
        {
            int x = 1;
        }

        void WhenTheMethodIsInvoked()
        {
            int x = 1;
        }

        void ThenTheMessageShouldBeRetrievedFromTheContext()
        {
            int x = 0;
        }

        void AndTheMessageShouldBeLogged()
        {
            int x = 0;
        }

    }

Renaming the then method from ThenTheMessageShouldBeRetrievedFromTheContext to ThenWeShouldGetTheMessageBody corrects the issue and the methods run in the correct order:

    public class ShouldLogMessageBodyOnPreReceive
    {
        private Core.Observers.ReceiveObserver sut;
        private Mock<ILogger> mockLog;
        private Mock<ReceiveContext> context;

        public ShouldLogMessageBodyOnPreReceive()
        {
            sut = new Core.Observers.ReceiveObserver();
            mockLog = new Mock<ILogger>();
            Core.Observers.ReceiveObserver.Log = mockLog.Object;
        }

        void GivenTheContextIsValid()
        {
            int x = 1;
        }

        void WhenTheMethodIsInvoked()
        {
            int x = 1;
        }

        void ThenWeShouldGetTheMessageBody()
        {
            int x = 0;
        }

        void AndTheMessageShouldBeLogged()
        {
            int x = 0;
        }

    }
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