public void Request_SearchRequestIsValid_TheReturnedResultShouldBeOfTypeHotelAvailabilityRequest()
        {
            var availabilityService = new AvailabilityService(_mockedHotelRepository.Object, _mockedHotelAvailability.Object, _mockedPricingService.Object);
            var result = availabilityService.Request(_searchFixtureData.ValidRequestCase1);

            Assert.IsType <HotelAvailabilityRequest>(result);
        }
Ejemplo n.º 2
0
        public void CheckAvailability_ValidSearchRequestAndResultIsReturnedWithTwoHotels_NewPriceShouldBeBiggerThanPrice()
        {
            //Arrange

            _hotelAvailability.Setup(x => x.SearchHotelAvailability(It.IsAny <HotelAvailabilityRequest>())).Returns(_hotelFixtureData.MockedHotelAvailabilityResponse);
            _pricingService.SetupSequence(x => x.CalculatePrice(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <decimal>()))
            .Returns(120)
            .Returns(170);
            //TODO: Check this
            //_pricingService.SetupSequence(x =>
            //            x.CalculatePrice(_hotelFixtureData.MockedHotelAvailabilityResponse.CheckIn,
            //                             _hotelFixtureData.MockedHotelAvailabilityResponse.CheckOut,
            //                             100))
            //    .Returns(120)
            //    .Returns(170);

            //Act
            var availabilityService = new AvailabilityService(_hotelRepository.Object, _hotelAvailability.Object, _pricingService.Object);
            var result = availabilityService.CheckAvailability(_searchFixtureData.ValidRequestCase1, It.IsAny <List <string> >());

            //Assert
            foreach (var item in result.AvailableHotels)
            {
                foreach (var room in item.AvailableRooms)
                {
                    //Assert.True(room.NewPrice > room.Price);
                    room.NewPrice.Should().BeGreaterThan(room.Price);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task AvailabilityService_Request_RequestExecuted()
        {
            var mockFactory = new Mock <IHttpClientFactory>();

            var mockHttpMessageHandler = new Mock <HttpMessageHandler>();

            mockHttpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("{'health':'Ok'}")
            });

            var client = new HttpClient(mockHttpMessageHandler.Object);

            mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);

            var availabilityService = new AvailabilityService(mockFactory.Object);

            var response = await availabilityService.Request("http://google.com/", CancellationToken.None)
                           .ConfigureAwait(false);

            Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);
            Assert.Equal("{'health':'Ok'}", response.Body);
        }
        public void ValidateSearchRequest_OnlyChildren_ShouldThrowException()
        {
            //Arrange

            //Act
            var availabilityService = new AvailabilityService(_mockedHotelRepository.Object, _mockedHotelAvailability.Object, _mockedPricingService.Object);

            //Arrange
            Assert.Throws <Exception>(() => availabilityService.ValidatedSearchRequest(_searchFixtureData.RequestCase5));
        }
Ejemplo n.º 5
0
        public void ValidateSearchRequest_InvalidAtLeastOneAdultPerRoomSearchReqest_ShouldThrowException()
        {
            //Arrange

            //Act
            var availabilityService = new AvailabilityService(_hotelRepository.Object, _hotelAvailability.Object, _pricingService.Object);

            //Assert
            Assert.Throws <Exception>(() => availabilityService.ValidateSearchRequest(_searchFixtureData.RequestCase4));
        }
        public void CheckAvailability_ValidSearchRequestAndTheServiceReturnedTwoHotels_ResultShouldContainTwoHotels()
        {
            _mockedHotelAvailability.Setup(x => x.SearchHotelAvailability(It.IsAny <HotelAvailabilityRequest>())).Returns(_searchServiceFixtureData.MockedHotelAvailabilityResponse);
            int expCount = 2;

            var availabilityService = new AvailabilityService(_mockedHotelRepository.Object, _mockedHotelAvailability.Object, _mockedPricingService.Object);
            var result = availabilityService.CheckAvailability(_searchFixtureData.ValidRequestCase1, It.IsAny <List <string> >());

            Assert.Equal(expCount, result.Count);
        }
