Example #1
0
        public async void RejectSessionRequest_Returns_OkObjectResult_With_Rejected_SessionRequestDto(string reason)
        {
            var userId    = Guid.NewGuid();
            var roomId    = Guid.NewGuid();
            var startTime = DateTime.Now;
            var endTime   = startTime.AddHours(2);

            _identity.Setup(i => i.IsAuthenticated).Returns(true);
            _identity.Setup(i => i.Name).Returns(userId.ToString());

            var room = new RoomDto
            {
                Id = roomId
            };

            var expectedModel = new SessionRequestDto
            {
                Id               = Guid.NewGuid(),
                RoomId           = roomId,
                RequestingUserId = userId,
                RequestedTime    = new DateRangeDto {
                    Start = startTime, End = endTime
                },
                SessionRequestStatusId = (int)SessionRequestStatusId.Rejected,
                RejectedReason         = reason
            };

            _roomService
            .Setup(s => s.GetAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(room));

            _roomService
            .Setup(s => s.RejectSessionRequestAsync(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <string>()))
            .Returns(Task.FromResult(expectedModel));

            var result = await _roomsController.RejectSessionRequest(roomId, expectedModel.Id, reason);

            Assert.IsType <OkObjectResult>(result);

            var okResult = result as OkObjectResult;

            Assert.IsType <SessionRequestDto>(okResult.Value);

            var actual = okResult.Value as SessionRequestDto;

            Assert.Equal(expectedModel.SessionRequestStatusId, actual.SessionRequestStatusId);
            Assert.Equal(expectedModel.RejectedReason, actual.RejectedReason);
        }