// TODO: Locate and Create are the ONLY methods that don't require authentication/location info.

        /// <summary>
        /// We receive the slug value as a kind of cross-cutting value that 
        /// all methods need and use, so we catch and load the conference here, 
        /// so it's available for all. Each method doesn't need the slug parameter.
        /// </summary>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var slug = (string)this.ControllerContext.RequestContext.RouteData.Values["slug"];
            if (!string.IsNullOrEmpty(slug))
            {
                this.ViewBag.Slug = slug;
                this.Conference = this.Service.FindConference(slug);

                if (this.Conference != null)
                {
                    // check access
                    var accessCode = (string)this.ControllerContext.RequestContext.RouteData.Values["accessCode"];

                    if (accessCode == null || !string.Equals(accessCode, this.Conference.AccessCode, StringComparison.Ordinal))
                    {
                        filterContext.Result = new HttpUnauthorizedResult("Invalid access code.");
                    }
                    else
                    {
                        this.ViewBag.OwnerName = this.Conference.OwnerName;
                        this.ViewBag.WasEverPublished = this.Conference.WasEverPublished;
                    }
                }
            }

            base.OnActionExecuting(filterContext);
        }
        public void GivenTheListOfTheAvailableOrderItemsForTheCqrsSummit2012Conference(Table table)
        {
            // Populate Conference data
            conferenceInfo = ConferenceHelper.PopulateConfereceData(table);

            // Store for being used by external step classes
            ScenarioContext.Current.Set(conferenceInfo);
        }
 public void InsertOrUpdate(ConferenceInfo conferenceinfo)
 {
     if (conferenceinfo.Id == default(int)) {
         // New entity
         context.ConferenceInfoes.Add(conferenceinfo);
     } else {
         // Existing entity
         context.Entry(conferenceinfo).State = EntityState.Modified;
     }
 }
        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 ActionResult Edit(ConferenceInfo conference)
        {
            if (this.Conference == null)
            {
                return HttpNotFound();
            }
            if (ModelState.IsValid)
            {
                this.Service.UpdateConference(conference);
                return RedirectToAction("Index", new { slug = conference.Slug, accessCode = conference.AccessCode });
            }

            return View(conference);
        }
        public ActionResult Create(ConferenceInfo conference)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    conference.Id = Guid.NewGuid();
                    this.Service.CreateConference(conference);
                }
                catch (DuplicateNameException e)
                {
                    ModelState.AddModelError("Slug", e.Message);
                    return View(conference);
                }

                return RedirectToAction("Index", new { slug = conference.Slug, accessCode = conference.AccessCode });
            }

            return View(conference);
        }
        public given_an_existing_conference_with_a_seat()
        {
            using (var context = new ConferenceContext(dbName))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.CreateIfNotExists();
            }

            this.bus = new MemoryEventBus();
            this.service = new ConferenceService(this.bus, this.dbName);
            this.conference = new ConferenceInfo
            {
                OwnerEmail = "*****@*****.**",
                OwnerName = "test owner",
                AccessCode = "qwerty",
                Name = "test conference",
                Description = "test conference description",
                Location = "redmond",
                Slug = "test",
                StartDate = DateTime.UtcNow,
                EndDate = DateTime.UtcNow.Add(TimeSpan.FromDays(2)),
                IsPublished = true,
                Seats = 
                {
                    new SeatType
                    {
                        Name = "general", 
                        Description = "general description", 
                        Price = 100, 
                        Quantity = 10,
                    }
                }
            };
            service.CreateConference(this.conference);
        }
 public void GivenThisConferenceInformation(Table table)
 {
     conference = ConferenceHelper.BuildConferenceInfo(table);
 }
        public given_an_existing_conference_with_a_seat()
        {
            using (var context = new ConferenceContext(dbName))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.CreateIfNotExists();
            }

            this.busEvents = new List<IEvent>();
            var busMock = new Mock<IEventBus>();
            busMock.Setup(b => b.Publish(It.IsAny<Envelope<IEvent>>())).Callback<Envelope<IEvent>>(e => busEvents.Add(e.Body));
            busMock.Setup(b => b.Publish(It.IsAny<IEnumerable<Envelope<IEvent>>>())).Callback<IEnumerable<Envelope<IEvent>>>(es => busEvents.AddRange(es.Select(e => e.Body)));
            this.service = new ConferenceService(busMock.Object, this.dbName);
            this.conference = new ConferenceInfo
            {
                OwnerEmail = "*****@*****.**",
                OwnerName = "test owner",
                AccessCode = "qwerty",
                Name = "test conference",
                Description = "test conference description",
                Location = "redmond",
                Slug = "test",
                StartDate = DateTime.UtcNow,
                EndDate = DateTime.UtcNow.Add(TimeSpan.FromDays(2)),
                IsPublished = true,
                Seats = 
                {
                    new SeatType
                    {
                        Name = "general", 
                        Description = "general description", 
                        Price = 100, 
                        Quantity = 10,
                    }
                }
            };
            service.CreateConference(this.conference);
        }
        public void when_creating_conference_and_seat_then_publishes_seat_created_on_publish()
        {
            var conference = new ConferenceInfo
            {
                OwnerEmail = "*****@*****.**",
                OwnerName = "test owner",
                AccessCode = "qwerty",
                Name = "test conference",
                Description = "test conference description",
                Location = "redmond",
                Slug = "test",
                StartDate = DateTime.UtcNow,
                EndDate = DateTime.UtcNow.Add(TimeSpan.FromDays(2)),
            };
            service.CreateConference(conference);

            var seat = new SeatType { Name = "seat", Description = "description", Price = 100, Quantity = 100 };
            service.CreateSeat(conference.Id, seat);

            service.Publish(conference.Id);

            var e = busEvents.OfType<SeatCreated>().FirstOrDefault();

            Assert.NotNull(e);
            Assert.Equal(e.SourceId, seat.Id);
        }
        public static Guid ReserveSeats(ConferenceInfo conference, Table table)
        {
            var seats = new List<SeatQuantity>();

            foreach (var row in table.Rows)
            {
                var seatInfo = conference.Seats.FirstOrDefault(s => s.Name == row["seat type"]);
                if (seatInfo == null) 
                    throw new InvalidOperationException("seat type not found");
                
                int qt;
                if (!row.ContainsKey("quantity") ||
                    !Int32.TryParse(row["quantity"], out qt))
                    qt = seatInfo.Quantity;
                
                seats.Add(new SeatQuantity(seatInfo.Id, qt));
            }

            var seatReservation = new MakeSeatReservation
            {
                ConferenceId = conference.Id,
                ReservationId = Guid.NewGuid(),
                Seats = seats
            };

            var commandBus = BuildCommandBus();
            commandBus.Send(seatReservation);

            // Wait for the events to be processed
            Thread.Sleep(Constants.WaitTimeout);

            return seatReservation.ReservationId;
        }
        internal static void SelectOrderItems(Browser browser, ConferenceInfo conferenceInfo, Table table)
        {
            // Navigate to Registration page
            browser.GoTo(Constants.RegistrationPage(conferenceInfo.Slug));

            foreach (var row in table.Rows)
            {
                browser.SelectListInTableRow(row["seat type"], row["quantity"]);
            }
        }