Ejemplo n.º 7
0
        public void ValidateSearchRequest_InvalidDateFromIsBiggerThanDateToInSearchReqest_ShouldThrowException()
        {
            //Arrange

            //Act
            var availabilityService = new AvailabilityService(_hotelRepository.Object, _hotelAvailability.Object, _pricingService.Object);

            //Assert
            Assert.Throws <Exception>(() => availabilityService.ValidateSearchRequest(_searchFixtureData.RequestCase3));
        }
Ejemplo n.º 8
0
        public void Request_SearchRequestIsValid_ResultShouldBeOfTypeHotelAvailabilityRequest()
        {
            //Arrange

            //Act
            var availabilityService = new AvailabilityService(_hotelRepository.Object, _hotelAvailability.Object, _pricingService.Object);
            var result = availabilityService.Request(_searchFixtureData.ValidRequestCase1, It.IsAny <List <string> >());

            //Assert
            Assert.IsType <HotelAvailabilityRequest>(result);
        }
        public void Request_SearchRequestIsValid_ShouldHaveCorrectData()
        {
            var availabilityService = new AvailabilityService(_mockedHotelRepository.Object, _mockedHotelAvailability.Object, _mockedPricingService.Object);
            var result = availabilityService.Request(_searchFixtureData.ValidRequestCase1);

            Assert.Equal(_searchFixtureData.HotelAvailabilityRequestCase1.CheckIn, result.CheckIn);
            Assert.Equal(_searchFixtureData.HotelAvailabilityRequestCase1.CheckOut, result.CheckOut);
            Assert.Equal(_searchFixtureData.HotelAvailabilityRequestCase1.Nights, result.Nights);
            Assert.Equal(_searchFixtureData.HotelAvailabilityRequestCase1.Adults, result.Adults);
            Assert.Equal(_searchFixtureData.HotelAvailabilityRequestCase1.Children, result.Children);
        }
        public void ValidateSearchRequest_InvalidToDate_ShouldThrowException()
        {
            //Arrange
            var expMsg = "ToDate must have value";
            //Act
            var availabilityService = new AvailabilityService(_mockedHotelRepository.Object, _mockedHotelAvailability.Object, _mockedPricingService.Object);

            //Arrange
            var result = Assert.Throws <Exception>(() => availabilityService.ValidatedSearchRequest(_searchFixtureData.RequestCase2));

            Assert.Equal(expMsg, result.Message);
        }
Ejemplo n.º 11
0
        public void CheckAvailability_ValidSearchRequestAndResultIsReturnedWithTwoHotels_ResultShouldContainTwoHotels()
        {
            //Arrange
            _hotelAvailability.Setup(x => x.SearchHotelAvailability(It.IsAny <HotelAvailabilityRequest>())).Returns(_hotelFixtureData.MockedHotelAvailabilityResponse);
            int expectedHotelsCount = 2;

            //Act
            var availabilityService = new AvailabilityService(_hotelRepository.Object, _hotelAvailability.Object, _pricingService.Object);
            var result = availabilityService.CheckAvailability(_searchFixtureData.ValidRequestCase1, It.IsAny <List <string> >());

            //Assert
            Assert.Equal(expectedHotelsCount, result.AvailableHotels.Count);
        }
Ejemplo n.º 12
0
        public virtual int SaveChanges(List <Booking> bookings, bool dontCheckClash)
        {
            int objectsWritten = 0;

            if (!dontCheckClash)
            {
                AvailabilityService aC = new AvailabilityService(_bookingRepository, _roomRepository, _locationRepository);
                List <Booking>      clashedBookings;

                using (var scope = TransactionUtils.CreateTransactionScope())
                {
                    foreach (var b in bookings)
                    {
                        bool invalid = aC.DoesMeetingClash(b, out clashedBookings);
                        //Checks if the booking that clashed is the current booking being saved, this allows us to edit bookings.
                        if (clashedBookings.Count == 1)
                        {
                            if (invalid && b.ID != 0)
                            {
                                invalid = !(b.ID == clashedBookings[0].ID);
                            }
                        }

                        if (invalid)
                        {
                            throw new BookingConflictException("Simultaneous booking conflict, please try again.");
                        }
                    }

                    //We dont mess around with the recurrence ID's after they are first created. So if the first booking in the batch has an ID, it exists in the DB. So dont go on further.
                    if (bookings.First().ID == 0)
                    {
                        int?recurrenceId = bookings.Select(x => x.RecurrenceId).FirstOrDefault();
                        //Check if the recurrence id is infact the next id in the DB (could potentially not be if a recurrence was made during execution of this request)
                        int nextRecurrenceId = _bookingRepository.GetNextRecurrenceId();
                        if (recurrenceId != null && recurrenceId != nextRecurrenceId)
                        {
                            //if the bookings recurrenceid is not the next, then set it.
                            bookings.ForEach(x => x.RecurrenceId = nextRecurrenceId);
                        }
                    }
                    objectsWritten = base.SaveChanges();
                    scope.Complete();
                }
            }
            else
            {
                objectsWritten = base.SaveChanges();
            }
            return(objectsWritten);
        }
