public async Task Should_update_student() { // create student var createStudentCommand = new CreateStudentCommand() { Id = Guid.NewGuid(), FirstName = "Milos", LastName = "Stojkovic", Address = "Bata Noleta 31", City = "Sokobanja", DateOfBirth = new DateTime(1991, 3, 18), State = "Srbija", Gender = (int)Domain.Enumerations.Gender.Male }; var CreateStudentCommandHandler = new CreateStudentCommandHandler(this.autoMapper, this.context); var result = await CreateStudentCommandHandler.Handle(createStudentCommand, CancellationToken.None); result.ShouldBe(true); // update student var updateStudentCommand = new UpdateStudentCommand() { Id = createStudentCommand.Id, FirstName = "Milos", LastName = "Stojkovic", Address = "Bata Noleta 31", City = "Beograd", DateOfBirth = new DateTime(1991, 3, 18), State = "Srbija", Gender = (int)Domain.Enumerations.Gender.Male }; var updateStudentCommandHandler = new UpdateStudentCommandHandler(this.autoMapper, this.context); result = await updateStudentCommandHandler.Handle(updateStudentCommand, CancellationToken.None); result.ShouldBe(true); var dbStudent = await this.context.Student.FirstOrDefaultAsync(s => s.Id == updateStudentCommand.Id); dbStudent.ShouldNotBeNull(); dbStudent.City.ShouldBe("Beograd"); }
public async Task Should_throw_not_found_exception() { var updateStudentCommand = new UpdateStudentCommand() { Id = Guid.NewGuid(), FirstName = "Milos", LastName = "Stojkovic", Address = "Bata Noleta 31", City = "Beograd", DateOfBirth = new DateTime(1991, 3, 18), State = "Srbija", Gender = (int)Domain.Enumerations.Gender.Male }; var updateStudentCommandHandler = new UpdateStudentCommandHandler(this.autoMapper, this.context); await Assert.ThrowsAsync <NotFoundException>(() => updateStudentCommandHandler.Handle(updateStudentCommand, CancellationToken.None)); }