public void when_available_seats_change_then_updates_remaining_quantity()
        {
            var seatId = Guid.NewGuid();

            sut.Handle(new SeatCreated {
                ConferenceId = conferenceId,
                SourceId     = seatId,
                Name         = "seat",
                Description  = "description",
                Price        = 200
            });

            sut.Handle(new AvailableSeatsChanged {
                SourceId = conferenceId,
                Version  = 1,
                Seats    = new[] { new SeatQuantity {
                                       SeatType = seatId, Quantity = 200
                                   } }
            });

            using (var context = new ConferenceRegistrationDbContext(dbName)) {
                var dto = context.Set <SeatType>()
                          .Where(x => x.ConferenceId == conferenceId)
                          .Single(x => x.Id == seatId);

                Assert.Equal("seat", dto.Name);
                Assert.Equal("description", dto.Description);
                Assert.Equal(200, dto.Price);
                Assert.Equal(200, dto.AvailableQuantity);
                Assert.Equal(1, dto.SeatsAvailabilityVersion);
            }
        }
Ejemplo n.º 2
0
        public void When_seat_created_even_when_conference_created_was_not_handled_then_creates_seat()
        {
            var conferenceId = Guid.NewGuid();
            var seatId       = Guid.NewGuid();

            this._sut.Handle(new SeatCreated {
                ConferenceId = conferenceId,
                SourceId     = seatId,
                Name         = "seat",
                Description  = "description",
                Price        = 200,
            });

            using (var context = new ConferenceRegistrationDbContext(_dbName)) {
                var dto = context.Set <SeatType>()
                          .FirstOrDefault(x => x.Id == seatId);

                Assert.NotNull(dto);
                Assert.AreEqual("seat", dto.Name);
                Assert.AreEqual("description", dto.Description);
                Assert.AreEqual(conferenceId, dto.ConferenceId);
                Assert.AreEqual(200, dto.Price);
                Assert.AreEqual(0, dto.AvailableQuantity);
            }
        }
        public void when_seat_created_then_adds_seat()
        {
            var seatId = Guid.NewGuid();

            this.sut.Handle(new SeatCreated
            {
                ConferenceId = conferenceId,
                SourceId     = seatId,
                Name         = "seat",
                Description  = "description",
                Price        = 200,
            });

            using (var context = new ConferenceRegistrationDbContext(dbName))
            {
                var dto = context.Set <SeatType>()
                          .Where(x => x.ConferenceId == conferenceId)
                          .Single(x => x.Id == seatId);

                Assert.Equal("seat", dto.Name);
                Assert.Equal("description", dto.Description);
                Assert.Equal(200, dto.Price);
                Assert.Equal(0, dto.AvailableQuantity);
                Assert.Equal(-1, dto.SeatsAvailabilityVersion);
            }
        }
        public void when_seat_updated_then_updates_seat_on_conference_dto()
        {
            var seatId = Guid.NewGuid();

            sut.Handle(new SeatCreated {
                ConferenceId = conferenceId,
                SourceId     = seatId,
                Name         = "seat",
                Description  = "description",
                Price        = 200
            });

            sut.Handle(new SeatUpdated {
                ConferenceId = conferenceId,
                SourceId     = seatId,
                Name         = "newseat",
                Description  = "newdescription",
                Price        = 100
            });

            using (var context = new ConferenceRegistrationDbContext(dbName)) {
                var dto = context.Set <SeatType>()
                          .Where(x => x.ConferenceId == conferenceId)
                          .Single(x => x.Id == seatId);

                Assert.NotNull(dto);
                Assert.Equal("newseat", dto.Name);
                Assert.Equal("newdescription", dto.Description);
                Assert.Equal(100, dto.Price);
                Assert.Equal(-1, dto.SeatsAvailabilityVersion);
            }
        }
        public void when_seat_availability_update_event_has_version_lower_than_last_update_then_event_is_ignored()
        {
            var seatId = Guid.NewGuid();

            this.sut.Handle(new SeatCreated
            {
                ConferenceId = conferenceId,
                SourceId     = seatId,
                Name         = "seat",
                Description  = "description",
                Price        = 200,
            });

            this.sut.Handle(new AvailableSeatsChanged
            {
                SourceId = conferenceId,
                Version  = 0,
                Seats    = new[] { new SeatQuantity {
                                       SeatType = seatId, Quantity = 200
                                   } }
            });

            this.sut.Handle(new SeatsReserved
            {
                SourceId = conferenceId,
                Version  = 1,
                AvailableSeatsChanged = new[] { new SeatQuantity {
                                                    SeatType = seatId, Quantity = -50
                                                } }
            });

            this.sut.Handle(new AvailableSeatsChanged
            {
                SourceId = conferenceId,
                Version  = 0,
                Seats    = new[] { new SeatQuantity {
                                       SeatType = seatId, Quantity = 200
                                   } }
            });

            using (var context = new ConferenceRegistrationDbContext(dbName))
            {
                var dto = context.Set <SeatType>()
                          .Where(x => x.ConferenceId == conferenceId)
                          .Single(x => x.Id == seatId);

                Assert.Equal("seat", dto.Name);
                Assert.Equal("description", dto.Description);
                Assert.Equal(200, dto.Price);
                Assert.Equal(150, dto.AvailableQuantity);
                Assert.Equal(1, dto.SeatsAvailabilityVersion);
            }
        }
