public void throw_error_if_update_location_that_is_not_available()
        {
            // given
            var trainingId = Guid.NewGuid();

            var locationId1 = Guid.NewGuid();
            var locationId2 = Guid.NewGuid();

            var trainerId = Guid.NewGuid();

            var sessionId  = Guid.NewGuid();
            var dispatcher = new EventDispatcher();

            var eventStore = new FakeEventStore();

            eventStore.Save(new LocationCreated(locationId1, 1, "Lyon", "test", 5));
            eventStore.Save(new LocationCreated(locationId2, 1, "Paris", "test", 5));
            eventStore.Save(new SessionPlanned(sessionId, 1, trainingId, new DateTime(2018, 1, 1), 5, 10, locationId1, trainerId));
            eventStore.Save(new LocationAssigned(locationId1, 2, new DateTime(2017, 12, 21), 5));
            eventStore.Save(new LocationAssigned(locationId2, 2, new DateTime(2017, 12, 20), 10));
            var eventBus = new EventBus(dispatcher, eventStore);

            // when
            Action action = () => new UpdateSession(eventBus).Execute(sessionId, trainingId, new DateTime(2017, 12, 21), 5, 10, locationId2, trainerId);

            action.ShouldThrow <LocationAlreadyAssignedException>();
        }
예제 #2
0
        public void release_session_seat_on_releaseSeat_command()
        {
            var sessionId            = Guid.NewGuid();
            var seatId               = Guid.NewGuid();
            var notificatioManagerId = Guid.NewGuid();
            var studentId            = Guid.NewGuid();

            var fakeStorage = new FakeEventStore();

            fakeStorage.Save(new SessionPlanned(sessionId, 1, Guid.NewGuid(), new DateTime(2018, 1, 9), 1, 5, null, null));
            fakeStorage.Save(new NotificationManagerCreated(notificatioManagerId, 1, sessionId));
            fakeStorage.Save(new SessionSeatBooked(sessionId, 2, Guid.NewGuid()));
            fakeStorage.Save(new SeatCreated(seatId, 3, sessionId, studentId, Guid.NewGuid()));

            var notifQueries = new FakeNotificationQueries();

            notifQueries.AddNotificationManager(sessionId, notificatioManagerId);

            var bus = new EventBus(new EventDispatcher(), fakeStorage);

            new ReleaseSeat(bus, notifQueries).Execute(sessionId, seatId, "essai");

            fakeStorage.GetEvents(sessionId).Should().Contain(new SessionSeatReleased(sessionId, 1, studentId));
            fakeStorage.GetEvents(seatId).Should().Contain(new SeatCanceled(seatId, 1, "essai"));
        }
        public void throw_error_if_create_convention_with_not_same_societe()
        {
            var sessionId             = Guid.NewGuid();
            var notificationManagerId = Guid.NewGuid();
            var seat1Id = Guid.NewGuid();
            var seat2Id = Guid.NewGuid();

            var eventStore = new FakeEventStore();

            eventStore.Save(new SeatCreated(seat1Id, 1, sessionId, Guid.NewGuid(), Guid.NewGuid()));
            eventStore.Save(new SeatCreated(seat2Id, 1, sessionId, Guid.NewGuid(), Guid.NewGuid()));
            eventStore.Save(new SeatValided(seat1Id, 2));
            eventStore.Save(new SeatValided(seat2Id, 2));
            eventStore.Save(new NotificationManagerCreated(notificationManagerId, 1, sessionId));

            var queries = new FakeNotificationQueries();

            queries.AddNotificationManager(sessionId, notificationManagerId);

            var    createConvention = new CreateAgreement(new EventBus(new EventDispatcher(), eventStore), new FakeAgreementQueries(), queries);
            Action action           = () => createConvention.Execute(Guid.NewGuid(), new List <Guid>()
            {
                seat1Id, seat2Id
            }, AgreementType.Free);

            action.ShouldThrow <AgreementCompanyException>();
        }
        public void throw_error_if_update_trainer_that_is_not_available()
        {
            // given
            var trainingId = Guid.NewGuid();

            var trainerId1 = Guid.NewGuid();
            var trainerId2 = Guid.NewGuid();

            var locationId = Guid.NewGuid();

            var sessionId  = Guid.NewGuid();
            var dispatcher = new EventDispatcher();

            var eventStore = new FakeEventStore();

            eventStore.Save(new TrainerCreated(trainerId1, 1, "BOUDOUX", "Aurelien", "*****@*****.**"));
            eventStore.Save(new TrainerCreated(trainerId2, 1, "Creutzfeldt", "Jacob", "*****@*****.**"));
            eventStore.Save(new SessionPlanned(sessionId, 1, trainingId, new DateTime(2017, 12, 21), 5, 10, locationId, trainerId1));
            eventStore.Save(new TrainerAssigned(trainerId1, 2, new DateTime(2017, 12, 21), 5));
            eventStore.Save(new TrainerAssigned(trainerId2, 2, new DateTime(2017, 12, 20), 10));
            var eventBus = new EventBus(dispatcher, eventStore);

            // when
            Action action = () => new UpdateSession(eventBus).Execute(sessionId, trainingId, new DateTime(2017, 12, 21), 5, 10, locationId, trainerId2);

            action.ShouldThrow <TrainerAlreadyAssignedException>();
        }
        public void dont_reassign_location_when_update_session_with_same_source_and_destination()
        {
            // given
            var trainingId = Guid.NewGuid();

            var locationId1 = Guid.NewGuid();
            var locationId2 = Guid.NewGuid();
            var formateurId = Guid.NewGuid();

            var sessionId   = Guid.NewGuid();
            var dispatcher  = new EventDispatcher();
            var mockHandler = new MockHandler <LocationAssigned, LocationUnassigned, SessionUpdated>();

            dispatcher.Register(mockHandler);

            var eventStore = new FakeEventStore();

            eventStore.Save(new LocationCreated(locationId1, 1, "Lyon", "test", 5));
            eventStore.Save(new LocationCreated(locationId2, 1, "Paris", "test", 5));
            eventStore.Save(new SessionPlanned(sessionId, 1, trainingId, new DateTime(2018, 1, 1), 5, 10, locationId1, formateurId));
            eventStore.Save(new LocationAssigned(locationId1, 2, new DateTime(2018, 1, 1), 5));
            var eventBus = new EventBus(dispatcher, eventStore);

            // when
            new UpdateSession(eventBus).Execute(sessionId, trainingId, new DateTime(2018, 1, 1), 5, 10, locationId1, formateurId);

            // then
            mockHandler.AllEvents.Should()
            .Contain(new SessionUpdated(Guid.Empty, 0, new DateTime(2018, 1, 1), 5, 10, locationId1, formateurId, trainingId));
        }
        public void dont_reassign_trainers_when_update_session_with_same_source_and_destination()
        {
            // given
            var trainingId = Guid.NewGuid();

            var trainerId1 = Guid.NewGuid();
            var trainerId2 = Guid.NewGuid();
            var lieuId     = Guid.NewGuid();

            var sessionId   = Guid.NewGuid();
            var dispatcher  = new EventDispatcher();
            var mockHandler = new MockHandler <TrainerAssigned, TrainerUnassigned, SessionUpdated>();

            dispatcher.Register(mockHandler);

            var eventStore = new FakeEventStore();

            eventStore.Save(new TrainerCreated(trainerId1, 1, "BOUDOUX", "Aurelien", "*****@*****.**"));
            eventStore.Save(new TrainerCreated(trainerId2, 1, "Creutzfeldt", "Jacob", "*****@*****.**"));
            eventStore.Save(new SessionPlanned(sessionId, 1, trainingId, new DateTime(2018, 1, 1), 5, 10, lieuId, trainerId1));
            eventStore.Save(new TrainerAssigned(trainerId1, 2, new DateTime(2017, 12, 21), 5));
            var eventBus = new EventBus(dispatcher, eventStore);

            // when
            new UpdateSession(eventBus).Execute(sessionId, trainingId, new DateTime(2018, 1, 1), 5, 10, lieuId, trainerId1);

            // then
            mockHandler.AllEvents.Should()
            .Contain(new SessionUpdated(Guid.Empty, 0, new DateTime(2018, 1, 1), 5, 10, lieuId, trainerId1, trainingId));
        }
