public void WhenTheRegistrantProceedToMakeTheReservation()
        {
            registerToConference = ScenarioContext.Current.Get<RegisterToConference>();
            var conferenceAlias = ScenarioContext.Current.Get<ConferenceAlias>();

            registerToConference.ConferenceId = conferenceAlias.Id;
            orderId = registerToConference.OrderId;
            this.commandBus.Send(registerToConference);
        }
        private string CreateAndSendRegisterToConference(Guid conferenceId, IEnumerable<SeatQuantity> seats)
        {
            var registration = new RegisterToConference {ConferenceId = conferenceId, OrderId = Guid.NewGuid()};
            registration.Seats.AddRange(seats);

            commandBus.Send(registration);

            return registration.OrderId.ToString();
        }
        public void ThenTheEventForReservingTheSelectedSeatsIsEmitted()
        {
            registerToConference = registerToConference ?? ScenarioContext.Current.Get<RegisterToConference>();

            // Wait and Check for SeatsReserved event was emitted 
            Assert.True(MessageLogHelper.CollectEvents<SeatsReserved>(registerToConference.ConferenceId, 1));
            var seatsReserved = MessageLogHelper.GetEvents<SeatsReserved>(registerToConference.ConferenceId).SingleOrDefault();

            Assert.NotNull(seatsReserved);
            Assert.Equal(registerToConference.Seats.Count, seatsReserved.AvailableSeatsChanged.Count());
        }
        public void WhenTheCommandToRegisterTheSelectedOrderItemsIsLost()
        {
            registerToConference = ScenarioContext.Current.Get<RegisterToConference>();
            var conferenceAlias = ScenarioContext.Current.Get<ConferenceAlias>();

            registerToConference.ConferenceId = conferenceAlias.Id;
            orderId = registerToConference.OrderId;

            //Command lost because of a failure
            //this.commandBus.Send(registerToConference); 
        }
        public void WhenTheCommandToRegisterTheSelectedOrderItemsIsSent()
        {
            registerToConference = ScenarioContext.Current.Get<RegisterToConference>();
            var conferenceAlias = ScenarioContext.Current.Get<ConferenceAlias>();

            registerToConference.ConferenceId = conferenceAlias.Id;
            orderId = registerToConference.OrderId;
            this.commandBus.Send(registerToConference);

            // Wait for event processing
            Thread.Sleep(Constants.WaitTimeout);
        }