Ejemplo n.º 6
0
        public void When_seats_are_released_then_updates_remaining_quantity()
        {
            var seatId = Guid.NewGuid();

            this._sut.Handle(new SeatCreated {
                ConferenceId = _conferenceId,
                SourceId     = seatId,
                Name         = "seat",
                Description  = "description",
                Price        = 200,
            });

            this._sut.Handle(new AvailableSeatsChanged {
                SourceId = _conferenceId,
                Version  = 1,
                Seats    = new[] { new SeatQuantity(seatId, 200) }
            });

            this._sut.Handle(new SeatsReserved {
                SourceId = _conferenceId,
                Version  = 2,
                AvailableSeatsChanged = new[] { new SeatQuantity(seatId, -50) }
            });

            this._sut.Handle(new SeatsReservationCancelled {
                SourceId = _conferenceId,
                Version  = 3,
                AvailableSeatsChanged = new[] { new SeatQuantity(seatId, 50) }
            });

            using (var context = new ConferenceRegistrationDbContext(_dbName)) {
                var dto = context.Set <SeatType>()
                          .Where(x => x.ConferenceId == _conferenceId)
                          .Single(x => x.Id == seatId);

                Assert.AreEqual("seat", dto.Name);
                Assert.AreEqual("description", dto.Description);
                Assert.AreEqual(200, dto.Price);
                Assert.AreEqual(200, dto.AvailableQuantity);
                Assert.AreEqual(3, dto.SeatsAvailabilityVersion);
            }
        }
        public void when_seat_created_even_when_conference_created_was_not_handled_then_creates_seat()
        {
            var conferenceId = Guid.NewGuid();
            var seatId = Guid.NewGuid();

            this.sut.Handle(new SeatCreated
            {
                ConferenceId = conferenceId,
                SourceId = seatId,
                Name = "seat",
                Description = "description",
                Price = 200,
            });

            using (var context = new ConferenceRegistrationDbContext(dbName))
            {
                var dto = context.Set<SeatType>()
                    .FirstOrDefault(x => x.Id == seatId);

                Assert.NotNull(dto);
                Assert.Equal("seat", dto.Name);
                Assert.Equal("description", dto.Description);
                Assert.Equal(conferenceId, dto.ConferenceId);
                Assert.Equal(200, dto.Price);
                Assert.Equal(0, dto.AvailableQuantity);
            }
        }
        public void when_seat_availability_update_event_has_version_lower_than_last_update_then_event_is_ignored()
        {
            var seatId = Guid.NewGuid();

            this.sut.Handle(new SeatCreated
            {
                ConferenceId = conferenceId,
                SourceId = seatId,
                Name = "seat",
                Description = "description",
                Price = 200,
            });

            this.sut.Handle(new AvailableSeatsChanged
            {
                SourceId = conferenceId,
                Version = 0,
                Seats = new[] { new SeatQuantity { SeatType = seatId, Quantity = 200 } }
            });

            this.sut.Handle(new SeatsReserved
            {
                SourceId = conferenceId,
                Version = 1,
                AvailableSeatsChanged = new[] { new SeatQuantity { SeatType = seatId, Quantity = -50 } }
            });

            this.sut.Handle(new AvailableSeatsChanged
            {
                SourceId = conferenceId,
                Version = 0,
                Seats = new[] { new SeatQuantity { SeatType = seatId, Quantity = 200 } }
            });

            using (var context = new ConferenceRegistrationDbContext(dbName))
            {
                var dto = context.Set<SeatType>()
                    .Where(x => x.ConferenceId == conferenceId)
                    .Single(x => x.Id == seatId);

                Assert.Equal("seat", dto.Name);
                Assert.Equal("description", dto.Description);
                Assert.Equal(200, dto.Price);
                Assert.Equal(150, dto.AvailableQuantity);
                Assert.Equal(1, dto.SeatsAvailabilityVersion);
            }
        }
        public void when_seats_are_released_then_updates_remaining_quantity()
        {
            var seatId = Guid.NewGuid();

            this.sut.Handle(new SeatCreated
            {
                ConferenceId = conferenceId,
                SourceId = seatId,
                Name = "seat",
                Description = "description",
                Price = 200,
            });

            this.sut.Handle(new AvailableSeatsChanged
            {
                SourceId = conferenceId,
                Version = 1,
                Seats = new[] { new SeatQuantity { SeatType = seatId, Quantity = 200 } }
            });

            this.sut.Handle(new SeatsReserved
            {
                SourceId = conferenceId,
                Version = 2,
                AvailableSeatsChanged = new[] { new SeatQuantity { SeatType = seatId, Quantity = -50 } }
            });

            this.sut.Handle(new SeatsReservationCancelled
            {
                SourceId = conferenceId,
                Version = 3,
                AvailableSeatsChanged = new[] { new SeatQuantity { SeatType = seatId, Quantity = 50 } }
            });

            using (var context = new ConferenceRegistrationDbContext(dbName))
            {
                var dto = context.Set<SeatType>()
                    .Where(x => x.ConferenceId == conferenceId)
                    .Single(x => x.Id == seatId);

                Assert.Equal("seat", dto.Name);
                Assert.Equal("description", dto.Description);
                Assert.Equal(200, dto.Price);
                Assert.Equal(200, dto.AvailableQuantity);
                Assert.Equal(3, dto.SeatsAvailabilityVersion);
            }
        }
        public void when_seat_updated_then_updates_seat_on_conference_dto()
        {
            var seatId = Guid.NewGuid();

            this.sut.Handle(new SeatCreated
            {
                ConferenceId = conferenceId,
                SourceId = seatId,
                Name = "seat",
                Description = "description",
                Price = 200,
            });

            this.sut.Handle(new SeatUpdated
            {
                ConferenceId = conferenceId,
                SourceId = seatId,
                Name = "newseat",
                Description = "newdescription",
                Price = 100,
            });

            using (var context = new ConferenceRegistrationDbContext(dbName))
            {
                var dto = context.Set<SeatType>()
                    .Where(x => x.ConferenceId == conferenceId)
                    .Single(x => x.Id == seatId);

                Assert.NotNull(dto);
                Assert.Equal("newseat", dto.Name);
                Assert.Equal("newdescription", dto.Description);
                Assert.Equal(100, dto.Price);
                Assert.Equal(-1, dto.SeatsAvailabilityVersion);
            }
        }
        public void when_seat_created_then_adds_seat()
        {
            var seatId = Guid.NewGuid();

            this.sut.Handle(new SeatCreated
            {
                ConferenceId = conferenceId,
                SourceId = seatId,
                Name = "seat",
                Description = "description",
                Price = 200,
            });

            using (var context = new ConferenceRegistrationDbContext(dbName))
            {
                var dto = context.Set<SeatType>()
                    .Where(x => x.ConferenceId == conferenceId)
                    .Single(x => x.Id == seatId);

                Assert.Equal("seat", dto.Name);
                Assert.Equal("description", dto.Description);
                Assert.Equal(200, dto.Price);
                Assert.Equal(0, dto.AvailableQuantity);
                Assert.Equal(-1, dto.SeatsAvailabilityVersion);
            }
        }
        public void when_seat_availability_update_event_has_version_equal_to_last_update_then_event_is_ignored()
        {
            var seatId = Guid.NewGuid();

            this.sut.Handle(new SeatCreated
            {
                ConferenceId = conferenceId,
                SourceId = seatId,
                Name = "seat",
                Description = "description",
                Price = 200,
            });

            this.sut.Handle(new AvailableSeatsChanged
            {
                SourceId = conferenceId,
                Version = 0,
                Seats = new[] { new SeatQuantity { SeatType = seatId, Quantity = 200 } }
            });

            this.sut.Handle(new SeatsReserved
            {
                SourceId = conferenceId,
                Version = 1,
                AvailableSeatsChanged = new[] { new SeatQuantity { SeatType = seatId, Quantity = -50 } }
            });

            this.sut.Handle(new SeatsReserved
            {
                SourceId = conferenceId,
                Version = 1,
                AvailableSeatsChanged = new[] { new SeatQuantity { SeatType = seatId, Quantity = -50 } }
            });

            using (var context = new ConferenceRegistrationDbContext(dbName))
            {
                var dtos = context.Set<Conference>()
                    .Where(x => x.Id == conferenceId)
                    .SelectMany(x => x.Seats, (Conference, Seat) => new { Conference, Seat })
                    .FirstOrDefault(x => x.Seat.Id == seatId);

                Assert.NotNull(dtos);
                Assert.Equal("seat", dtos.Seat.Name);
                Assert.Equal("description", dtos.Seat.Description);
                Assert.Equal(200, dtos.Seat.Price);
                Assert.Equal(150, dtos.Seat.AvailableQuantity);
                Assert.Equal(1, dtos.Conference.SeatsAvailabilityVersion);
            }
        }
        public void when_seat_created_then_adds_seat_to_conference_dto()
        {
            var seatId = Guid.NewGuid();

            this.sut.Handle(new SeatCreated
            {
                ConferenceId = conferenceId,
                SourceId = seatId,
                Name = "seat",
                Description = "description",
                Price = 200,
            });

            using (var context = new ConferenceRegistrationDbContext(dbName))
            {
                var dto = context.Set<Conference>()
                    .Where(x => x.Id == conferenceId)
                    .SelectMany(x => x.Seats)
                    .FirstOrDefault(x => x.Id == seatId);

                Assert.NotNull(dto);
                Assert.Equal("seat", dto.Name);
                Assert.Equal("description", dto.Description);
                Assert.Equal(200, dto.Price);
                Assert.Equal(0, dto.AvailableQuantity);
            }

        }