Ejemplo n.º 13
0
        public AvailabilityController(VORBSContext context,
                                      IBookingRepository bookingRepository,
                                      ILocationRepository locationRepository,
                                      IRoomRepository roomsRepository)
        {
            _logger = NLog.LogManager.GetCurrentClassLogger();
            db      = context;
            _availabilityService = new AvailabilityService(bookingRepository, roomsRepository, locationRepository);

            _bookingRepository  = bookingRepository;
            _locationRepository = locationRepository;
            _roomsRepository    = roomsRepository;

            _logger.Trace(LoggerHelper.InitializeClassMessage());
        }
Ejemplo n.º 14
0
        public void Request_SearchRequestIsValid_ShouldContainCorrectData()
        {
            //Arrange

            //Act
            var availabilityService = new AvailabilityService(_hotelRepository.Object, _hotelAvailability.Object, _pricingService.Object);
            var result = availabilityService.Request(_searchFixtureData.ValidRequestCase1, It.IsAny <List <string> >());

            //Assert
            //Assert.Equal(_searchFixtureData.HotelAvailabilityRequestCase1.CheckIn, result.CheckIn);
            //Assert.Equal(_searchFixtureData.HotelAvailabilityRequestCase1.CheckOut, result.CheckOut);
            Assert.Equal(_searchFixtureData.HotelAvailabilityRequestCase1.Nights, result.Nights);
            Assert.Equal(_searchFixtureData.HotelAvailabilityRequestCase1.Adults, result.Adults);
            Assert.Equal(_searchFixtureData.HotelAvailabilityRequestCase1.Children, result.Children);
            Assert.Equal(_searchFixtureData.HotelAvailabilityRequestCase1.Rooms, result.Rooms);
        }
Ejemplo n.º 15
0
        public Client(string userName, string password)
        {
            this.UserName = userName;
            this.Password = password;

            ApplicationLoadService  = new ApplicationLoadService(this);
            AuthenticateService     = new AuthenticateService(this);
            AvailabilityService     = new AvailabilityService(this);
            CurrentPayPeriodService = new CurrentPayPeriodService(this);
            MobileCarrierService    = new MobileCarrierService(this);
            NotificationService     = new NotificationService(this);
            OfficeService           = new OfficeService(this);
            PlacementService        = new PlacementService(this);
            TimesheetService        = new TimesheetService(this);
            UserService             = new UserService(this);
        }
        public void CheckAvailability_ValidSearchRequestAndTheServiceReturnedTwoHotels_TheNewPriceShouldHaveValue()
        {
            _mockedHotelAvailability.Setup(x => x.SearchHotelAvailability(It.IsAny <HotelAvailabilityRequest>())).Returns(_searchServiceFixtureData.MockedHotelAvailabilityResponse);
            _mockedPricingService.Setup(x => x.CalculatePrice(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <decimal>())).Returns(150);

            var availabilityService = new AvailabilityService(_mockedHotelRepository.Object, _mockedHotelAvailability.Object, _mockedPricingService.Object);
            var result = availabilityService.CheckAvailability(_searchFixtureData.ValidRequestCase1, It.IsAny <List <string> >());

            foreach (var item in result.AvailableHotels)
            {
                item.AvailableRooms.Select(x => x.NewPrice).Should().NotContainNulls();
                //foreach (var room in item.AvailableRooms)
                //{
                //    Assert.True(room.NewPrice > 0);
                //}
            }
        }