Exemplo n.º 6
0
        public StartRegistrationResult Post(RegisterToConference command)
        {
            this.ConferenceCode = command.ConferenceCode;
            var existingOrder = command.OrderVersion != 0 ? this._orderDao.FindDraftOrder(command.OrderId) : null;
            var viewModel = this.CreateViewModel();

            if (existingOrder != null)
            {
                UpdateViewModel(viewModel, existingOrder);
            }

            viewModel.OrderId = command.OrderId;

            bool needsExtraValidation = false;
            foreach (var seat in command.Seats)
            {
                var modelItem = viewModel.Items.FirstOrDefault(x => x.SeatType.Id == seat.SeatType);
                if (modelItem != null)
                {
                    if (seat.Quantity > modelItem.MaxSelectionQuantity)
                    {
                        modelItem.PartiallyFulfilled = needsExtraValidation = true;
                        modelItem.OrderItem.ReservedSeats = modelItem.MaxSelectionQuantity;
                    }
                }
                else
                {
                    // seat type no longer exists for conference.
                    needsExtraValidation = true;
                }
            }

            //TODO: doesn't this need some work? 
            if (needsExtraValidation)
            {
                return new StartRegistrationResult
                {
                    Success = false
                };
            }

            command.ConferenceId = this.ConferenceAlias.Id;
            this._commandBus.Send(command);

            return new StartRegistrationResult
            {
                Success = true,
                ConferenceCode = this.ConferenceCode,
                OrderId = command.OrderId,
                Version = command.OrderVersion
            };
        }
        public void GivenTheSelectedOrderItems(Table table)
        {
            conferenceInfo = ScenarioContext.Current.Get<ConferenceInfo>();
            registrationController = RegistrationHelper.GetRegistrationController(conferenceInfo.Slug);

            var orderViewModel = RegistrationHelper.GetModel<OrderViewModel>(registrationController.StartRegistration());
            Assert.NotNull(orderViewModel);

            registration = new RegisterToConference { ConferenceId = conferenceInfo.Id, OrderId = registrationController.ViewBag.OrderId };

            foreach (var row in table.Rows)
            {
                var orderItemViewModel = orderViewModel.Items.FirstOrDefault(s => s.SeatType.Description == row["seat type"]);
                Assert.NotNull(orderItemViewModel);
                registration.Seats.Add(new SeatQuantity(orderItemViewModel.SeatType.Id, Int32.Parse(row["quantity"])));
            }

            // Store for sharing between steps implementations
            ScenarioContext.Current.Set(registration);
            ScenarioContext.Current.Set(registrationController.ConferenceAlias);
        }
        public void GivenTheSelectedOrderItems(Table table)
        {
            // Get the RegistrationController for this conference
            var controller = RegistrationHelper.GetRegistrationController(ScenarioContext.Current.Get<ConferenceInfo>().Slug);
            // Store for later use
            ScenarioContext.Current.Set(controller);

            var conference = ScenarioContext.Current.Get<ConferenceInfo>();
            var orderViewModel = ((ViewResult)controller.StartRegistration()).Model as OrderViewModel;
            Assert.NotNull(orderViewModel);
            var registration = new RegisterToConference { ConferenceId = conference.Id, OrderId = controller.ViewBag.OrderId };

            foreach (var row in table.Rows)
            {
                var orderItemViewModel = orderViewModel.Items.FirstOrDefault(s => s.SeatType.Description == row["seat type"]);
                Assert.NotNull(orderItemViewModel);
                registration.Seats.Add(new SeatQuantity(orderItemViewModel.SeatType.Id, Int32.Parse(row["quantity"])));
            }

            ScenarioContext.Current.Set(registration);
        }
        public ActionResult StartRegistration(RegisterToConference command, int orderVersion)
        {
            if (!ModelState.IsValid)
            {
                return this.ShowRegistrationEditor(command.OrderId, orderVersion);
            }

            // TODO: validate incoming seat types correspond to the conference.

            command.ConferenceId = this.ConferenceAlias.Id;
            this.commandBus.Send(command);

            return RedirectToAction(
                "SpecifyRegistrantAndPaymentDetails",
                new { conferenceCode = this.ConferenceCode, orderId = command.OrderId, orderVersion = orderVersion });
        }
        public void when_specifying_seats_for_a_valid_registration_then_places_registration_and_redirects_to_action()
        {
            var seatTypeId = Guid.NewGuid();
            var seats = new[] { new SeatType(seatTypeId, conferenceAlias.Id, "Test Seat", "Description", 10, 50) { AvailableQuantity = 50 } };

            // Arrange
            Mock.Get(this.conferenceDao).Setup(r => r.GetPublishedSeatTypes(conferenceAlias.Id)).Returns(seats);

            var orderId = Guid.NewGuid();

            Mock.Get(this.orderDao).Setup(r => r.FindDraftOrder(orderId)).Returns(new DraftOrder(orderId, conferenceAlias.Id, DraftOrder.States.PendingReservation));

            var registration =
                new RegisterToConference
                {
                    OrderId = orderId,
                    Seats = { new SeatQuantity(seatTypeId, 10) }
                };

            // Act
            var result = (RedirectToRouteResult)this.sut.StartRegistration(registration, 0);

            // Assert
            Assert.Equal(null, result.RouteValues["controller"]);
            Assert.Equal("SpecifyRegistrantAndPaymentDetails", result.RouteValues["action"]);
            Assert.Equal(conferenceAlias.Code, result.RouteValues["conferenceCode"]);
            Assert.Equal(orderId, result.RouteValues["orderId"]);

            Mock.Get<ICommandBus>(this.bus)
                .Verify(
                    b =>
                        b.Send(It.Is<Envelope<ICommand>>(e =>
                            ((RegisterToConference)e.Body).ConferenceId == conferenceAlias.Id
                                && ((RegisterToConference)e.Body).OrderId == orderId
                                && ((RegisterToConference)e.Body).Seats.Count == 1
                                && ((RegisterToConference)e.Body).Seats.ElementAt(0).Quantity == 10
                                && ((RegisterToConference)e.Body).Seats.ElementAt(0).SeatType == seatTypeId)),
                    Times.Once());
        }
Exemplo n.º 11
0
        public ActionResult StartRegistration(RegisterToConference command, int orderVersion)
        {
            var existingOrder = orderVersion != 0 ? this.orderDao.FindDraftOrder(command.OrderId) : null;
            var viewModel = this.CreateViewModel();
            if (existingOrder != null)
            {
                UpdateViewModel(viewModel, existingOrder);
            }

            viewModel.OrderId = command.OrderId;

            if (!ModelState.IsValid)
            {
                return View(viewModel);
            }

            // checks that there are still enough available seats, and the seat type IDs submitted are valid.
            ModelState.Clear();
            bool needsExtraValidation = false;
            foreach (var seat in command.Seats)
            {
                var modelItem = viewModel.Items.FirstOrDefault(x => x.SeatType.Id == seat.SeatType);
                if (modelItem != null)
                {
                    if (seat.Quantity > modelItem.MaxSelectionQuantity)
                    {
                        modelItem.PartiallyFulfilled = needsExtraValidation = true;
                        modelItem.OrderItem.ReservedSeats = modelItem.MaxSelectionQuantity;
                    }
                }
                else
                {
                    // seat type no longer exists for conference.
                    needsExtraValidation = true;
                }
            }

            if (needsExtraValidation)
            {
                return View(viewModel);
            }

            command.ConferenceId = this.ConferenceAlias.Id;
            this.commandBus.Send(command);

            return RedirectToAction(
                "SpecifyRegistrantAndPaymentDetails",
                new { conferenceCode = this.ConferenceCode, orderId = command.OrderId, orderVersion = orderVersion });
        }