Example #1
0
        public void CancelBooking_InValidBooking_ThrowsArgumentException()
        {
            var bookingId = _fixture.Create <Guid>();
            //arrange
            var booking = _context.Order.FirstOrDefault(o => o.Id == bookingId);

            if (booking != null)
            {
                _context.Order.Remove(booking);
                _context.SaveChanges();
            }

            //act
            try
            {
                _bookingService.CancelBooking(bookingId);
            }
            catch (ArgumentException ex)
            {
                ex.Message.Should().Be("Invalid booking");
            }
            catch (Exception ex)
            {
                Assert.Fail("Was expecting ArgumentException");
            }
        }
Example #2
0
        public void CancelBooking_ValidatesRequest()
        {
            //arrange
            var request = _fixture.Create <CancelBookingRequest>();

            //act
            _bookingService.CancelBooking(request);

            //assert
            _cancelBookingRequestValidation.Verify(x => x.ValidateRequest(request), Times.Once);
        }
Example #3
0
        public void CancelBooking_BookingIsNotCancelled_SetsIsCancelled()
        {
            //arrange
            var booking = _fixture.Build <Order>().With(o => o.IsCancelled, false).Create();

            _context.Order.Add(booking);
            _context.SaveChanges();

            //act
            _bookingService.CancelBooking(booking.Id);

            //assert
            booking.IsCancelled.Should().BeTrue();
        }
Example #4
0
        public void CancelBooking_Success_ReturnsTrue()
        {
            // arrange
            SetupTestData();

            // act
            bool result = _bookingService.CancelBooking(100, "683074b8-44c9-468b-9288-dfafa1e533c9");

            bool cancellationStatus = _context.Order.Where(o => o.Id == Guid.Parse("683074b8-44c9-468b-9288-dfafa1e533c9"))
                                      .Select(o => o.Cancelled)
                                      .First();

            // assert
            result.Should().BeTrue();
            cancellationStatus.Should().BeTrue();
        }
        public void CancelBooking_ValidatesRequest()
        {
            //arrange
            var booking = _fixture.Create <Order>();

            _context.Order.Add(booking);
            _context.SaveChanges();

            //act
            _bookingService.CancelBooking(booking.Id);

            //assert
            using (new AssertionScope())
            {
                _cancelBookingValidator.Verify(x => x.ValidateRequest(booking.Id), Times.Once);
            }
        }
Example #6
0
        public IHttpActionResult Delete([FromUri] int id)
        {
            var item = _service.GetBookingById(id);

            if (item == null)
            {
                return(NotFound());
            }
            if (_service.CancelBooking(id))
            {
                return(Ok());
            }
            return(InternalServerError());
        }
Example #7
0
        public void CancelBooking()
        {
            //arrange
            var clinic  = _fixture.Create <Clinic>();
            var doctor  = _fixture.Create <Doctor>();
            var patient = _fixture.Create <Patient>();
            var order   = _fixture.Create <Order>();

            patient.Clinic = clinic;

            _context.Clinic.Add(clinic);
            _context.Patient.Add(patient);
            _context.Doctor.Add(doctor);
            _context.Order.Add(order);

            _context.SaveChanges();


            //act
            _bookingService.CancelBooking(order.Id);

            //assert
            var expected = new Order()
            {
                Id          = order.Id,
                StartTime   = order.StartTime,
                EndTime     = order.EndTime,
                SurgeryType = order.SurgeryType,
                PatientId   = order.PatientId,
                DoctorId    = order.DoctorId,
                Cancelled   = true,
            };

            _context.Order.Find(order.Id).Should().BeEquivalentTo(expected,
                                                                  options => options
                                                                  .ExcludingNestedObjects()
                                                                  .IgnoringCyclicReferences()
                                                                  .Excluding(order => order.Id)
                                                                  .Excluding(order => order.Patient)
                                                                  .Excluding(order => order.Doctor));
        }
Example #8
0
        public async Task ShouldCancelBooking()
        {
            using var connection = new SqliteConnection("Filename=:memory:");
            connection.Open();

            var options = new DbContextOptionsBuilder <DiallogDbContext>()
                          .UseSqlite(connection)
                          .Options;

            using var dbContext = new DiallogDbContext(options);
            dbContext.Database.EnsureCreated();

            var bookingService = new BookingService(dbContext);

            var booking = new Booking
            {
                GuestUserId = "XXXXXX",
                GuestName   = "XXXXXX",
                Car         = new Car {
                    DailyRentalCost = 100, GasConsumption = "XXXXX", NumberOfUnits = 3
                },
                StartDateUtc = DateTime.UtcNow,
                EndDateUtc   = DateTime.UtcNow.AddDays(3)
            };

            var result = await bookingService.AddBooking(booking);

            Assert.True(result.Success);
            Assert.Equal(1, result.Id);
            Assert.Empty(result.ValidationErrors);

            var bookingId = result.Id.Value;

            result = await bookingService.CancelBooking("tester", bookingId);

            booking = await bookingService.GetBooking(bookingId);

            Assert.Equal(BookingStatus.Cancelled, booking.Status);
        }
        public ActionResult Cancel(int roomId)
        {
            _service.CancelBooking(roomId);

            return(Json(true, JsonRequestBehavior.AllowGet));
        }