Skip to content

Instantly share code, notes, and snippets.

@chrisnicola
Created June 17, 2010 23:59
Show Gist options
  • Save chrisnicola/442983 to your computer and use it in GitHub Desktop.
Save chrisnicola/442983 to your computer and use it in GitHub Desktop.
public abstract class DomainEventTestBase<T> : IEventHandler<T> where T : DomainEvent
{
protected T Result;
protected InProcessEventBus DomainEventBus;
#region IEventHandler<T> Members
public void Handle(T evnt)
{
Result = evnt;
}
#endregion
[TestFixtureSetUp]
public void GenericOneTimeSetup()
{
DomainEventBus = new InProcessEventBus();
NcqrsEnvironment.SetDefault<IEventBus>(DomainEventBus);
DomainEventBus.RegisterHandler(this);
}
}
public abstract class StudyDomainTestBase<T> : DomainEventTestBase<T> where T : DomainEvent
{
protected CoreStudy Study;
protected Guid studyId = Guid.NewGuid();
protected Guid accountId = Guid.NewGuid();
protected Guid programId = Guid.NewGuid();
protected Guid userId = Guid.NewGuid();
protected string studyName = "Name";
protected string studyType = "Type";
protected bool isPublishedStudy = true;
[SetUp]
public void BaseSetUp()
{
new UnitOfWorkFactory().CreateUnitOfWork();
Study = new CoreStudy();
}
[TearDown]
public void BaseTearDown()
{
UnitOfWork.Current.Dispose();
}
}
[TestFixture]
public class when_a_study_receives_a_response : StudyDomainTestBase<StudyResponseRecorded>
{
private string _responseType;
private Guid _respondentId;
[SetUp]
public void SetUp()
{
_responseType = "Response";
_respondentId = Guid.NewGuid();
Study.RecordNewResponse(_respondentId, _responseType);
UnitOfWork.Current.Accept();
}
[Test]
public void it_raises_a_response_recorded_event()
{
Assert.AreEqual((object) Result.RespondantId, (object) _respondentId);
Assert.AreEqual(Result.ResponseType, _responseType);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment