Skip to content

Instantly share code, notes, and snippets.

@benfoster
Created April 16, 2012 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benfoster/2397891 to your computer and use it in GitHub Desktop.
Save benfoster/2397891 to your computer and use it in GitHub Desktop.
BDD with MSpec and Machine Fakes
[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
{
}
}
@benfoster
Copy link
Author

Output:

Domain Events: Raising an event, When an event publisher is not defined

  • Should do nothing

Domain Events: Raising an event, When an event publisher is defined

  • Should raise the event

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment