Caveat: I'm not an expert at this and I work in isolation, but this is my personal take based on several months of trial and error.
There's an overload of the subject attribute [Subject(Type subjectType, string subject)]
Perhaps you could use the string parameter to document your concern, so perhaps you'd use something like:
[Subject(typeof(MuchGoodServiceOrchestrator), "Logged in"]
-and-
[Subject(typeof(MuchGoodServiceOrchestrator), "Not logged in"]
Expanding on that a bit, if you are using the convention
- Given the system is in this particular state
- When this interesting thing happens
- Then these are the consequences
That is another way of expressing the Arrange, Act, Assert pattern. The Given (Arrange) is your context, the preconditions for the test. The When (Act) is the activity you're testing and the Then (Assert) is where you verify expected behaviour.
in MSpec, I usually use this pattern:
public class when_doing_domething : with_context
{
It should_behave_like_this; // One or more assertions.
It should_also_behave_like_this;
}
So to try to use terms from your problem domain:
public class with_logged_in_user
{
protected static User User;
protected static MuchGoodServiceOrchestrator sut;
// Arrange
Establish context =()=>
{
User = new User() { /* initialize the User object as a logged in user */ };
sut = new MuchGoodServiceOrchestrator(User); // Dependency injection
};
}
public class with_anonymous_user
{
protected static User User;
protected static MuchGoodServiceOrchestrator sut;
// Arrange
Establish context =()=>
{
User = new User() { /* initialize the User object as anonymous or not logged in */ };
sut = new MuchGoodServiceOrchestrator(User); // Dependency injection
};
}
[Subject(typeof(MuchGoodServiceOrchestrator), "Logged in")]
public class when_viewing_things_as_a_logged_in_user : with_logged_in_user
{
// Act
Because of =()=> sut.CallTheCodeToBeTested();
// Assert
It should_do_this =()=> sut.Member.ShouldEqual(expectedValue); // Assert
}
[Subject(typeof(MuchGoodServiceOrchestrator), "Not logged in")]
public class when_viewing_things_while_not_logged_in : with_anonymous_user
{
// Etc...
}