Exemple #1
0
        public void Test1()
        {
            // given
            var pastStream   = new EventStream(rooms.GetByNumber(12).Id);
            var roomCleaning = new RoomCleaning(pastStream);
            var repo         = new RepositoryStub <RoomCleaning>(roomCleaning);
            // when
            var requestedAt    = DateTime.Today.AddDays(5);
            var commandToApply = new CleaningRequestCommand()
            {
                RequestedAt = requestedAt,
                RoomId      = rooms.GetByNumber(12).Id
            };
            var commandHandler = new CleaningRequestHandler(repo);

            commandHandler.Handle(commandToApply);

            //then
            var expectedEvents = new List <IEvent>()
            {
                new CleaningRequested(rooms.GetByNumber(12).Id, "the boss", requestedAt)
            };

            Check.That(repo.ProducedEvents).ContainsExactly(expectedEvents);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Generating the commands");

            var rooms      = new RoomReferential();
            var commands   = new List <ICommand>();
            var rounds     = 1;
            var roomsCount = 1;

            //var roomsCount = rooms.Count();
            for (int round = 1; round <= rounds; round++)
            {
                commands.AddRange(
                    Enumerable.Range(1, roomsCount)
                    .Select(roomNumber => new CleaningRequestCommand()
                {
                    RequestedAt = DateTime.UtcNow, RoomId = rooms.GetByNumber(roomNumber).Id
                })
                    );
            }


            Console.WriteLine("Dispatching the commands");
            foreach (var command in commands)
            {
                CompositionRoot.DispatchCommand(command);
            }


            Console.ReadLine();
        }