public void ApproveReject_SessionRequest_Returns_SessionRequest_With_Updated_Status( string type, string reason, int expectedStatusId) { var userId = Guid.NewGuid(); var roomFunctionId = Guid.NewGuid(); var startTime = DateTime.Now; var endTime = startTime.AddHours(2); var requestedTime = DateRange.Create(startTime, endTime); _sessionScheduleValidator .Setup(v => v.ValidateAsync(It.IsAny <Guid>(), It.IsAny <Guid?>(), It.IsAny <DateRange>())) .Returns(Task.FromResult(SessionScheduleValidatorResult.Success)); var request = Room.RequestSession(userId, requestedTime, roomFunctionId, _sessionScheduleValidator.Object); Assert.Equal((int)SessionRequestStatusId.Pending, request.SessionRequestStatusId); SessionRequest modifiedRequest = null; switch (type) { case "Approve": modifiedRequest = Room.ApproveSessionRequest(request.Id, _sessionScheduleValidator.Object); break; case "Reject": modifiedRequest = Room.RejectSessionRequest(request.Id, reason); break; } Assert.Equal(expectedStatusId, modifiedRequest.SessionRequestStatusId); }
public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var dateRange = DateRange.Create(request.Rental.Start, request.Rental.End); var vehicle = await _context.FindAsync <Vehicle>(request.Rental.VehicleId); if (vehicle.Deleted.HasValue) { throw new System.Exception(""); } var dailyRate = await _context.FindAsync <DailyRate>(vehicle.DailyRateId); var rental = new Rental( request.Rental.VehicleId, request.Rental.ClientId, dateRange.Value, (Price)(dailyRate.Price * dateRange.Value.Days)); if (_context.Set <Rental>().Any(x => rental.Overlap(x))) { throw new System.Exception("Overlaping Rentals"); } _context.Store(rental); await _context.SaveChangesAsync(cancellationToken); return(new Response() { Rental = rental.ToDto() }); }
public async Task <EmployeeListQueryResponse> Handle(EmployeeListQuery query, CancellationToken cancellationToken) { var employees = await _employeeDomain.GetEmployeesAsync(DateRange.Create(query.HireDateStart, query.HireDateEnd), query.IncludeTerminated); return(EmployeeListQueryResponse.Create(employees.Select(e => EmployeeListItem.Create(e.Id, e.HireDate, e.TerminationDate, e.Name)) .OrderByDescending(emp => emp.HireDate))); }
public void EndSession_Throws_SessionNotStartException() { var endTime = DateTime.Now; var schedule = DateRange.Create(endTime, endTime.AddHours(2)); var session = Room.CreateSession(schedule, _sessionScheduleValidator.Object); var ex = Assert.Throws <SessionNotStartedException>(() => Room.EndSession(session.Id, endTime)); Assert.NotNull(ex); }
public void RescheduleSession_Returns_RoomSession_With_New_Schedule() { var schedule = DateRange.Create(DateTime.Now, DateTime.Now.AddHours(2)); var session = Room.CreateSession(schedule, _sessionScheduleValidator.Object); Assert.NotNull(session); Assert.Equal(Room.Id, session.RoomId); Assert.NotNull(session.Schedule); Assert.Equal(schedule.Start, session.Schedule.Start); Assert.Equal(schedule.End, session.Schedule.End); }
public void When(WeddingCreated weddingCreated) { WeddingId = weddingCreated.WeddingId; StartLocation = weddingCreated.Start; EndLocation = weddingCreated.End; Parts = new List <WeddingPart>(); Trips = new List <Trip>(); var dateRange = DateRange.Create(weddingCreated.DateTime, weddingCreated.DateTime.AddHours(weddingCreated.Hours)); Parts.Add(new WeddingPart(dateRange.Value, null, null)); }
public async void Validate_Should_Return_Success() { _roomRepositoryMock .Setup(r => r.GetScheduleAsync(It.IsAny <Guid>(), It.IsAny <DateRange>())) .Returns(Task.FromResult(Enumerable.Empty <RoomSessionSchedule>())); var schedule = DateRange.Create(DateTime.Now, DateTime.Now.AddHours(2)); var result = await _validator.ValidateAsync(RoomId, null, schedule); Assert.Equal(SessionScheduleValidatorResult.Success, result); }
public void StartSession_Throws_SessionAlreadyStartedException() { var time = DateTime.Now; var schedule = DateRange.Create(time, time.AddHours(2)); var session = Room.CreateSession(schedule, _sessionScheduleValidator.Object); Room.StartSession(session.Id, time); var ex = Assert.Throws <SessionAlreadyStartedException>(() => Room.StartSession(session.Id, time)); Assert.NotNull(ex); }
public void StartSession_Sets_ActualStartTime() { var time = DateTime.Now; var schedule = DateRange.Create(time, time.AddHours(2)); var session = Room.CreateSession(schedule, _sessionScheduleValidator.Object); Room.StartSession(session.Id, time); Assert.NotNull(session); Assert.Equal(Room.Id, session.RoomId); Assert.NotNull(session.ActualStartTime); Assert.Equal(time, session.ActualStartTime); }
public async void Validate_Should_Return_Success_When_Schedule_Overlaps_With_Same_SessionId() { _roomRepositoryMock .Setup(r => r.GetScheduleAsync(It.IsAny <Guid>(), It.IsAny <DateRange>())) .Returns(Task.FromResult(RoomSchedule)); var start = Start.AddMinutes(-30); var end = End.AddMinutes(-30); var schedule = DateRange.Create(start, end); var sessionId = RoomSchedule.First().SessionId; var result = await _validator.ValidateAsync(RoomId, sessionId, schedule); Assert.Equal(SessionScheduleValidatorResult.Success, result); }
public async Task <SessionRequestDto> RequestSessionAsync(SessionRequestDto model) { var requestedDateRange = model.RequestedTime != null ? DateRange.Create(model.RequestedTime.Start, model.RequestedTime.End) : null; var room = await _roomRepository.GetAsync(model.RoomId); var newModel = room.RequestSession(model.RequestingUserId, requestedDateRange, model.RoomFunctionId, _sessionScheduleValidator); var entity = await _roomRepository.RequestSessionAsync(newModel); var result = _mapper.Map <SessionRequestDto>(entity); return(result); }
public async Task <SessionDto> CreateSessionAsync(Guid roomId, SessionDto session) { var room = await _roomRepository.GetAsync(roomId); var schedule = session.Schedule == null ? null : DateRange.Create(session.Schedule.Start, session.Schedule.End); var model = room.CreateSession(schedule, _sessionScheduleValidator); var entity = await _roomRepository.CreateSessionAsync(room.Id, model); var result = _mapper.Map <SessionDto>(entity); return(result); }
public async void Validate_Should_Throw_Exception_When_Start_Greater_Than_End() { _roomRepositoryMock .Setup(r => r.GetScheduleAsync(It.IsAny <Guid>(), It.IsAny <DateRange>())) .Returns(Task.FromResult(Enumerable.Empty <RoomSessionSchedule>())); var start = DateTime.Now; var end = start.AddHours(-2); var schedule = DateRange.Create(start, end); var ex = await Assert.ThrowsAsync <DomainValidationException>(() => _validator.ValidateAsync(RoomId, null, schedule)); Assert.NotNull(ex); Assert.NotNull(ex.InnerException); Assert.IsType <ScheduleEndMustBeGreaterThanStartException>(ex.InnerException); }
public async void Validate_Should_Throw_Exception_When_Schedule_Start_Overlaps() { _roomRepositoryMock .Setup(r => r.GetScheduleAsync(It.IsAny <Guid>(), It.IsAny <DateRange>())) .Returns(Task.FromResult(RoomSchedule)); var start = Start.AddHours(1); var end = Start.AddHours(3); var schedule = DateRange.Create(start, end); var ex = await Assert.ThrowsAsync <DomainValidationException>(() => _validator.ValidateAsync(RoomId, null, schedule)); Assert.NotNull(ex); Assert.NotNull(ex.InnerException); Assert.IsType <OverlappingScheduleException>(ex.InnerException); }
public override async Task InitializeAsync() { // prepare command var createCommand = new CreateMeeting( MeetingId, MeetingName ); // send create command await Client.PostAsync(ApiUrl, createCommand.ToJsonStringContent()); var occurs = DateRange.Create(Start, End); // send schedule meeting request CommandResponse = await Client.PostAsync($"{MeetingsManagementApi.MeetingsUrl}/{MeetingId}/schedule", occurs.ToJsonStringContent()); }
public override async Task InitializeAsync() { // prepare command var createCommand = new CreateMeeting( MeetingId, MeetingName ); // send create command await PostAsync(createCommand); var occurs = DateRange.Create(Start, End); // send schedule meeting request CommandResponse = await PostAsync($"{MeetingId}/schedule", occurs); }
public async Task Should_StoreAndReHydrateCorrectly() { var fakeId = Guid.NewGuid(); var dateRange = DateRange.Create(DateTime.UtcNow.AddDays(1), DateTime.UtcNow.AddDays(2)).Value; var rental = new Rental(fakeId, fakeId, dateRange, (Price)1m); var dateTime = new MachineDateTime(); var options = new DbContextOptionsBuilder().UseInMemoryDatabase("UnitTest").Options; var eventStoreDbContext = new EventStoreDbContext(options); var eventStore = new EventStore(eventStoreDbContext, dateTime); var aggregateSet = new AggregateSet(eventStoreDbContext, dateTime); eventStore.Store(rental); await eventStore.SaveChangesAsync(default);
public async void RequestSessionAsync_Returns_New_SessionRequestDto() { var studioId = Guid.NewGuid(); var room = Room.Create(studioId, "Room"); var userId = Guid.NewGuid(); var startTime = DateTime.Now; var endTime = startTime.AddHours(2); var requestedTime = DateRange.Create(startTime, endTime); var entity = room.RequestSession(userId, requestedTime, null, _sessionScheduleValidator.Object); var requestedTimeDto = new DateRangeDto { Start = startTime, End = endTime }; _roomRepository .Setup(r => r.GetAsync(It.IsAny <Guid>())) .Returns(Task.FromResult(room)); _roomRepository .Setup(r => r.RequestSessionAsync(It.IsAny <SessionRequest>())) .Returns(Task.FromResult(entity)); _sessionScheduleValidator .Setup(v => v.ValidateAsync(It.IsAny <Guid>(), It.IsAny <Guid?>(), It.IsAny <DateRange>())) .Returns(Task.FromResult(SessionScheduleValidatorResult.Success)); var dto = new SessionRequestDto { RoomId = room.Id, RequestingUserId = userId, RequestedTime = new DateRangeDto { Start = startTime, End = endTime } }; var result = await _roomService.RequestSessionAsync(dto); Assert.NotNull(result); Assert.Equal(entity.Id, result.Id); Assert.Equal(entity.RoomId, result.RoomId); Assert.Equal(entity.RoomFunctionId, result.RoomFunctionId); Assert.Equal(entity.RequestingUserId, result.RequestingUserId); Assert.Equal(entity.RequestedStartTime, result.RequestedTime.Start); Assert.Equal(entity.RequestedEndTime, result.RequestedTime.End); }
public void RequestSession_Returns_SessionRequest_Model() { var userId = Guid.NewGuid(); var roomFunctionId = Guid.NewGuid(); var startTime = DateTime.Now; var endTime = startTime.AddHours(2); var requestedTime = DateRange.Create(startTime, endTime); var model = Room.RequestSession(userId, requestedTime, roomFunctionId, _sessionScheduleValidator.Object); Assert.NotNull(model); Assert.Equal(userId, model.RequestingUserId); Assert.Equal(roomFunctionId, model.RoomFunctionId); Assert.Equal(startTime, model.RequestedStartTime); Assert.Equal(endTime, model.RequestedEndTime); Assert.Equal(requestedTime, model.RequestedTime); Assert.Equal((int)SessionRequestStatusId.Pending, model.SessionRequestStatusId); }
public async Task <SessionDto> RescheduleSessionAsync(Guid roomId, Guid sessionId, DateRangeDto newSchedule) { var room = await _roomRepository.GetAsync(roomId); var entity = room.Sessions.Single(s => s.Id == sessionId); var schedule = newSchedule == null ? null : DateRange.Create(newSchedule.Start, newSchedule.End); var model = room.RescheduleSession(entity, schedule, _sessionScheduleValidator); var updatedEntity = await _roomRepository.RescheduleSessionAsync(model.Id, model.Schedule); var result = _mapper.Map <SessionDto>(updatedEntity); return(result); }
public async void CreateSessionAsync_Returns_New_RoomSessionDto_With_Schedule() { var studioId = Guid.NewGuid(); var room = Room.Create(studioId, "Room"); _roomRepository .Setup(r => r.GetAsync(It.IsAny <Guid>())) .Returns(Task.FromResult(room)); var schedule = DateRange.Create(DateTime.Now, DateTime.Now.AddHours(2)); var entity = Session.Create(room.Id, schedule, null); _roomRepository .Setup(r => r.CreateSessionAsync(It.IsAny <Guid>(), It.IsAny <Session>())) .Returns(Task.FromResult(entity)); _sessionScheduleValidator .Setup(v => v.ValidateAsync(It.IsAny <Guid>(), It.IsAny <Guid?>(), It.IsAny <DateRange>())) .Returns(Task.FromResult(SessionScheduleValidatorResult.Success)); var dto = new SessionDto { RoomId = room.Id, Schedule = new DateRangeDto { Start = schedule.Start, End = schedule.End } }; var result = await _roomService.CreateSessionAsync(room.Id, dto); Assert.NotNull(dto); Assert.Equal(room.Id, dto.RoomId); Assert.NotNull(dto.Schedule); Assert.Equal(dto.Schedule.Start, schedule.Start); Assert.Equal(dto.Schedule.End, schedule.End); Assert.Equal(studioId, room.StudioId); }
public WaterQualityDeployment Build(DbDataReader reader) { WaterQualityDeployment tmp = new WaterQualityDeployment(new CompoundIdentity(DbReaderUtils.GetGuid(reader, 0), DbReaderUtils.GetGuid(reader, 1)), DbReaderUtils.GetString(reader, 2), new CompoundIdentity(DbReaderUtils.GetGuid(reader, 3), DbReaderUtils.GetGuid(reader, 4)), new CompoundIdentity(DbReaderUtils.GetGuid(reader, 5), DbReaderUtils.GetGuid(reader, 6)), new CompoundIdentity(DbReaderUtils.GetGuid(reader, 7), DbReaderUtils.GetGuid(reader, 8)), DateRange.Create(Db.FixDate(DbReaderUtils.GetNullableDateTime(reader, 9)), Db.FixDate(DbReaderUtils.GetNullableDateTime(reader, 10))), DbReaderUtils.GetString(reader, 11), DbReaderUtils.GetBoolean(reader, 12)); if (tmp.IsPrivate) { if (prov == null) { return(null); //can't verify } if (!prov.HasAffiliationForSampleEvent(tmp.SampleEventId, false)) { return(null); } } return(tmp); }
public void When(ConsultationRescheduled consultationRescheduled) { Scheduled = DateRange.Create(consultationRescheduled.StartDate, consultationRescheduled.EndDate).Value; }
public void When(WeddingPartAdded weddingPartAdded) { var dateRange = DateRange.Create(weddingPartAdded.DateTime, weddingPartAdded.DateTime.AddHours(weddingPartAdded.Hours)); Parts.Add(new WeddingPart(dateRange.Value, weddingPartAdded.Location, weddingPartAdded.Description)); }