public async Task <IActionResult> StartShift(int babySitterId, [FromBody] StartShiftArgs args) { args = args.WithId(babySitterId); var model = await _commandBus.Execute <StartShiftArgs, ShiftModel>(args); return(CreatedAtRoute("GetBabySitterShift", new { shiftId = model.Id, babySitterId = model.SitterId }, model)); }
public async Task ShouldReturn404IfShiftStartedForSitterThatDoesNotExist() { using (var client = _fixture.CreateClient()) { var args = new StartShiftArgs(54, "5:00 PM".ToLocalDateTime(), "7:00 PM".ToLocalDateTime()); var response = await client.PostJsonAsync <object>("babysitters/54/startShift", args); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } }
public async Task <ShiftModel> StartShift(int sitterId, LocalDateTime startTime, LocalDateTime bedTime) { var startArgs = new StartShiftArgs(sitterId, startTime, bedTime); using (var client = CreateClient()) { var response = await client.PostJsonAsync($"babysitters/{sitterId}/startShift", startArgs); return(await client.GetJsonAsync <ShiftModel>(response.Headers.Location)); } }
public async Task ShouldThrowValidationException() { var sitter = _context.Add(ModelFactory.CreateSitter()).Entity; _context.SaveChanges(); var startTime = "5:00 PM".ToLocalDateTime(); var bedTime = "8:00 PM".ToLocalDateTime(); var args = new StartShiftArgs(sitter.Id, startTime, bedTime); await _command.Execute(args); await Assert.ThrowsAsync <ValidationException>(() => _command.Execute(args)); }
public async Task ShouldCreateShiftWithStartTime() { var sitter = _context.Add(ModelFactory.CreateSitter()).Entity; _context.SaveChanges(); var startTime = "5:00 PM".ToLocalDateTime(); var bedTime = "7:00 PM".ToLocalDateTime(); var args = new StartShiftArgs(sitter.Id, startTime, bedTime); await _command.Execute(args); var shift = _context.Shifts.First(); Assert.Equal(startTime, shift.StartTime); Assert.Equal(bedTime, shift.Bedtime); Assert.Equal(sitter.HourlyRates, shift.HourlyRates); }
public async Task ShouldThrowEntityNotFoundException() { var args = new StartShiftArgs(int.MaxValue, "5:00 PM".ToLocalDateTime(), "11:00 PM".ToLocalDateTime()); await Assert.ThrowsAsync <EntityNotFoundException <Sitter> >(() => _command.Execute(args)); }