예제 #1
0
        public async Task <IActionResult> PostRoomAsync
            ([FromBody, Bind("ComplexID, RoomID, RoomNumber, NumberOfBeds, NumberOfOccupants, Gender, RoomType, LeaseStart, LeaseEnd")] Lib.Room room)
        {
            try
            {
                _logger.LogInformation("Adding a room");

                var createdRoom = new Lib.Room
                {
                    ComplexId         = room.ComplexId,
                    RoomId            = room.RoomId,
                    RoomNumber        = room.RoomNumber,
                    NumberOfBeds      = room.NumberOfBeds,
                    NumberOfOccupants = room.NumberOfOccupants,
                    Gender            = room.Gender,
                    RoomType          = room.RoomType
                };
                createdRoom.SetLease(room.LeaseStart, room.LeaseEnd);

                await _repository.CreateRoomAsync(createdRoom);

                await _repository.SaveAsync();

                _logger.LogInformation("Success. Room has been added");

                return(CreatedAtRoute("GetRoom", new { RoomID = createdRoom.RoomId }, createdRoom));
            }
            catch (ArgumentException ex)
            {
                _logger.LogInformation("Lease was invalid", ex);
                return(BadRequest());
            }
        }
        public async Task PutRoomShouldReturnNotFound()
        {
            //arrange
            var mockRepo = new Mock <IRepository>();

            var mockLogger = new Mock <ILogger <ComplexController> >();

            mockRepo.Setup(r => r.UpdateRoomAsync(
                               It.IsAny <Lib.Room>()
                               )).Throws(new InvalidOperationException());

            mockRepo.Setup(r => r.ReadRoomAsync(It.IsAny <Guid>())).Returns(Task.FromResult <Lib.Room>(new Lib.Room()));

            var controller = new ComplexController(mockRepo.Object, mockLogger.Object);;

            //act
            var roomTest = new Lib.Room();

            //Need to set lease or else we will get an Argument Exception instead of InvalidOperation Exception
            roomTest.SetLease(DateTime.Now, DateTime.Now.AddDays(3));

            var result = await controller.PutRoomAsync(Guid.NewGuid(), roomTest);

            //assert
            Assert.IsType <NotFoundResult>(result);
        }
예제 #3
0
        /// <summary>
        /// Method that converts a DB Entities Room Object to a Business Logic Library Room Object
        /// Maps RoomId, ComplexId, Gender, RoomNumber, RoomType, NumberOfBeds, LeaseStart, LeaseEnd, NumberOfOccupants
        /// </summary>
        /// <param name="roomEntity"></param>
        /// <returns></returns>
        public Lib.Room ParseRoom(Entities.Room roomEntity)
        {
            var room = new Lib.Room()
            {
                RoomId            = roomEntity.RoomId,
                ComplexId         = roomEntity.ComplexId,
                RoomNumber        = roomEntity.RoomNumber,
                RoomType          = roomEntity.RoomType.Type,
                NumberOfBeds      = roomEntity.NumberOfBeds,
                NumberOfOccupants = roomEntity.NumberOfOccupants
            };

            room.SetLease(roomEntity.LeaseStart, roomEntity.LeaseEnd);
            if (roomEntity.Gender != null)
            {
                room.Gender = roomEntity.Gender.Type;
            }
            return(room);
        }