예제 #7
0
        public void SendCommand_WithStoredEvents_AppliesEventsBeforeHandlingCommand()
        {
            // Arrange
            var stubEventStore = new FakeEventStore();
            var mockEvent      = new FakeEvent();

            stubEventStore.Save(new AdditionalEvents(Guid.NewGuid(),
                                                     new ArrayList()
            {
                mockEvent
            }));
            var stubMessageDispatcher = new EventSourcedMessageDispatcher(stubEventStore);

            stubMessageDispatcher
            .RegisteredHandlerFor <AppliesFakeEventHandlesFakeCommand, FakeCommand>();
            var mockCommand = new FakeCommand();

            // Act
            stubMessageDispatcher.SendCommand(mockCommand);

            // Assert
            Assert.Equal(mockEvent,
                         AppliesFakeEventHandlesFakeCommand.applied_event);
            Assert.Equal(mockCommand,
                         AppliesFakeEventHandlesFakeCommand.handled_command);
        }
        public void reassign_location_if_update_session_period()
        {
            // given
            var trainingId = Guid.NewGuid();
            var locationId = Guid.NewGuid();

            var sessionId   = Guid.NewGuid();
            var dispatcher  = new EventDispatcher();
            var mockHandler = new MockHandler <LocationReassigned, SessionUpdated>();

            dispatcher.Register(mockHandler);

            var eventStore = new FakeEventStore();

            eventStore.Save(new LocationCreated(locationId, 1, "Lyon", "test", 5));
            eventStore.Save(new LocationAssigned(locationId, 2, new DateTime(2018, 1, 1), 5));

            eventStore.Save(new SessionPlanned(sessionId, 1, trainingId, new DateTime(2018, 1, 1), 5, 10, locationId, null));

            var eventBus = new EventBus(dispatcher, eventStore);

            // when
            new UpdateSession(eventBus).Execute(sessionId, trainingId, new DateTime(2018, 1, 2), 4, 10, locationId, null);

            // then
            mockHandler.AllEvents.Should()
            .Contain(new LocationReassigned(Guid.Empty, 0, new DateTime(2018, 1, 1), 5, new DateTime(2018, 1, 2), 4)).And
            .Contain(new SessionUpdated(Guid.Empty, 0, new DateTime(2018, 1, 2), 4, 10, locationId, null, trainingId));
        }
        public void unassign_location_when_session_deleted()
        {
            // given
            var trainingId = Guid.NewGuid();
            var trainerId1 = Guid.NewGuid();
            var locationId = Guid.NewGuid();

            var sessionId   = Guid.NewGuid();
            var dispatcher  = new EventDispatcher();
            var mockHandler = new MockHandler <TrainerUnassigned, LocationUnassigned, SessionDeleted>();

            dispatcher.Register(mockHandler);

            var eventStore = new FakeEventStore();

            eventStore.Save(new TrainerCreated(trainerId1, 1, "BOUDOUX", "Aurelien", "*****@*****.**"));
            eventStore.Save(new TrainerAssigned(trainerId1, 2, new DateTime(2017, 12, 21), 5));

            eventStore.Save(new LocationCreated(locationId, 1, "Lyon", "test", 5));
            eventStore.Save(new LocationAssigned(locationId, 2, new DateTime(2017, 12, 21), 5));

            eventStore.Save(new SessionPlanned(sessionId, 1, trainingId, new DateTime(2017, 12, 21), 5, 10, locationId, trainerId1));

            var eventBus = new EventBus(dispatcher, eventStore);

            // when
            new RemoveSession(eventBus).Execute(sessionId);

            // then
            mockHandler.AllEvents.Should()
            .Contain(new TrainerUnassigned(Guid.Empty, 0, new DateTime(2017, 12, 21), 5)).And
            .Contain(new LocationUnassigned(Guid.Empty, 0, new DateTime(2017, 12, 21), 5)).And
            .Contain(new SessionDeleted(Guid.Empty, 0));
        }
        public void unassign_all_loction_when_formation_is_deleted()
        {
            // given
            var trainingId = Guid.NewGuid();

            var locationId1 = Guid.NewGuid();
            var locationId2 = Guid.NewGuid();

            var sessionId1 = Guid.NewGuid();
            var sessionId2 = Guid.NewGuid();
            var sessionId3 = Guid.NewGuid();
            var sessionId4 = Guid.NewGuid();
            var sessionId5 = Guid.NewGuid();
            var sessionId6 = Guid.NewGuid();

            //var formateurId = Guid.NewGuid();

            var dispatcher  = new EventDispatcher();
            var mockHandler = new MockHandler <LocationUnassigned, SessionDeleted, TrainingDeleted>();

            dispatcher.Register(mockHandler);

            var eventStore = new FakeEventStore();

            eventStore.Save(new LocationCreated(locationId1, 1, "Paris", "test", 5));
            eventStore.Save(new LocationCreated(locationId2, 1, "Lyon", "test", 3));
            eventStore.Save(new SessionPlanned(sessionId1, 1, trainingId, new DateTime(2017, 10, 21), 2, 2, locationId1, null));
            eventStore.Save(new SessionPlanned(sessionId2, 2, trainingId, new DateTime(2017, 11, 21), 2, 2, locationId1, null));
            eventStore.Save(new SessionPlanned(sessionId3, 3, trainingId, new DateTime(2017, 12, 21), 2, 2, locationId1, null));
            eventStore.Save(new SessionPlanned(sessionId4, 1, trainingId, new DateTime(2017, 10, 21), 2, 2, locationId2, null));
            eventStore.Save(new SessionPlanned(sessionId5, 2, trainingId, new DateTime(2017, 11, 21), 2, 2, locationId2, null));
            eventStore.Save(new SessionPlanned(sessionId6, 3, trainingId, new DateTime(2017, 12, 21), 2, 2, locationId2, null));
            eventStore.Save(new LocationAssigned(locationId1, 1, new DateTime(2017, 10, 21), 2));
            eventStore.Save(new LocationAssigned(locationId1, 2, new DateTime(2017, 11, 21), 2));
            eventStore.Save(new LocationAssigned(locationId1, 3, new DateTime(2017, 12, 21), 2));
            eventStore.Save(new LocationAssigned(locationId2, 4, new DateTime(2017, 10, 21), 2));
            eventStore.Save(new LocationAssigned(locationId2, 5, new DateTime(2017, 11, 21), 2));
            eventStore.Save(new LocationAssigned(locationId2, 6, new DateTime(2017, 12, 21), 2));
            eventStore.Save(new TrainingCreated(trainingId, 1, "Formation de test", 1, Color.Empty.ToArgb()));
            var eventBus = new EventBus(dispatcher, eventStore);

            var sessionQueries = new FakeSessionQueries();

            sessionQueries.AddSession(trainingId, sessionId1, new DateTime(2017, 10, 21), 2, locationId1, null);
            sessionQueries.AddSession(trainingId, sessionId2, new DateTime(2017, 11, 21), 2, locationId1, null);
            sessionQueries.AddSession(trainingId, sessionId3, new DateTime(2017, 12, 21), 2, locationId1, null);
            sessionQueries.AddSession(trainingId, sessionId4, new DateTime(2017, 10, 21), 2, locationId2, null);
            sessionQueries.AddSession(trainingId, sessionId5, new DateTime(2017, 11, 21), 2, locationId2, null);
            sessionQueries.AddSession(trainingId, sessionId6, new DateTime(2017, 12, 21), 2, locationId2, null);

            // when
            new DeleteTraining(eventBus, sessionQueries).Execute(trainingId);

            // then
            mockHandler.AllEvents.OfType <SessionDeleted>().Should().HaveCount(6);
            mockHandler.AllEvents.OfType <LocationUnassigned>().Should().HaveCount(6);
            mockHandler.AllEvents.OfType <TrainingDeleted>().Should().HaveCount(1);
        }
        public void unassign_all_trainer_when_training_is_deleted()
        {
            // given
            var trainingId = Guid.NewGuid();

            var trainerId1 = Guid.NewGuid();
            var trainerId2 = Guid.NewGuid();

            var sessionId1 = Guid.NewGuid();
            var sessionId2 = Guid.NewGuid();
            var sessionId3 = Guid.NewGuid();
            var sessionId4 = Guid.NewGuid();
            var sessionId5 = Guid.NewGuid();
            var sessionId6 = Guid.NewGuid();

            var locationId = Guid.NewGuid();

            var dispatcher  = new EventDispatcher();
            var mockHandler = new MockHandler <TrainerUnassigned, SessionDeleted, TrainingDeleted>();

            dispatcher.Register(mockHandler);

            var eventStore = new FakeEventStore();

            eventStore.Save(new TrainerCreated(trainerId1, 1, "BOUDOUX", "Aurelien", "*****@*****.**"));
            eventStore.Save(new TrainerCreated(trainerId2, 1, "Creutzfeldt", "Jacob", "*****@*****.**"));
            eventStore.Save(new SessionPlanned(sessionId1, 1, trainingId, new DateTime(2017, 10, 21), 2, 2, locationId, trainerId1));
            eventStore.Save(new SessionPlanned(sessionId2, 2, trainingId, new DateTime(2017, 11, 21), 2, 2, locationId, trainerId1));
            eventStore.Save(new SessionPlanned(sessionId3, 3, trainingId, new DateTime(2017, 12, 21), 2, 2, locationId, trainerId1));
            eventStore.Save(new SessionPlanned(sessionId4, 1, trainingId, new DateTime(2017, 10, 21), 2, 2, locationId, trainerId2));
            eventStore.Save(new SessionPlanned(sessionId5, 2, trainingId, new DateTime(2017, 11, 21), 2, 2, locationId, trainerId2));
            eventStore.Save(new SessionPlanned(sessionId6, 3, trainingId, new DateTime(2017, 12, 21), 2, 2, locationId, trainerId2));
            eventStore.Save(new TrainerAssigned(trainerId1, 1, new DateTime(2017, 10, 21), 2));
            eventStore.Save(new TrainerAssigned(trainerId1, 2, new DateTime(2017, 11, 21), 2));
            eventStore.Save(new TrainerAssigned(trainerId1, 3, new DateTime(2017, 12, 21), 2));
            eventStore.Save(new TrainerAssigned(trainerId2, 4, new DateTime(2017, 10, 21), 2));
            eventStore.Save(new TrainerAssigned(trainerId2, 5, new DateTime(2017, 11, 21), 2));
            eventStore.Save(new TrainerAssigned(trainerId2, 6, new DateTime(2017, 12, 21), 2));
            eventStore.Save(new TrainingCreated(trainingId, 1, "Formation de test", 1, Color.Empty.ToArgb()));
            var eventBus = new EventBus(dispatcher, eventStore);

            var sessionQueries = new FakeSessionQueries();

            sessionQueries.AddSession(trainingId, sessionId1, new DateTime(2017, 10, 21), 2, null, trainerId1);
            sessionQueries.AddSession(trainingId, sessionId2, new DateTime(2017, 11, 21), 2, null, trainerId1);
            sessionQueries.AddSession(trainingId, sessionId3, new DateTime(2017, 12, 21), 2, null, trainerId1);
            sessionQueries.AddSession(trainingId, sessionId4, new DateTime(2017, 10, 21), 2, null, trainerId2);
            sessionQueries.AddSession(trainingId, sessionId5, new DateTime(2017, 11, 21), 2, null, trainerId2);
            sessionQueries.AddSession(trainingId, sessionId6, new DateTime(2017, 12, 21), 2, null, trainerId2);

            // when
            new DeleteTraining(eventBus, sessionQueries).Execute(trainingId);

            // then
            mockHandler.AllEvents.OfType <SessionDeleted>().Should().HaveCount(6);
            mockHandler.AllEvents.OfType <TrainerUnassigned>().Should().HaveCount(6);
            mockHandler.AllEvents.OfType <TrainingDeleted>().Should().HaveCount(1);
        }
        public void throw_error_if_plan_session_with_trainer_that_not_exists()
        {
            var trainingId = Guid.NewGuid();
            var dispatcher = new EventDispatcher();
            var eventStore = new FakeEventStore();
            var eventBus   = new EventBus(dispatcher, eventStore);

            Action action = () => new PlanSession(eventBus).Execute(trainingId, new DateTime(2017, 12, 21), 5, 10, Guid.NewGuid(), trainingId);

            action.ShouldThrow <TrainerNotExistsException>();
        }
        public void throw_error_if_plan_session_with_location_that_not_exists()
        {
            var trainingId = Guid.NewGuid();
            var trainerId  = Guid.NewGuid();
            var dispatcher = new EventDispatcher();
            var eventStore = new FakeEventStore();

            eventStore.Save(new TrainerCreated(trainerId, 1, "BOUDOUX", "Aurelien", "*****@*****.**"));
            var eventBus = new EventBus(dispatcher, eventStore);

            Action action = () => new PlanSession(eventBus).Execute(trainingId, new DateTime(2017, 12, 21), 5, 10, Guid.NewGuid(), trainerId);

            action.ShouldThrow <LocationNotExistsException>();
        }
예제 #14
0
        public void throw_exception_if_update_trainer_with_existing_name()
        {
            var query = new FakeTrainerQueries();

            query.AddTrainer("Cordier", "Fabrice");

            var eventStore = new FakeEventStore();
            var trainerId  = Guid.NewGuid();

            eventStore.Save(new TrainerCreated(trainerId, 1, "BOUDOXU", "Aurélien", ""));

            Action action = () => new UpdateTrainer(new EventBus(new EventDispatcher(), eventStore), query).Execute(trainerId, "cordier", "fabrice", "");

            action.ShouldThrow <TrainerAlreadyExistsException>();
        }
        public void registering_a_new_timeout()
        {
            Guid correlationId   = Guid.NewGuid();
            int  timeoutPeriodMS = 500;
            var  waitHandle      = new ManualResetEvent(false);

            IEventStore eventStore      = new FakeEventStore(new List <IEvent>());
            var         timeoutRegistry = new TimeoutRegistry(eventStore, @event => { });

            var newTimeoutCommand = new StartTimeout
            {
                CorrelationId = correlationId.ToString(),
                ElapsesInMS   = timeoutPeriodMS,
            };
        }
예제 #16
0
        public void throw_error_if_updating_company_with_same_name()
        {
            var queries = new FakeCompanyQueries();

            queries.Add("trend");

            var eventStore = new FakeEventStore();
            var trainerId  = Guid.NewGuid();

            eventStore.Save(new CompanyCreated(trainerId, 1, "Peaks", "", "", ""));

            Action action = () => new UpdateCompany(new EventBus(new EventDispatcher(), eventStore), queries).Execute(trainerId, "TREND", String.Empty, String.Empty, String.Empty);

            action.ShouldThrow <CompanyAlreadyExistsException>();
        }
