public async Task <ActionResult <Guid> > CreateStudentItem(CreateStudentItemCommand itemCommand) { var vm = await mediator.Send(itemCommand); if (vm.Id != null) { var link = Url.Link("GetStudentItem", new { studentId = vm.Id }); return(Created(link, vm)); } else { return(BadRequest(vm)); } }
public async Task ShouldCreateStudent() { var command = new CreateStudentItemCommand() { FirstName = "first", LastName = "last" }; var dto = await SendWithValidationAsync(command, new CreateStudentItemCommandValidator()); var created = await ExecuteDbContextAsync(db => db.Students.Where(c => c.Id.Equals(dto.Id)).SingleOrDefaultAsync()); created.ShouldNotBeNull(); created.FirstName.ShouldBe(command.FirstName); created.LastName.ShouldBe(command.LastName); }
public async Task ShouldGetStudentList() { var createStudentItemCommand = new CreateStudentItemCommand() { FirstName = "first", LastName = "last" }; var createStudentDto = await SendAsync(createStudentItemCommand); var created = await ExecuteDbContextAsync(db => db.Students.Where(c => c.Id.Equals(createStudentDto.Id)).SingleOrDefaultAsync()); GetStudentListQuery query = new GetStudentListQuery(); GetObjectListVm <GetStudentItemDto> dto = await SendAsync(query); dto.ShouldNotBeNull(); dto.Count.ShouldBeGreaterThanOrEqualTo(1); dto.Data.ShouldContain(d => d.Id.Equals(created.Id)); }
public async Task ShouldGetStudentItem() { var createStudentItemCommand = new CreateStudentItemCommand() { FirstName = "first", LastName = "last" }; var createStudentDto = await SendAsync(createStudentItemCommand); GetStudentItemQuery query = new GetStudentItemQuery() { Id = createStudentDto.Id }; GetStudentItemDto dto = await SendAsync(query); var created = await ExecuteDbContextAsync(db => db.Students.Where(c => c.Id.Equals(dto.Id)).SingleOrDefaultAsync()); dto.ShouldNotBeNull(); dto.Id.ShouldBe(created.Id); dto.Name.ShouldBe($"{created.FirstName} {created.LastName}"); }