/// <summary> /// Creates one instance of Type T /// </summary> /// <param name="reader">Reader with the query result</param> /// <param name="prefix">Optional prefix to identify relevant rows in the query results</param> /// <returns>Instance of object type.</returns> internal static RoomInformation MapReader(IDataReader reader, string prefix = "") { var roomInfo = new RoomInformation { RoomTypes = new List<RoomType>(), }; //get all room types associated with the business while (reader.Read()) { roomInfo.RoomTypes.Add(RoomTypeMapper.MapRecordWithCode(reader)); } // Populate rooms, nested inside the room types if (reader.NextResult()) { while (reader.Read()) { //get all rooms and combined rooms associated with the business var room = RoomMapper.MapRecord(reader); roomInfo.RoomTypes.Find(rt => rt.Id == room.RoomTypeId).Rooms.Add(room); } } if (roomInfo.RoomTypes.Count == 0) { roomInfo = null; } return roomInfo; }
///<summary> /// Convert RoomInformation To RoomInformationDto ///</summary> ///<param name="roomInformation">RoomInformation</param> ///<returns>RoomInformation DTO</returns> public static RoomInformationDto ConvertRoomInformationToDto(RoomInformation roomInformation) { var dto = new RoomInformationDto { Rooms = new List<RoomDto>(), RoomTypes = new List<RoomTypeDto>(), }; if (roomInformation != null) { foreach (var roomType in roomInformation.RoomTypes) { dto.Rooms.AddRange(roomType.Rooms.ConvertAll(ConvertRoomToDto)); dto.Rooms.AddRange(roomType.CombinedRooms.ConvertAll(ConvertRoomToDto)); } dto.RoomTypes = roomInformation.RoomTypes.ConvertAll(ConvertRoomTypeToDto); } if (dto.Rooms.Count == 0 && dto.RoomTypes.Count == 0) { return null; } return dto; }
public void GetRoomInformationValidBusinessReturnsPopulatedObject() { // Arrange const long BUSINESS_ID = 1; const string CULTURE_CODE = "en-GB"; // Stub the BusinessCache to be used by our service method CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID); // invalidate the cache so we make sure our business is loaded into the cache Cache.Business.Invalidate(); var managerReturnData = new RoomInformation { RoomTypes = new List<RoomType> { new RoomType { Id = 1, BusinessId = BUSINESS_ID, Name = "RoomType1", RoomClass = new RoomClass { Code = "TWN" }, QualityType = new QualityType { Code = "CTG" }, BathroomType = new BathroomType { Code = "PB" }, Aspect = new Aspect { Code = "CVW" }, Rooms = new List<Room> { new Room { Id = 1, BusinessId = 1, IsCombined = false, RoomStatus = new RoomStatus { Code = RoomStatusCodes.ACTIVE } } }, BaseRatePlan = new BaseRatePlan() } } }; stubRoomInformationManager.Stub(r => r.GetRoomInformation(BUSINESS_ID, CULTURE_CODE)).Return(managerReturnData); // Act RoomInformationDto receivedObj = PropertyManagementSystemService.GetRoomInformation(BUSINESS_ID, CULTURE_CODE); // Assert Assert.IsNotNull(receivedObj, "The room information returned can't be null"); Assert.AreEqual(1, receivedObj.RoomTypes[0].Rooms.FindAll(r => !r.IsCombined).Count, "The room information should only contain one room"); Assert.AreEqual(0, receivedObj.RoomTypes[0].Rooms.FindAll(r => r.IsCombined).Count, "The room information should not return combined rooms"); Assert.AreEqual(1, receivedObj.RoomTypes.Count, "The room information should return one room type"); Assert.IsNotNull(receivedObj.RoomTypes[0].RatePlans, "Number of Rateplans in the roomtype is null."); // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method CacheHelper.ReAssignBusinessDaoToBusinessCache(); }
public void GetRoomInformationValidBusinessReturnsPopulatedObject() { // Arrange const long BUSINESS_ID = 1; var stubRoomInformationManager = MockRepository.GenerateStub<IRoomInformationManager>(); // Stub the BusinessCache to be used by our service method CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID); // invalidate the cache so we make sure our business is loaded into the cache Cache.Business.Invalidate(); var managerReturnData = new RoomInformation { RoomTypes = new List<RoomType> { new RoomType { Id = 1, BusinessId = BUSINESS_ID, Name = "RoomType1", CombinedRooms = new List<CombinedRoom>(), Rooms = new List<Room> { new Room { Id = 1, BusinessId = 1, IsCombined = false, RoomStatus = new EnumEntity { Code = RoomStatus.ACTIVE } } }, RatePlans = new List<RatePlan>() } } }; stubRoomInformationManager.Stub(r => r.GetRoomInformation(BUSINESS_ID)).Return(managerReturnData); limitedMobileService.RoomInformationManager = stubRoomInformationManager; // Act RoomInformationDto roomInformationDto = limitedMobileService.GetRoomInformation(BUSINESS_ID); // Assert Assert.IsNotNull(roomInformationDto, "The room information returned can't be null"); Assert.AreEqual(1, roomInformationDto.Rooms.FindAll(r => !r.IsCombined).Count, "The room information should only contain one room"); Assert.AreEqual(0, roomInformationDto.Rooms.FindAll(r => r.IsCombined).Count, "The room information should not return combined rooms"); Assert.AreEqual(1, roomInformationDto.RoomTypes.Count, "The room information should return one room type"); Assert.IsNotNull(roomInformationDto.RoomTypes[0].RatePlans, "Number of Rateplans in the roomtype is null."); // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method CacheHelper.ReAssignBusinessDaoToBusinessCache(); }
/// <summary> /// Fills the two rate plan lists in the roomtype part of room information /// </summary> /// <param name="roomInformation">room information object</param> /// <param name="variantRatePlans">variant rate plans from db</param> /// <param name="baseRatePlans">base rate plans from db</param> public void AssociatePlansToRoomType(RoomInformation roomInformation, List<VariantRatePlan> variantRatePlans, List<BaseRatePlan> baseRatePlans) { foreach (RoomType roomType in roomInformation.RoomTypes) { if (variantRatePlans != null) { foreach (VariantRatePlan variant in variantRatePlans) { if (!variant.RoomTypeId.HasValue || variant.RoomTypeId.Value == roomType.Id) { if (roomType.VariantRatePlans == null) { roomType.VariantRatePlans = new List<VariantRatePlan>(); } roomType.VariantRatePlans.Add(variant); } } } if (baseRatePlans != null) { foreach (BaseRatePlan basePlan in baseRatePlans) { if (basePlan.RoomTypeId == roomType.Id) { roomType.BaseRatePlan = basePlan; } } } } }
public void GetRoomInformationValidBusinessReturnsPopulatedRoomInformation() { // Arrange long businessId = 1; const string CULTURE_CODE = "en-GB"; IRoomInformationDao stubRoomInformationDao = MockRepository.GenerateStub<IRoomInformationDao>(); RoomInformationManager roomInformationManager = new RoomInformationManager(); RoomInformation daoReturnData = new RoomInformation { RoomTypes = new List<RoomType> { new RoomType { Id = 1, BusinessId = 1, Name = "RoomType1", Rooms = new List<Room> { new Room { Id = 1, BusinessId = 1, IsCombined = false, RoomStatus = new RoomStatus { Code = RoomStatusCodes.ACTIVE } } }, VariantRatePlans = new List<VariantRatePlan>() } }, }; stubRoomInformationDao.Stub(r => r.GetByBusiness(businessId, CULTURE_CODE)).Return(daoReturnData); roomInformationManager.RoomInformationDao = stubRoomInformationDao; // Act RoomInformation receivedObj = roomInformationManager.GetRoomInformation(businessId, CULTURE_CODE); // Assert Assert.IsNotNull(receivedObj, "The room information returned can't be null"); Assert.AreEqual(1, receivedObj.RoomTypes.Count, "The room information should return one room type"); Assert.AreEqual(1, receivedObj.RoomTypes[0].Rooms.Count, "The room type should only return one room"); }
public void GetRoomInformationWithRateCacheValidBusinessCallsCorrectMethods() { // Arrange const long BUSINESS_ID = 1; const int ROOM_TYPE_ID = 1; const string CULTURE_CODE = "en-GB"; var roomInformationDao = MockRepository.GenerateMock<IRoomInformationDao>(); var variantRatePlanDao = MockRepository.GenerateMock<IVariantRatePlanDao>(); var baseRatePlanDao = MockRepository.GenerateMock<IBaseRatePlanDao>(); var rateCacheManager = MockRepository.GenerateMock<IRateCacheManager>(); var roomInformationManager = new RoomInformationManager { RoomInformationDao = roomInformationDao, VariantRatePlanDao = variantRatePlanDao, BaseRatePlanDao = baseRatePlanDao, RateCacheManager = rateCacheManager }; var returnData = new RoomInformation { RoomTypes = new List<RoomType> { new RoomType { Id = ROOM_TYPE_ID, BusinessId = BUSINESS_ID, Name = "RoomType1", Rooms = new List<Room> { new Room { Id = 1, BusinessId = 1, IsCombined = false, RoomStatus = new RoomStatus { Code = RoomStatusCodes.ACTIVE } } } } }, }; var baseRatePlans = new List<BaseRatePlan> { new BaseRatePlan { RoomTypeId = ROOM_TYPE_ID } }; var variantRatePlans = new List<VariantRatePlan> { new VariantRatePlan { RoomTypeId = ROOM_TYPE_ID }, new VariantRatePlan { RoomTypeId = ROOM_TYPE_ID } }; roomInformationDao.Expect(r => r.GetByBusiness(BUSINESS_ID, CULTURE_CODE)).Return(returnData).Repeat.Once(); variantRatePlanDao.Expect(v => v.GetByBusinessId(BUSINESS_ID, CULTURE_CODE)).Return(variantRatePlans).Repeat.Once(); baseRatePlanDao.Expect(b => b.GetByBusinessId(BUSINESS_ID, CULTURE_CODE)).Return(baseRatePlans).Repeat.Once(); rateCacheManager.Expect(r => r.GetRatesByRoomTypeIdRatePlanIdAndDateRange(Arg<long>.Is.Anything, Arg<int>.Is.Anything, Arg<int>.Is.Anything, Arg<DateTime>.Is.Anything, Arg<DateTime>.Is.Anything)).Repeat.Times(1); // Act roomInformationManager.GetRoomInformationWithRateCache(BUSINESS_ID, DateTime.Now, DateTime.Now.AddDays(1), CULTURE_CODE); // Assert roomInformationDao.VerifyAllExpectations(); baseRatePlanDao.VerifyAllExpectations(); variantRatePlanDao.VerifyAllExpectations(); rateCacheManager.VerifyAllExpectations(); }