public async Task <ActionResult <Guid> > CreatEnrollmentItem(CreateEnrollmentItemCommand itemCommand) { var vm = await mediator.Send(itemCommand); if (vm.Id != null) { var link = Url.Link("GetEnrollmentItem", new { enrollmentId = vm.Id }); return(Created(link, vm)); } else { return(BadRequest(vm)); } }
private async Task <CreateEnrollmentItemDto> CreateEnrollmentDtoAsync() { var studentDto = await SendAsync(new CreateStudentItemCommand() { FirstName = "first", LastName = "last" }); var createCourseCommand = new CreateCourseItemCommand() { Name = "Course1", Rate = 40, }; var courseDto = await SendWithValidationAsync(createCourseCommand, new CreateCourseItemCommandValidator()); var locationDto = await SendWithValidationAsync(new CreateLocationItemCommand() { IsEnabled = true, Name = "location1", Address = "address1", OpeningTime = new TimeSpan(0, 19, 0), ClosingTime = new TimeSpan(0, 21, 0), }, new CreateLocationItemCommandValidator()); var createCourseClassCommand = new CreateCourseClassItemCommand() { Name = $"{createCourseCommand.Name}-class1", CourseId = courseDto.Id, LocationId = locationDto.Id, Capacity = 40, }; var courseClassDto = await SendWithValidationAsync(createCourseClassCommand, new CreateCourseClassItemCommandValidator()); var command = new CreateEnrollmentItemCommand() { StartDate = DateTime.UtcNow.DateTimeWithoutMilisecond(), StudentId = studentDto.Id, CourseClassId = courseClassDto.Id, }; var dto = await SendAsync(command); return(dto); }
public async Task ShouldCreateEnrollment() { var studentDto = await CreateStudentAsync(); var courseClassDto = await CreateCourseClassAsync("ShouldCreateEnrollment"); var command = new CreateEnrollmentItemCommand() { StartDate = DateTime.UtcNow.DateTimeWithoutMilisecond(), StudentId = studentDto.Id, CourseClassId = courseClassDto.Id, }; var dto = await SendAsync(command); var created = await ExecuteDbContextAsync(db => db.Enrollments.Where(c => c.Id.Equals(dto.Id)).SingleOrDefaultAsync()); created.ShouldNotBeNull(); created.StartDate.ShouldBe(command.StartDate); created.StudentId.ShouldBe(command.StudentId); created.CourseClassId.ShouldBe(command.CourseClassId); }