Ejemplo n.º 1
0
        public void RunTest(IEnumerable <ICommand> commands)
        {
            Setup();

            var repository = new FakeEventRepository();

            repository.InitialEvents = Given();

            var queryDataStore = new FakeQueryDataStore();
            var queryService   = new QueryHandlerFactory(queryDataStore);

            var commandRepository = new Mock <ICommandRepository>();

            HandleEvents(repository.InitialEvents, queryDataStore);

            Exception caughtException       = null;
            var       commandHandlerFactory = new CommandHandlerFactory(repository, queryService, commandRepository.Object);

            var generatedEvents = new List <IEvent>();

            foreach (var command in commands)
            {
                try
                {
                    commandHandlerFactory.ExecuteCommand(command);
                }
                catch (Exception e)
                {
                    if (ExpectedException() == null)
                    {
                        throw;
                    }

                    caughtException = e;
                }

                HandleEvents(repository.EventList, queryDataStore);
                generatedEvents.AddRange(repository.EventList);
                repository.InitialEvents = new List <IEvent>(repository.InitialEvents).Concat(repository.EventList).ToList();
                repository.EventList.Clear();
            }

            if (caughtException != null || ExpectedException() != null)
            {
                if (caughtException != null && ExpectedException() != null)
                {
                    Assert.AreEqual(ExpectedException().GetType(), caughtException.GetType());
                }
                else
                {
                    Assert.Fail("There was an Expected Exception but none was thrown.");
                }
            }

            ValidateExpectedEvents(ExpectedEvents(), generatedEvents);
        }
Ejemplo n.º 2
0
        public void RunTest(ICommand command)
        {
            Setup();

            var repository = new FakeEventRepository();

            repository.InitialEvents = Given();

            var queryDataStore = new FakeQueryDataStore();
            var queryService   = new QueryHandlerFactory(queryDataStore);

            var commandRepository = new Mock <ICommandRepository>();

            HandleEvents(repository.InitialEvents, queryDataStore);

            Exception caughtException       = null;
            var       commandHandlerFactory = new CommandHandlerFactory(repository, queryService, commandRepository.Object);

            try
            {
                commandHandlerFactory.ExecuteCommand(command);
            }
            catch (Exception e)
            {
                if (ExpectedException() == null)
                {
                    throw;
                }

                caughtException = e;
            }

            if (caughtException != null || ExpectedException() != null)
            {
                if (caughtException != null && ExpectedException() != null)
                {
                    Assert.AreEqual(ExpectedException().GetType(), caughtException.GetType());
                }
                else
                {
                    Assert.Fail("There was an Expected Exception but none was thrown.");
                }
            }

            ValidateExpectedEvents(ExpectedEvents(), repository.EventList);
        }