Beispiel #13
0
        internal static void SelectOrderItems(Browser browser, ConferenceInfo conferenceInfo, Table table, bool navigateToRegPage = true)
        {
            if (navigateToRegPage)
            {
                browser.GoTo(Constants.RegistrationPage(conferenceInfo.Slug));
                browser.WaitForComplete((int)Constants.UI.WaitTimeout.TotalSeconds);
            }

            foreach (var row in table.Rows)
            {
                browser.SelectListInTableRow(row["seat type"], row["quantity"]);
            }
        }
        public ConferenceInfo Put(ConferenceInfo conference)
        {
            _tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "ConferenceController: PUT");

            if (_user == null)
            {
                _tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "User not found returning 404");
                this.NotFound();
            }

            if (conference.PublishNow)
            {
                try
                {
                    this.service.Publish(conference.Id);
                }
                catch (System.Exception exc)
                {
                    _tracer.Error(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, exc);
                    throw;
                }
            }

            return conference;
        }
        public ConferenceInfo Post(ConferenceInfo conference)
        {
            _tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "ConferenceController: POST");

            if (_user == null)
            {
                _tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "User not found returning 404");
                this.NotFound();
            }

            try
            {
                conference.Id = GuidUtil.NewSequentialId();
                this.service.CreateConference(conference);
            }
            catch (System.Exception exc)
            {
                _tracer.Error(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, exc);
                throw;
            }

            return conference;
        }
        public void when_creating_conference_and_seat_then_does_not_publish_seat_created()
        {
            var conference = new ConferenceInfo
            {
                OwnerEmail = "*****@*****.**",
                OwnerName = "test owner",
                AccessCode = "qwerty",
                Name = "test conference",
                Description = "test conference description",
                Location = "redmond",
                Slug = "test",
                StartDate = DateTime.UtcNow,
                EndDate = DateTime.UtcNow.Add(TimeSpan.FromDays(2)),
            };
            service.CreateConference(conference);

            var seat = new SeatType { Name = "seat", Description = "description", Price = 100, Quantity = 100 };
            service.CreateSeat(conference.Id, seat);

            Assert.Empty(busEvents.OfType<SeatCreated>());
        }
Beispiel #17
0
        private static ConferenceInfo BuildInternalConferenceInfo(Table seats)
        {
            string conferenceSlug = Slug.CreateNew().Value;
            var conference = new ConferenceInfo()
            {
                Description = Constants.UI.ConferenceDescription +  " (" + conferenceSlug + ")",
                Name = conferenceSlug,
                Slug = conferenceSlug,
                Location = Constants.UI.Location,
                Tagline = Constants.UI.TagLine,
                TwitterSearch = Constants.UI.TwitterSearch,
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(1),
                OwnerName = "test",
                OwnerEmail = "*****@*****.**",
                IsPublished = true,
                WasEverPublished = true
            };

            return conference;
        }
        private static ConferenceInfo BuildConferenceInfo(Table seats, string conferenceSlug)
        {
            var conference = new ConferenceInfo()
            {
                Description = Constants.UI.ConferenceDescription +  " (" + conferenceSlug + ")",
                Name = conferenceSlug,
                Slug = conferenceSlug,
                Location = Constants.UI.Location,
                Tagline = Constants.UI.TagLine,
                TwitterSearch = Constants.UI.TwitterSearch,
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(1),
                OwnerName = "test",
                OwnerEmail = "*****@*****.**",
                IsPublished = true,
                WasEverPublished = true
            };

            foreach (var row in seats.Rows)
            {
                var seat = new SeatType()
                {
                    Id = Guid.NewGuid(),
                    Description = row["seat type"],
                    Name = row["seat type"],
                    Price = Convert.ToDecimal(row["rate"].Replace("$", "")),
                    Quantity = Convert.ToInt32(row["quota"])
                };
                conference.Seats.Add(seat);
            }

            return conference;
        }