예제 #17
0
        public void dont_throw_error_if_updating_existing_company()
        {
            var queries = new FakeCompanyQueries();

            queries.Add("trend");

            var eventStore = new FakeEventStore();
            var companyId  = Guid.NewGuid();

            eventStore.Save(new CompanyCreated(companyId, 1, "Peaks", "", "", ""));
            queries.Add("Peaks", companyId: companyId);

            new UpdateCompany(new EventBus(new EventDispatcher(), eventStore), queries).Execute(companyId, "Peaks", "ceci est un test", String.Empty, String.Empty);

            eventStore.GetEvents(companyId).Should().Contain(new CompanyUpdated(Guid.Empty, 0, "Peaks", "ceci est un test", String.Empty, String.Empty));
        }
예제 #18
0
        public void dont_throw_exception_if_updating_current_trainer()
        {
            var query = new FakeTrainerQueries();

            query.AddTrainer("Cordier", "Fabrice");

            var eventStore = new FakeEventStore();
            var trainerId  = Guid.NewGuid();

            eventStore.Save(new TrainerCreated(trainerId, 1, "BOUDOUX", "Aurélien", ""));
            query.AddTrainer("BOUDOUX", "Aurélien", trainerId: trainerId);

            new UpdateTrainer(new EventBus(new EventDispatcher(), eventStore), query).Execute(trainerId, "BOUDOUX", "Aurélien", "*****@*****.**");

            eventStore.GetEvents(trainerId).Should().Contain(new TrainerUpdated(Guid.Empty, 0, "BOUDOUX", "Aurélien", "*****@*****.**"));
        }
        public void plan_new_session_with_no_trainer()
        {
            var trainingId = Guid.NewGuid();
            var dispatcher = new EventDispatcher();
            var eventStore = new FakeEventStore();
            var eventBus   = new EventBus(dispatcher, eventStore);

            var mockHandler = new MockHandler <SessionPlanned>();

            dispatcher.Register(mockHandler);

            new PlanSession(eventBus).Execute(trainingId, new DateTime(2018, 1, 1), 5, 10, null, null);

            mockHandler.AllEvents.Should().HaveCount(1);
            mockHandler.AllEvents.Should().Contain(new SessionPlanned(Guid.Empty, 0, trainingId, new DateTime(2018, 1, 1), 5, 10, null, null));
        }
예제 #20
0
        public void dont_throw_error_if_updating_myself()
        {
            var queries = new FakeLocationQueries();

            queries.Add("lulu", "test", 1);
            queries.Add("lala", "test", 1);
            queries.Add("titi", "test", 1);

            var eventStore = new FakeEventStore();
            var lieuId     = Guid.NewGuid();

            eventStore.Save(new LocationCreated(lieuId, 1, "COUCOU", "osef", 1));

            new UpdateLocation(new EventBus(new EventDispatcher(), eventStore), queries).Execute(lieuId, "COUCOU", "ok", 2);

            eventStore.GetEvents(lieuId).Should().Contain(new LocationUpdated(lieuId, 0, "COUCOU", "ok", 2));
        }
예제 #21
0
        public void throw_error_if_updating_name_whith_same_name()
        {
            var queries = new FakeLocationQueries();

            queries.Add("lulu", "test", 1);
            queries.Add("lala", "test", 1);
            queries.Add("titi", "test", 1);

            var eventStore = new FakeEventStore();
            var lieuId     = Guid.NewGuid();

            eventStore.Save(new LocationCreated(lieuId, 1, "COUCOU", "osef", 1));

            Action action = () => new UpdateLocation(new EventBus(new EventDispatcher(), eventStore), queries).Execute(lieuId, "lala", "ok", 1);

            action.ShouldThrow <LocationAlreadyExistsException>();
        }
        public void throw_error_if_trainer_not_available_on_planNewSession()
        {
            // given
            var trainingId = Guid.NewGuid();
            var trainerId  = Guid.NewGuid();
            var dispatcher = new EventDispatcher();

            var eventStore = new FakeEventStore();

            eventStore.Save(new TrainerCreated(trainerId, 1, "BOUDOUX", "Aurelien", "*****@*****.**"));
            eventStore.Save(new TrainerAssigned(trainerId, 2, new DateTime(2017, 12, 20), 10));
            var eventBus = new EventBus(dispatcher, eventStore);

            // when
            Action action = () => new PlanSession(eventBus).Execute(trainingId, new DateTime(2017, 12, 21), 5, 1, Guid.NewGuid(), trainerId);

            // then
            action.ShouldThrow <TrainerAlreadyAssignedException>();
        }
        public void plan_new_session_with_no_location()
        {
            var trainingId = Guid.NewGuid();
            var trainerId  = Guid.NewGuid();
            var dispatcher = new EventDispatcher();
            var eventStore = new FakeEventStore();

            eventStore.Save(new TrainerCreated(trainerId, 1, "BOUDOUX", "Aurelien", "*****@*****.**"));
            var eventBus = new EventBus(dispatcher, eventStore);

            var mockHandler = new MockHandler <SessionPlanned>();

            dispatcher.Register(mockHandler);

            new PlanSession(eventBus).Execute(trainingId, new DateTime(2018, 1, 1), 5, 10, null, trainerId);

            mockHandler.AllEvents.Should().HaveCount(1);
            mockHandler.AllEvents.Should().Contain(new SessionPlanned(Guid.Empty, 0, trainingId, new DateTime(2018, 1, 1), 5, 10, null, trainerId));
        }
예제 #24
0
        public void throw_error_if_sequence_not_consistent_with_event_store()
        {
            var store    = new FakeEventStore();
            var eventBus = new EventBus(new EventDispatcher(), store);

            var uncommitedEvent = new UncommitedEvents();

            var guid = Guid.NewGuid();

            uncommitedEvent.Add(new TestDomainEvent(guid, 1));
            uncommitedEvent.Add(new TestDomainEvent(guid, 2));
            uncommitedEvent.Add(new TestDomainEvent(guid, 3));
            eventBus.Publish(uncommitedEvent);

            uncommitedEvent.Add(new TestDomainEvent(guid, 3));
            var publish = (Action)(() => eventBus.Publish(uncommitedEvent));

            publish.ShouldThrow <ConsistencyException>();
        }
예제 #25
0
        public void SendCommand_WithCommandThatEmitsEvent_SavesEventInEventStore()
        {
            // Arrange
            var stubEventStore        = new FakeEventStore();
            var stubMessageDispatcher = new EventSourcedMessageDispatcher(stubEventStore);
            var mockGuid = Guid.NewGuid();

            stubMessageDispatcher
            .RegisteredHandlerFor <HandlesFakeCommandEmitsFakeEvents, FakeCommand>();

            // Act
            stubMessageDispatcher.SendCommand(
                new FakeCommand()
            {
                Id = mockGuid
            });

            // Assert
            Assert.Equal(mockGuid, ((FakeEvent)(stubEventStore
                                                .LoadEventsFor(mockGuid) as ArrayList)[0]).Id);
        }
        public void be_planned_if_trainner_available_for_session()
        {
            // given
            var trainingId  = Guid.NewGuid();
            var trainerId   = Guid.NewGuid();
            var dispatcher  = new EventDispatcher();
            var mockHandler = new MockHandler <TrainerAssigned, SessionPlanned>();

            dispatcher.Register(mockHandler);

            var eventStore = new FakeEventStore();

            eventStore.Save(new TrainerCreated(trainerId, 1, "BOUDOUX", "Aurelien", "*****@*****.**"));
            var eventBus = new EventBus(dispatcher, eventStore);

            // when
            new PlanSession(eventBus).Execute(trainingId, new DateTime(2018, 1, 1), 5, 10, null, trainerId);

            // then
            mockHandler.AllEvents.Should()
            .Contain(new TrainerAssigned(Guid.Empty, 0, new DateTime(2018, 1, 1), 5)).And
            .Contain(new SessionPlanned(Guid.Empty, 0, trainingId, new DateTime(2018, 1, 1), 5, 10, null, trainerId));
        }
        public void be_planned_if_location_available_for_session()
        {
            // given
            var trainingId = Guid.NewGuid();

            var locationId  = Guid.NewGuid();
            var dispatcher  = new EventDispatcher();
            var mockHandler = new MockHandler <LocationAssigned, SessionPlanned>();

            dispatcher.Register(mockHandler);

            var eventStore = new FakeEventStore();

            eventStore.Save(new LocationCreated(locationId, 1, "Paris", "test", 5));
            var eventBus = new EventBus(dispatcher, eventStore);

            // when
            new PlanSession(eventBus).Execute(trainingId, new DateTime(2018, 1, 1), 5, 10, locationId, null);

            // then
            mockHandler.AllEvents.Should()
            .Contain(new LocationAssigned(Guid.Empty, 0, new DateTime(2018, 1, 1), 5)).And
            .Contain(new SessionPlanned(Guid.Empty, 0, trainingId, new DateTime(2018, 1, 1), 5, 10, locationId, null));
        }
 public delete_calendar_item_command_handler_tests()
 {
     EventStore           = new FakeEventStore();
     CreateCommandHandler = new CreateCalendarItemCommandHandler(EventStore);
     DeleteCommandHandler = new DeleteCalendarItemCommandHandler(EventStore);
 }
예제 #29
0
 public Subscription(FakeEventStore eventStore)
 {
     this.eventStore = eventStore;
 }
예제 #30
0
 public AddNumberCommandHandler(FakeEventStore fakeStore)
 {
     _fakeStore = fakeStore;
 }