public void can_create_find_update_and_delete_teacher() { TeacherGateway sut = new TeacherGateway(TestHelpers.ConnectionString); string firstName = TestHelpers.RandomTestName(); string lastName = TestHelpers.RandomTestName(); sut.Create(firstName, lastName); Teacher teacher; { teacher = sut.FindByName(firstName, lastName); CheckTeacher(teacher, firstName, lastName); } { teacher = sut.FindById(teacher.TeacherId); CheckTeacher(teacher, firstName, lastName); } { firstName = TestHelpers.RandomTestName(); lastName = TestHelpers.RandomTestName(); sut.Update(teacher.TeacherId, firstName, lastName); teacher = sut.FindById(teacher.TeacherId); CheckTeacher(teacher, firstName, lastName); } { sut.Delete(teacher.TeacherId); teacher = sut.FindById(teacher.TeacherId); Assert.That(teacher, Is.Null); } }
public Result <int> Delete(int teacherId) { if (_teacherGateway.FindById(teacherId) == null) { return(Result.Failure <int>(Status.NotFound, "Teacher not found.")); } _teacherGateway.Delete(teacherId); return(Result.Success(Status.Ok, teacherId)); }
public void can_assign_teacher() { TeacherGateway teacherGateway = new TeacherGateway(TestHelpers.ConnectionString); string firstName = TestHelpers.RandomTestName(); string lastName = TestHelpers.RandomTestName(); teacherGateway.Create(firstName, lastName); Teacher teacher1 = teacherGateway.FindByName(firstName, lastName); ClassGateway sut = new ClassGateway(TestHelpers.ConnectionString); string name = TestHelpers.RandomTestName(); string level = TestHelpers.RandomLevel(); sut.Create(name, level, teacher1.TeacherId); Class c; { c = sut.FindByName(name); CheckClass(c, name, level, teacher1.TeacherId); } { string firstName2 = TestHelpers.RandomTestName(); string lastName2 = TestHelpers.RandomTestName(); teacherGateway.Create(firstName2, lastName2); Teacher teacher2 = teacherGateway.FindByName(firstName2, lastName2); sut.AssignTeacher(c.ClassId, teacher2.TeacherId); c = sut.FindById(c.ClassId); CheckClass(c, name, level, teacher2.TeacherId); sut.AssignTeacher(c.ClassId, 0); c = sut.FindById(c.ClassId); CheckClass(c, name, level, 0); teacherGateway.Delete(teacher2.TeacherId); } sut.Delete(c.ClassId); teacherGateway.Delete(teacher1.TeacherId); }
public async Task can_create_find_update_and_delete_teacher() { TeacherGateway sut = new TeacherGateway(TestHelpers.ConnectionString); string firstName = TestHelpers.RandomTestName(); string lastName = TestHelpers.RandomTestName(); var result = await sut.Create(firstName, lastName); Assert.That(result.Status, Is.EqualTo(Status.Created)); int teacherId = result.Content; Result <TeacherData> teacher; { teacher = await sut.FindById(teacherId); CheckTeacher(teacher, firstName, lastName); } { firstName = TestHelpers.RandomTestName(); lastName = TestHelpers.RandomTestName(); Result r = await sut.Update(teacherId, firstName, lastName); Assert.That(r.Status, Is.EqualTo(Status.Ok)); teacher = await sut.FindById(teacherId); CheckTeacher(teacher, firstName, lastName); } { await sut.Delete(teacherId); teacher = await sut.FindById(teacherId); Assert.That(teacher.Status, Is.EqualTo(Status.NotFound)); Assert.That(teacher.HasError, Is.True); } }
public async Task <IActionResult> DeleteTeacher(int id) { Result result = await _teacherGateway.Delete(id); return(this.CreateResult(result)); }