public void SetUp() { EventStore = new FakeEventStore(Given()); var commandHandler = OnHandler(); List <IEvent> expected = null; List <IEvent> produced = null; try { commandHandler.Handle(When()); expected = Then().ToList(); produced = EventStore.PeakChanges().ToList(); } catch (Exception exception) { if (ThenException().Compile()(exception)) { Assert.Pass(); } if (ExpectedException() == null) { Assert.Fail(string.Format("No exception expected but received a {0} exception.", exception.GetType())); } Assert.Fail(string.Format("Expected a {0} exception but received a {1} exception.", ExpectedException().GetType(), exception.GetType())); } finally { Finally(); } CompareMessages(expected, produced); }
public void RunTest() { EventStore = new FakeEventStore(Given()); var commandHandler = BuildCommandHandler(); List <IEvent> expected = Then().ToList(); List <IEvent> produced = new List <IEvent>(); try { commandHandler.Handle(When()); produced = EventStore.PeakChanges().ToList(); } catch (Exception exception) { if (ThenException().Compile()(exception)) { Assert.Pass(); } Type exceptionType = ThenException().Parameters[0].Type; Assert.Fail(string.Format("Received an exception ({0}) that failed the provided predicate.", exceptionType)); } finally { Finally(); } string comparisonResults = EventComparer.Instance.Compare(expected, produced, new[] { "CorrelationId" }); if (comparisonResults == null) { Assert.Pass(); } Assert.Fail(string.Format("Actual events do not match the expected events: {0}{1}", Environment.NewLine, comparisonResults)); }