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);
        }
        public async Task PutRoomShouldUpdateRoom()
        {
            //arrange
            var mockRepo   = new Mock <IRepository>();
            var mockLogger = new Mock <ILogger <ComplexController> >();

            mockRepo.Setup(r => r.UpdateRoomAsync(
                               It.IsAny <Lib.Room>()
                               ));
            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 Revature.Room.Lib.Room
            {
                ComplexId         = Guid.NewGuid(),
                RoomId            = Guid.NewGuid(),
                RoomNumber        = "ABC",
                NumberOfBeds      = 4,
                NumberOfOccupants = 4,
                Gender            = "Male",
                RoomType          = "Apartment"
            };

            roomTest.SetLease(DateTime.Now, DateTime.Today.AddDays(3));

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

            //assert
            Assert.IsAssignableFrom <NoContentResult>(result);
        }
Exemplo n.º 3
0
        public async void PutRoomAsyncTest()
        {
            var amId    = Guid.NewGuid();
            var cId     = Guid.NewGuid();
            var rId     = Guid.NewGuid();
            var amenity = new ApiAmenity
            {
                AmenityId   = amId,
                AmenityType = "Pool",
                Description = "swimmming"
            };
            var amenities = new List <ApiAmenity>
            {
                amenity
            };
            var ar = new Logic.AmenityRoom
            {
                AmenityRoomId = Guid.NewGuid(),
                AmenityId     = amId,
                RoomId        = rId
            };
            var room = new ApiRoom
            {
                RoomId       = rId,
                RoomNumber   = "1234",
                ComplexId    = cId,
                ApiRoomType  = "dorm",
                NumberOfBeds = 3,
                LeaseStart   = Convert.ToDateTime("2010/1/1"),
                LeaseEnd     = Convert.ToDateTime("2020/1/1"),
                Amenities    = amenities
            };
            var complexRepo = new Mock <IRepository>();
            var logger      = new Mock <ILogger <ComplexController> >();
            var rss         = new Mock <IRoomServiceSender>();
            var ara         = new Mock <IAddressRequest>();
            var rr          = new Mock <IRoomRequest>();
            var res         = true;

            complexRepo.Setup(r => r.DeleteAmenityRoomAsync(rId))
            .Returns(Task.FromResult(res));
            complexRepo.Setup(r => r.CreateAmenityRoomAsync(ar))
            .Returns(Task.FromResult(res));

            //act
            var controller = new ComplexController(complexRepo.Object, logger.Object, rss.Object, ara.Object, rr.Object);
            var model      = Assert.IsAssignableFrom <StatusCodeResult>(await controller.PutRoomAsync(room));

            //assert
            Assert.IsAssignableFrom <StatusCodeResult>(model);
        }
        public async Task PutRoomShouldReturnBadRequest()
        {
            //arrange
            var mockRepo = new Mock <IRepository>();

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

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

            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();

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

            //assert
            Assert.IsType <BadRequestResult>(result);
        }