Ejemplo n.º 1
0
        static void activateReservation()
        {
            Console.WriteLine("Activating reservation, to go back input '_back_'.");
            Console.WriteLine("Format: 'reservationId'");
            Console.WriteLine("Example: 1");
            Console.Write(">");
            var input = Console.ReadLine();

            if (input == "_back_")
            {
                return;
            }

            try
            {
                var param = int.Parse(input.Trim());
                using (var crs = new CarReservationService())
                {
                    var asyncAr = crs.activateReservation(param);
                    asyncAr.Wait();
                    var ar = asyncAr.Result;
                    Console.WriteLine("Reservation with id " + param + " has been activated.");
                    Console.WriteLine("ActivatedReservation id is " + ar.id + ".");
                }
            }
            catch (Exception e)
            {
                printExceptions(e);
            }
        }
Ejemplo n.º 2
0
        public void SuccessfullyActivatesReservationAfterCollidingActivatedReservationIsDeactivated()
        {
            var customerMockSet             = new Mock <DbSet <BasicCustomer> >();
            var rentalCarMockSet            = new Mock <DbSet <RentalCar> >();
            var carTypeMockSet              = new Mock <DbSet <RentalCarType> >();
            var mockContext                 = new Mock <CarRentalContext>();
            var reservationMockSet          = new Mock <DbSet <Reservation> >();
            var activatedReservationMockSet = new Mock <DbSet <ActivatedReservation> >();

            unitTestHelper.setUpMockBasicCustomers(customerMockSet, mockContext);
            unitTestHelper.setUpMockCars(rentalCarMockSet, carTypeMockSet, mockContext);

            var carTypes = carTypeMockSet.Object.ToArray();
            var carType1 = carTypes[0];
            var carType2 = carTypes[1];
            var customer = customerMockSet.Object.ToArray()[0];

            var reservation1 = new Reservation(
                customer,
                carType2,
                DateTime.Now,
                DateTime.Now.AddDays(2));

            var reservation2 = new Reservation(
                customer,
                carType2,
                DateTime.Now,
                DateTime.Now.AddDays(2));

            reservation1.id = 0;
            reservation2.id = 1;

            unitTestHelper.setUpMockReservations(new List <Reservation> {
                reservation1, reservation2
            }, carTypeMockSet, customerMockSet, reservationMockSet, mockContext);

            using (var csr = new CarReservationService(mockContext.Object))
            {
                var reservations = reservationMockSet.Object.ToArray();
                var rentalcars   = rentalCarMockSet.Object.ToArray();
                var existingActivatedReservation = new ActivatedReservation(reservations[0], rentalcars[1], 0, false);

                unitTestHelper.setUpMockActivatedReservations(new List <ActivatedReservation> {
                    existingActivatedReservation
                }, activatedReservationMockSet, mockContext);

                var asyncActivatedReservation = csr.activateReservation(reservation1.id);
                asyncActivatedReservation.Wait();
                var activatedReservation = asyncActivatedReservation.Result;


                activatedReservationMockSet.Verify(a => a.Add(It.IsAny <ActivatedReservation>()), Times.Once());
                mockContext.Verify(a => a.SaveChangesAsync(), Times.Once());
            }
        }
Ejemplo n.º 3
0
        public void FailsToActivateReservationWhenRentalDateHasNotYetBeenMet()
        {
            var customerMockSet             = new Mock <DbSet <BasicCustomer> >();
            var rentalCarMockSet            = new Mock <DbSet <RentalCar> >();
            var carTypeMockSet              = new Mock <DbSet <RentalCarType> >();
            var mockContext                 = new Mock <CarRentalContext>();
            var reservationMockSet          = new Mock <DbSet <Reservation> >();
            var activatedReservationMockSet = new Mock <DbSet <ActivatedReservation> >();

            unitTestHelper.setUpMockBasicCustomers(customerMockSet, mockContext);
            unitTestHelper.setUpMockCars(rentalCarMockSet, carTypeMockSet, mockContext);

            var carTypes = carTypeMockSet.Object.ToArray();
            var carType1 = carTypes[0];
            var carType2 = carTypes[1];
            var customer = customerMockSet.Object.ToArray()[0];

            var reservation1 = new Reservation(
                customer,
                carType2,
                DateTime.Now.AddDays(1),
                DateTime.Now.AddDays(2));

            reservation1.id = 0;

            unitTestHelper.setUpMockReservations(new List <Reservation> {
                reservation1
            }, carTypeMockSet, customerMockSet, reservationMockSet, mockContext);
            unitTestHelper.setUpMockActivatedReservations(new List <ActivatedReservation>(), activatedReservationMockSet, mockContext);

            using (var csr = new CarReservationService(mockContext.Object))
            {
                try
                {
                    var reservations = reservationMockSet.Object.ToArray();
                    var reservation  = reservations[0];

                    var asyncActivatedReservation = csr.activateReservation(reservation.id);
                    asyncActivatedReservation.Wait();
                    var activatedReservation = asyncActivatedReservation.Result;

                    Assert.IsNull(activatedReservation);
                    activatedReservationMockSet.Verify(a => a.Add(It.IsAny <ActivatedReservation>()), Times.Never());
                }
                catch (Exception e)
                {
                    Assert.IsTrue(e.GetType() == new InvalidOperationException().GetType() || e.InnerException is InvalidOperationException);
                }
            }
        }
Ejemplo n.º 4
0
        public void SuccessfullyActivatesReservationWhenCarsAreAvailable()
        {
            var customerMockSet             = new Mock <DbSet <BasicCustomer> >();
            var rentalCarMockSet            = new Mock <DbSet <RentalCar> >();
            var carTypeMockSet              = new Mock <DbSet <RentalCarType> >();
            var mockContext                 = new Mock <CarRentalContext>();
            var reservationMockSet          = new Mock <DbSet <Reservation> >();
            var activatedReservationMockSet = new Mock <DbSet <ActivatedReservation> >();

            unitTestHelper.setUpMockBasicCustomers(customerMockSet, mockContext);
            unitTestHelper.setUpMockCars(rentalCarMockSet, carTypeMockSet, mockContext);

            var carTypes = carTypeMockSet.Object.ToArray();
            var carType1 = carTypes[0];
            var carType2 = carTypes[1];
            var customer = customerMockSet.Object.ToArray()[0];

            var reservation1 = new Reservation(
                customer,
                carType2,
                DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0)),
                DateTime.Now.AddDays(1));

            reservation1.id = 0;

            unitTestHelper.setUpMockReservations(new List <Reservation> {
                reservation1
            }, carTypeMockSet, customerMockSet, reservationMockSet, mockContext);
            unitTestHelper.setUpMockActivatedReservations(new List <ActivatedReservation>(), activatedReservationMockSet, mockContext);

            using (var csr = new CarReservationService(mockContext.Object))
            {
                var reservation = reservationMockSet.Object.First();

                var asyncActivatedReservation = csr.activateReservation(reservation.id);
                asyncActivatedReservation.Wait();
                var activatedReservation = asyncActivatedReservation.Result;

                activatedReservationMockSet.Verify(a => a.Add(It.IsAny <ActivatedReservation>()), Times.Once());
                mockContext.Verify(a => a.SaveChangesAsync(), Times.Once());
            }
        }