public void ApproveReject_Throws_Exception_When_Request_Not_Pending(string currentState, string action) { var request = SessionRequest.Create(Guid.NewGuid(), Guid.NewGuid(), DateTime.Now, DateTime.Now, Guid.NewGuid()); switch (currentState) { case "Approved": request.Approve(); break; case "Rejected": request.Reject("SomeReason"); break; } Assert.Throws <DomainValidationException>(() => { switch (action) { case "Approve": request.Approve(); break; case "Reject": request.Reject("Some reason"); break; } }); }
public async void ApproveSessionRequestAsync_Returns_Approved_SessionRequestDto() { var startTime = DateTime.Now; var endTime = startTime.AddHours(2); var room = Room.Create(Guid.NewGuid(), "Room"); var request = SessionRequest.Create(Guid.NewGuid(), room.Id, startTime, endTime, null); room.SessionRequests.Add(request); var newSession = Session.Create(room.Id, request.RequestedTime, request.Id); _roomRepository .Setup(r => r.GetAsync(It.IsAny <Guid>())) .Returns(Task.FromResult(room)); _roomRepository .Setup(r => r.CreateSessionAsync(It.IsAny <Guid>(), It.IsAny <Session>())) .Returns(Task.FromResult(newSession)); _sessionScheduleValidator .Setup(v => v.ValidateAsync(It.IsAny <Guid>(), It.IsAny <Guid?>(), It.IsAny <DateRange>())) .Returns(Task.FromResult(SessionScheduleValidatorResult.Success)); var result = await _roomService.ApproveSessionRequestAsync(room.Id, request.Id); Assert.Equal((int)SessionRequestStatusId.Approved, result.SessionRequestStatusId); Assert.NotEqual(new Guid(), request.SessionId); }
public async void RejectSessionRequestAsync_Returns_Rejected_SessionRequestDto(string reason) { var startTime = DateTime.Now; var endTime = startTime.AddHours(2); var room = Room.Create(Guid.NewGuid(), "Room"); var request = SessionRequest.Create(Guid.NewGuid(), room.Id, startTime, endTime, null); room.SessionRequests.Add(request); _roomRepository .Setup(r => r.GetAsync(It.IsAny <Guid>())) .Returns(Task.FromResult(room)); var result = await _roomService.RejectSessionRequestAsync(room.Id, request.Id, reason); Assert.Equal((int)SessionRequestStatusId.Rejected, result.SessionRequestStatusId); Assert.Equal(reason, result.RejectedReason); }
public SessionRequest RequestSession( Guid requestingUserId, DateRange requestedTime, Guid?roomFunctionId, ISessionScheduleValidator sessionScheduleValidator) { var result = Room.ValidateSchedule(this.Id, null, requestedTime, sessionScheduleValidator); if (result) { var request = SessionRequest.Create( requestingUserId, this.Id, requestedTime.Start, requestedTime.End, roomFunctionId); SessionRequests.Add(request); return(request); } throw new InvalidOperationException(); }