-
Notifications
You must be signed in to change notification settings - Fork 84
Methods Run in Incorrect Order When Using Method Naming Conventions #266
Copy link
Copy link
Open
Description
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;
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels