Beispiel #1
0
        // Commands created from events from the conference BC

        public void Handle(AddSeats command)
        {
            var availability = repository.Find(command.ConferenceId);

            if (availability == null)
            {
                availability = new SeatsAvailability(command.ConferenceId);
            }

            availability.AddSeats(command.SeatType, command.Quantity);
            repository.Save(availability, command.Id.ToString());
        }
        public void Handle(RegisterToConference command)
        {
            var items = command.Seats.Select(t => new OrderItem(t.SeatType, t.Quantity)).ToList();
            var order = repository.Find(command.OrderId);

            if (order == null)
            {
                order = new Order(command.OrderId, command.ConferenceId, items, pricingService);
            }
            else
            {
                order.UpdateSeats(items, pricingService);
            }

            repository.Save(order, command.Id.ToString());
        }
        public void Handle(RegisterToWorkshop command)
        {
            var items = command.Anchors.Select(t => new OrderItem(t.AnchorType, t.Quantity)).ToList();
            var order = repository.Find(command.OrderId);

            if (order == null)
            {
                order = new Order(command.OrderId, command.WorkshopId, items, pricingService);
            }
            else
            {
                order.UpdateAnchors(items, pricingService);
            }

            repository.Save(order, command.Id.ToString());
        }
        public async Task Consume(ConsumeContext <RegisterToConference> commandContext)
        {
            var items = commandContext.Message.Seats.Select(t => new OrderItem(t.SeatType, t.Quantity)).ToList();
            var order = await repository.Find(commandContext.Message.OrderId);

            if (order == null)
            {
                order = new Order(commandContext.Message.OrderId, commandContext.Message.ConferenceId, items, pricingService);
            }
            else
            {
                order.UpdateSeats(items, pricingService);
            }

            await repository.Save(order, commandContext.Message.Id.ToString());
        }
Beispiel #5
0
        public void Handle(AddOrUpdateAppSettings command)
        {
            var company = _repository.Find(command.CompanyId);

            company.AddOrUpdateAppSettings(command.AppSettings);
            _repository.Save(company, command.Id.ToString());
        }
Beispiel #6
0
        public async Task Handle(
            Envelope <UpdateTodoItem> envelope,
            CancellationToken cancellationToken)
        {
            UpdateTodoItem command   = envelope.Message;
            Guid           messageId = envelope.MessageId;

            TodoItem todoItem = await
                                _repository.Find(command.TodoItemId, cancellationToken);

            if (todoItem == null)
            {
                throw new InvalidOperationException(
                          $"Cannot find todo item with id '{command.TodoItemId}'.");
            }

            todoItem.Update(command.Description);

            await _repository.Save(todoItem, messageId, cancellationToken);
        }
        public async Task CreateTheater_command_handler_creates_Theater_aggregate_root(
            CreateTheater command)
        {
            IEventSourcedRepository <Theater>
                repository = GetRepository(Theater.Factory);
            var sut        = new TheaterCommandHandler(repository);

            await sut.Handle(new Envelope(command));

            Theater actual = await repository.Find(command.TheaterId);

            actual.Should().NotBeNull();
        }
        public async Task CreateMovie_command_handler_creates_Movie_aggregate_root(
            CreateMovie command)
        {
            IEventSourcedRepository <Movie>
                repository = GetRepository(Movie.Factory);
            var sut        = new MovieCommandHandler(
                repository, GetRepository(Theater.Factory));

            await sut.Handle(new Envelope(command));

            Movie actual = await repository.Find(command.MovieId);

            actual.Should().NotBeNull();
            actual.Title.Should().Be(command.Title);
        }
        public async Task AddScreening_command_handler_adds_Screening_correctly(
            Guid theaterId,
            string name,
            [Range(1, 20)] int seatRowCount,
            [Range(1, 20)] int seatColumnCount,
            Movie movie,
            IFixture builder)
        {
            // Arange
            IEventSourcedRepository <Theater>
                theaterRepository = GetRepository(Theater.Factory);
            var theater           = new Theater(
                theaterId, name, seatRowCount, seatColumnCount);
            await theaterRepository.SaveAndPublish(theater);

            IEventSourcedRepository <Movie>
            movieRepository = GetRepository(Movie.Factory);
            await movieRepository.SaveAndPublish(movie);

            var sut = new MovieCommandHandler(
                movieRepository, theaterRepository);

            AddScreening command = builder.Build <AddScreening>()
                                   .With(e => e.MovieId, movie.Id)
                                   .With(e => e.TheaterId, theaterId)
                                   .Create();

            // Act
            await sut.Handle(new Envelope(command));

            // Assert
            Movie actual = await movieRepository.Find(movie.Id);

            actual.Screenings
            .Should().Contain(s => s.Id == command.ScreeningId).Which
            .Should().BeEquivalentTo(new
            {
                Id = command.ScreeningId,
                command.TheaterId,
                Seats = from r in Enumerable.Range(0, seatRowCount)
                        from c in Enumerable.Range(0, seatColumnCount)
                        let isReserved = false
                                         select new Seat(row: r, column: c, isReserved),
                command.ScreeningTime,
                command.DefaultFee,
                command.ChildrenFee,
            });
        }
        public static Task <T> Find <T>(
            this IEventSourcedRepository <T> repository,
            Guid sourceId)
            where T : class, IEventSourced
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            if (sourceId == Guid.Empty)
            {
                throw new ArgumentException(
                          $"{nameof(sourceId)} cannot be empty.", nameof(sourceId));
            }

            return(repository.Find(sourceId, CancellationToken.None));
        }
        public void Handle(MakeAppointment command)
        {
            Console.WriteLine("AppointmentCommandHandler Handle " + command.ToString());

            _repository.Find(command.Id).ContinueWith((task) =>
            {
                var appointmentAggregate = task.Result;
                if (appointmentAggregate != null)
                {
                    throw new DuplicatedAggregateException(command.Id, "Appointment");
                }
                else
                {
                    appointmentAggregate = new AppointmentAggregate(command.Id);
                }

                appointmentAggregate.CreateAppointment(command.Appointment);
                var saveTask = _repository.Save(appointmentAggregate, command.Id);
                saveTask.Wait();
            });
        }
        private async Task HandleAddScreening(
            Envelope <AddScreening> envelope,
            CancellationToken cancellationToken)
        {
            AddScreening command = envelope.Message;

            Movie movie = await _movieRepository.Find(command.MovieId);

            Theater theater = await _theaterRepository.Find(command.TheaterId);

            movie.AddScreening(
                command.ScreeningId,
                command.TheaterId,
                theater.SeatRowCount,
                theater.SeatColumnCount,
                command.ScreeningTime,
                command.DefaultFee,
                command.ChildrenFee);

            await _movieRepository.SaveAndPublish(
                movie, correlation : envelope, cancellationToken);
        }
        public void Handle(CancelOrder command)
        {
            var order = _repository.Find(command.OrderId);

            order.Cancel();
            _repository.Save(order, command.Id.ToString());
        }
Beispiel #14
0
        public void Handle(AddOrUpdateCreditCard command)
        {
            var account = _repository.Find(command.AccountId);

            account.AddOrUpdateCreditCard(
                command.CreditCardCompany,
                command.CreditCardId,
                command.NameOnCard,
                command.Last4Digits,
                command.ExpirationMonth,
                command.ExpirationYear,
                command.Token,
                command.Label,
                command.ZipCode,
                command.StreetNumber,
                command.StreetName,
                command.Email,
                command.Phone,
                command.Country);
            _repository.Save(account, command.Id.ToString());
        }