public async Task CreateAsyncCreatesOneEntity() { BaseServiceTests.Initialize(); var repository = new DbRepository <Assignment>(dbFixture.dbContext); var service = new AssignmentService(repository); var assgnCount = this.dbFixture.dbContext.Assignments.Count(); var lecturecise = this.dbFixture.dbContext.Lecturecises.First(); var lectureciseId = lecturecise.Id; var educator = this.dbFixture.dbContext.Educator.First(); var educatorId = educator.Id; await service.CreateAsync(new AssignmentCreateBindingModel() { Name = "Assgn2", MaxGrade = 10m, EducatorId = educatorId, LectureciseId = lectureciseId }); Assert.Equal(assgnCount + 1, dbFixture.dbContext.Assignments.Count()); }
public async Task <ActionResult <AssignmentDto> > CreateLessonAssignmentAsync( [FromRoute] Guid classroomId, [FromRoute] Guid lessonId, [FromBody] AssignmentDto assignmentDto ) { var user = (ApplicationUser)HttpContext.Items["ApplicationUser"]; Debug.Assert(user != null, nameof(user) + " != null"); try { var classroom = await _classroomService.FindAsync(classroomId); var authorization = await _authorizationService.AuthorizeAsync(User, classroom, "IsInClassroom"); if (!authorization.Succeeded) { return(Forbid()); } var assignment = await _assignmentService.CreateAsync(assignmentDto.ToAssignment()); var lesson = await _lessonService.FindAsync(lessonId); await _lessonService.AddAssignmentAsync(lesson, assignment); return(Ok(assignment.ToDto())); } catch (Exception e) { Console.WriteLine(e); return(BadRequest()); } }