Ejemplo n.º 17
0
        public async Task GetUnavailabilityForFutureReturnsCorrectAvailability(int employeeId, int year, int month, int day)
        {
            var datetime = new DateTime(year, month, day);
            var expected = new Dictionary <long, Availability>();

            _modelMocks.PlannedEvents
            .OfType <Availability>()
            .Where(a => a.StartTime > datetime && a.Employee.Id == employeeId && a.EventTitle == "Niet beschikbaar")
            .ToList()
            .ForEach(
                availability => AvailabilityService.CalculateTimeFromEpoch(availability)
                .ToList()
                .ForEach(l => expected.Add(l, availability)));

            Dictionary <long, Availability> actual = await _availabilityService.GetUnavailabilityForFuture(employeeId, datetime);

            Assert.Equal(expected, actual);
        }
        public void CheckAvailability_ValidSearchRequestAndTheServiceReturnedTwoHotelsWithSetupSequence_TheNewPriceShouldBeBiggerThanPrice()
        {
            _mockedHotelAvailability.Setup(x => x.SearchHotelAvailability(It.IsAny <HotelAvailabilityRequest>())).Returns(_searchServiceFixtureData.MockedHotelAvailabilityResponse);
            _mockedPricingService.SetupSequence(x => x.CalculatePrice(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <decimal>()))
            .Returns(120)
            .Returns(180);

            var availabilityService = new AvailabilityService(_mockedHotelRepository.Object, _mockedHotelAvailability.Object, _mockedPricingService.Object);
            var result = availabilityService.CheckAvailability(_searchFixtureData.ValidRequestCase1, It.IsAny <List <string> >());

            foreach (var item in result.AvailableHotels)
            {
                //item.AvailableRooms.Select(x => x.NewPrice).Should().HaveCountGreaterThan();
                foreach (var room in item.AvailableRooms)
                {
                    Assert.True(room.NewPrice > room.Price);
                }
            }
        }
Ejemplo n.º 19
0
        public virtual int SaveChanges(Booking booking, bool dontCheckClash)
        {
            List <Booking> clashedBookings;
            int            objectsWritten = 0;

            if (!dontCheckClash)
            {
                using (var scope = TransactionUtils.CreateTransactionScope())
                {
                    AvailabilityService aC = new AvailabilityService(_bookingRepository, _roomRepository, _locationRepository);

                    bool invalid = aC.DoesMeetingClash(booking, out clashedBookings);
                    //Checks if the booking that clashed is the current booking being saved, this allows us to edit bookings.
                    if (clashedBookings.Count == 1)
                    {
                        if (invalid && booking.ID != 0)
                        {
                            invalid = !(booking.ID == clashedBookings[0].ID);
                        }
                    }

                    if (invalid)
                    {
                        throw new BookingConflictException("Simultaneous booking conflict, please try again.");
                    }

                    objectsWritten = base.SaveChanges();
                    scope.Complete();
                }
            }
            else
            {
                objectsWritten = base.SaveChanges();
            }
            return(objectsWritten);
        }
 public AvailabilitiesController(IMapper mapper, AvailabilityService availabilityService)
 {
     _mapper = mapper;
     _availabilityService = availabilityService;
 }
Ejemplo n.º 21
0
        public List <Booking> GetAvailableSmartRoomBookings(Booking newBooking, out List <Booking> clashedBookings)
        {
            List <Booking> bookingsToCreate = new List <Booking>();
            List <Booking> clashedBs        = new List <Booking>();
            List <int>     smartRoomIds     = new List <int>();

            smartRoomIds.Add(newBooking.RoomID);

            AvailabilityService aC = new AvailabilityService(this, _roomRepository, _locationRepository);

            foreach (var smartLoc in newBooking.SmartLoactions)
            {
                int smartLocId = 0;
                int.TryParse(smartLoc, out smartLocId);

                Room smartLocData = db.Rooms.Where(x => x.ID == smartLocId).Select(x => x).ToList().FirstOrDefault();

                List <Booking> doesClash;
                Room           roomToBook = null;
                if (aC.DoesMeetingClash(new Booking()
                {
                    StartDate = newBooking.StartDate, EndDate = newBooking.EndDate, RoomID = smartLocData.ID
                }, out doesClash))
                {
                    roomToBook = aC.GetAlternateSmartRoom(smartRoomIds, newBooking.StartDate, newBooking.EndDate, db.Locations.Single(l => l.Name == smartLocData.Location.Name).ID);
                }
                else
                {
                    roomToBook = smartLocData;
                }

                if (roomToBook == null || bookingsToCreate.Select(x => x.Room).Contains(roomToBook))
                {
                    clashedBs.Add(new Booking()
                    {
                        StartDate      = newBooking.StartDate,
                        Owner          = newBooking.Owner,
                        IsSmartMeeting = true,
                        Room           = smartLocData
                    });
                }
                else
                {
                    bookingsToCreate.Add(new Booking()
                    {
                        DssAssist         = newBooking.DssAssist,
                        ExternalAttendees = newBooking.ExternalAttendees,
                        Flipchart         = newBooking.Flipchart,
                        NumberOfAttendees = newBooking.Room.SeatCount,
                        Owner             = newBooking.Owner,
                        PID            = newBooking.PID,
                        Projector      = newBooking.Projector,
                        RoomID         = roomToBook.ID,
                        Room           = roomToBook,
                        Subject        = newBooking.Subject,
                        StartDate      = newBooking.StartDate,
                        EndDate        = newBooking.EndDate,
                        IsSmartMeeting = true
                    });

                    smartRoomIds.Add(roomToBook.ID);
                }
            }

            clashedBookings = clashedBs;

            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(bookingsToCreate, clashedBookings));

            return(bookingsToCreate);
        }
 public AvailabilityController(AvailabilityService service)
 {
     this.service = service;
 }
