Example #1
0
        public async Task GivenExistingBooking_WhenUpdatedWithTooManyCabins_ShouldPreserveExistingBooking()
        {
            Assert.AreEqual(10, Config.NumberOfCabins);

            var cruise = await CruiseRepositoryTest.GetCruiseForTestAsync();

            var repository = GetBookingRepositoryForTest();

            // First create a booking of 9/10 cabins
            var nineOutOfTenCabins = new BookingSource.Cabin[9];

            for (int i = 0; i < nineOutOfTenCabins.Length; i++)
            {
                nineOutOfTenCabins[i] = GetCabinForTest(SjoslagetDbExtensions.CabinTypeId, GetPaxForTest());
            }
            var bookingThatFillsNineOutOfTenCabins = GetBookingForTest(nineOutOfTenCabins);
            await repository.CreateAsync(cruise, bookingThatFillsNineOutOfTenCabins);

            // Then create a booking for the 10th cabin
            var source = GetBookingForTest(GetCabinForTest(SjoslagetDbExtensions.CabinTypeId, GetPaxForTest(firstName: "Test1", lastName: "Test2")));
            var result = await repository.CreateAsync(cruise, source);

            var booking = await repository.FindByReferenceAsync(result.Reference);

            var cabins = await repository.GetCabinsForBookingAsync(booking);

            Assert.AreEqual(1, cabins.Length);

            // Now try to update it with two bookings
            source = GetBookingForTest(
                GetCabinForTest(SjoslagetDbExtensions.CabinTypeId, GetPaxForTest()),
                GetCabinForTest(SjoslagetDbExtensions.CabinTypeId, GetPaxForTest())
                );
            source.Reference = result.Reference;

            try
            {
                result = await repository.UpdateAsync(cruise, source);

                Assert.Fail("Update booking did not throw.");
            }
            catch (AvailabilityException)
            {
            }

            // Check to make sure it is still there
            booking = await repository.FindByReferenceAsync(result.Reference);

            cabins = await repository.GetCabinsForBookingAsync(booking);

            Assert.AreEqual(1, cabins.Length);

            var pax = cabins[0].Pax[0];

            Assert.AreEqual(pax.FirstName, "Test1");
            Assert.AreEqual(pax.LastName, "Test2");
        }
Example #2
0
        static BookingSource.Cabin CreateUpdatedCabin(params BookingSource.Pax[] pax)
        {
            var updated = new BookingSource.Cabin {
                Pax = new List <BookingSource.Pax>(pax.Length)
            };

            updated.Pax.AddRange(pax);
            return(updated);
        }
Example #3
0
        static BookingSource.Cabin CreateUpdatedCabinWithOnePax(string firstName, string lastName)
        {
            var updated = new BookingSource.Cabin
            {
                Pax = new List <BookingSource.Pax>
                {
                    new BookingSource.Pax
                    {
                        FirstName = firstName,
                        LastName  = lastName
                    }
                }
            };

            return(updated);
        }
Example #4
0
        public async Task GivenExistingBooking_WhenUpdatedWithMoreCabins_ShouldAllowUpToMaximumCapacity()
        {
            Assert.AreEqual(10, Config.NumberOfCabins);

            var cruise = await CruiseRepositoryTest.GetCruiseForTestAsync();

            var repository = GetBookingRepositoryForTest();

            // First create a booking of 8/10 cabins
            var eightOutOfTenCabins = new BookingSource.Cabin[8];

            for (int i = 0; i < eightOutOfTenCabins.Length; i++)
            {
                eightOutOfTenCabins[i] = GetCabinForTest(SjoslagetDbExtensions.CabinTypeId, GetPaxForTest());
            }

            var booking = GetBookingForTest(eightOutOfTenCabins);
            var result  = await repository.CreateAsync(cruise, booking);

            // Now update it to 9/10 cabins
            var nineOutOfTenCabins = new BookingSource.Cabin[9];

            for (int i = 0; i < nineOutOfTenCabins.Length; i++)
            {
                nineOutOfTenCabins[i] = GetCabinForTest(SjoslagetDbExtensions.CabinTypeId, GetPaxForTest());
            }

            booking           = GetBookingForTest(nineOutOfTenCabins);
            booking.Reference = result.Reference;
            result            = await repository.UpdateAsync(cruise, booking);

            var savedBooking = await repository.FindByReferenceAsync(result.Reference);

            var cabins = await repository.GetCabinsForBookingAsync(savedBooking);

            Assert.AreEqual(9, cabins.Length);
        }