int Run() { var testTypes = typeof(AccountShouldBeLockedAfterThreeOverdraws).Assembly.GetTypes().Where(x => typeof(TestBase).IsAssignableFrom(x) && x.IsAbstract == false); foreach (var type in testTypes) { var test = Activator.CreateInstance(type) as TestBase; var newMessages = new List <object>(); var bus = new MessageBus(); bus.RegisterHandler <object>(newMessages.Add); var eventStore = new InMemoryEventStore(bus, test.GivenTheseEvents()); var repository = new DomainRepository(eventStore); test.RegisterHandler(bus, repository); printGivens(type, test); var command = test.WhenThisHappens(); Exception exception = null; var expectedException = test.ThisExceptionShouldOccur(); try { bus.Handle(command); } catch (Exception e) { exception = e; } var foundException = printException(expectedException, exception, command); if (foundException) { continue; } ; printThens(test.TheseEventsShouldOccur().ToList(), newMessages, command); Console.WriteLine(); Console.WriteLine(new string('=', 40)); Console.WriteLine(); } return(_suuccess ? 0 : -1); }
public void Test() { var newMessages = new List<object>(); var bus = new MessageBus(); bus.RegisterHandler<object>(newMessages.Add); var eventStore = new InMemoryEventStore(bus, GivenTheseEvents()); var repository = new DomainRepository(eventStore); RegisterHandler(bus, repository); bus.Handle(WhenThisHappens()); var expected = TheseEventsShouldOccur(); Assert.AreEqual(expected.Count(), newMessages.Count); }
public void Test() { var newMessages = new List <object>(); var bus = new MessageBus(); bus.RegisterHandler <object>(newMessages.Add); var eventStore = new InMemoryEventStore(bus, GivenTheseEvents()); var repository = new DomainRepository(eventStore); RegisterHandler(bus, repository); try { bus.Handle(WhenThisHappens()); } catch (Exception e) { var expectedException = ThisExceptionShouldOccur(); if (expectedException == null) { Assert.Fail(e.Message); } if (expectedException.GetType().IsAssignableFrom(e.GetType())) { Assert.AreEqual(expectedException.Message, e.Message); return; } Assert.Fail("Expected exception of type {0} with message {1} but got exception of type {2} with message {3}", expectedException.GetType(), expectedException.Message, e.GetType(), e.Message); } var expectedEvents = TheseEventsShouldOccur().ToList(); var comparer = new CompareObjects(); if (!comparer.Compare(expectedEvents, newMessages)) { Assert.Fail(comparer.DifferencesString); } }
public void Test() { var newMessages = new List<object>(); var bus = new MessageBus(); bus.RegisterHandler<object>(newMessages.Add); var eventStore = new InMemoryEventStore(bus, GivenTheseEvents()); var repository = new DomainRepository(eventStore); RegisterHandler(bus, repository); try { bus.Handle(WhenThisHappens()); } catch(Exception e) { var expectedException = ThisExceptionShouldOccur(); if(expectedException == null) Assert.Fail(e.Message); if(expectedException.GetType().IsAssignableFrom(e.GetType())) { Assert.AreEqual(expectedException.Message, e.Message); return; } Assert.Fail("Expected exception of type {0} with message {1} but got exception of type {2} with message {3}", expectedException.GetType(), expectedException.Message, e.GetType(), e.Message); } var expectedEvents = TheseEventsShouldOccur().ToList(); var comparer = new CompareObjects(); if(!comparer.Compare(expectedEvents, newMessages)) { Assert.Fail(comparer.DifferencesString); } }
int Run() { var testTypes = typeof(AccountShouldBeLockedAfterThreeOverdraws).Assembly.GetTypes().Where(x => typeof(TestBase).IsAssignableFrom(x) && x.IsAbstract == false); foreach (var type in testTypes) { var test = Activator.CreateInstance(type) as TestBase; var newMessages = new List<object>(); var bus = new MessageBus(); bus.RegisterHandler<object>(newMessages.Add); var eventStore = new InMemoryEventStore(bus, test.GivenTheseEvents()); var repository = new DomainRepository(eventStore); test.RegisterHandler(bus, repository); printGivens(type, test); var command = test.WhenThisHappens(); Exception exception = null; var expectedException = test.ThisExceptionShouldOccur(); try { bus.Handle(command); } catch(Exception e) { exception = e; } var foundException = printException(expectedException, exception, command); if(foundException) continue; ; printThens(test.TheseEventsShouldOccur().ToList(), newMessages, command); Console.WriteLine(); Console.WriteLine(new string('=', 40)); Console.WriteLine(); } return _suuccess ? 0 : -1; }