Created
April 16, 2012 11:24
-
-
Save benfoster/2397891 to your computer and use it in GitHub Desktop.
BDD with MSpec and Machine Fakes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Subject("Domain Events: Raising an event")] | |
public class Raising_an_event | |
{ | |
public class When_an_event_publisher_is_not_defined | |
{ | |
Because of = () | |
=> new TestDomainObject().Start(); | |
It Should_do_nothing = () => { }; | |
} | |
public class When_an_event_publisher_is_defined : WithFakes | |
{ | |
static Action<IDomainEvent> eventPublisher; | |
Because of = () => | |
{ | |
eventPublisher = An<Action<IDomainEvent>>(); | |
DomainEvents.RegisterEventPublisher(eventPublisher); | |
new TestDomainObject().Start(); | |
}; | |
It Should_raise_the_event = () | |
=> eventPublisher.WasToldTo(x => x.Invoke(Param.IsAny<IDomainEvent>())); | |
} | |
public class TestDomainObject | |
{ | |
public void Start() | |
{ | |
DomainEvents.Raise(new TestDomainObjectStartedEvent()); | |
} | |
} | |
public class TestDomainObjectStartedEvent : IDomainEvent | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
Domain Events: Raising an event, When an event publisher is not defined
Domain Events: Raising an event, When an event publisher is defined