Ejemplo n.º 23
0
 public ConfigurationCommands(IDbContextFactory <DatabaseContext> db, AvailabilityService availability)
 {
     _db           = db;
     _availability = availability;
 }
Ejemplo n.º 24
0
        public List <RoomDTO> GetAvailableRoomsForLocation(string location, DateTime start, DateTime end, int numberOfPeople, bool smartRoom, int existingBookignId)
        {
            List <RoomDTO> rooms = new List <RoomDTO>();

            if (location == null)
            {
                return(new List <RoomDTO>());
            }

            List <Room> roomData = new List <Room>();

            //var locationRooms = db.Rooms.Where(x => x.Location.Name == location && x.SeatCount >= numberOfPeople).ToList();

            try
            {
                List <Room> availableRooms = new List <Room>();

                Booking existingBooking = _bookingRepository.GetById(existingBookignId);

                List <Booking> clashedBookings;
                existingBooking.StartDate = start;
                existingBooking.EndDate   = end;

                AvailabilityService availabilityService = new AvailabilityService(_bookingRepository, _roomsRepository, _locationRepository);
                bool meetingClash = availabilityService.DoesMeetingClash(existingBooking, out clashedBookings);

                if (meetingClash && clashedBookings.Count == 1 && clashedBookings[0].ID == existingBooking.ID)
                {
                    availableRooms.Add(existingBooking.Room);
                }

                else
                {
                    availableRooms = db.Rooms.Where(x => x.Location.Name == location && x.SeatCount >= numberOfPeople && x.Active == true && x.SmartRoom == smartRoom &&
                                                    (x.Bookings.Where(b => start <b.EndDate && end> b.StartDate && b.ID != existingBookignId).Count() == 0)) //Do any bookings overlap
                                     .OrderBy(r => r.SeatCount)
                                     .ToList();
                }
                roomData.AddRange(availableRooms);

                roomData.ForEach(x => rooms.Add(new RoomDTO()
                {
                    ID            = x.ID,
                    RoomName      = x.RoomName,
                    PhoneCount    = x.PhoneCount,
                    ComputerCount = x.ComputerCount,
                    SeatCount     = x.SeatCount,
                    SmartRoom     = x.SmartRoom,
                    Bookings      = x.Bookings.Where(b => b.StartDate.Date == start.Date && b.EndDate.Date == end.Date).Select(b =>
                    {
                        BookingDTO bDto = new BookingDTO()
                        {
                            ID             = b.ID,
                            Owner          = b.Owner,
                            StartDate      = b.StartDate,
                            EndDate        = b.EndDate,
                            IsSmartMeeting = b.IsSmartMeeting
                        };
                        return(bDto);
                    }).ToList()
                }));
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to get available rooms for location: " + location, ex);
            }
            return(rooms);
        }
Ejemplo n.º 25
0
 public AvailabilityCommands(ILogger <AvailabilityCommands> logger, AvailabilityService availability)
 {
     _logger       = logger;
     _availability = availability;
 }