public async Task can_assign_class()
        {
            ClassGateway   classGateway  = new ClassGateway(TestHelpers.ConnectionString);
            StudentGateway sut           = new StudentGateway(TestHelpers.ConnectionString);
            string         firstName     = TestHelpers.RandomTestName();
            string         lastName      = TestHelpers.RandomTestName();
            DateTime       birthDate     = TestHelpers.RandomBirthDate(_random.Next(5, 10));
            Result <int>   studentResult = await sut.Create(firstName, lastName, birthDate);

            int studentId = studentResult.Content;

            int classId1;
            {
                string       className   = TestHelpers.RandomTestName();
                string       level       = TestHelpers.RandomLevel();
                Result <int> classResult = await classGateway.Create(className, level);

                Assert.That(classResult.Status, Is.EqualTo(Status.Created));
                classId1 = classResult.Content;

                await sut.AssignClass(studentId, classId1);

                Result <StudentClassData> studentClass = await sut.FindStudentClassById(studentId);

                CheckStudent(studentClass, firstName, lastName, birthDate, classId1);
            }

            {
                string       className   = TestHelpers.RandomTestName();
                string       level       = "CP";
                Result <int> classResult = await classGateway.Create(className, level);

                int classId2 = classResult.Content;
                await sut.AssignClass(studentId, classId2);

                Result <StudentClassData> studentClass = await sut.FindStudentClassById(studentId);

                CheckStudent(studentClass, firstName, lastName, birthDate, classId2);

                await sut.AssignClass(studentId, 0);

                studentClass = await sut.FindStudentClassById(studentId);

                CheckStudent(studentClass, firstName, lastName, birthDate, 0);

                await classGateway.Delete(classId2);
            }

            await sut.Delete(studentId);

            await classGateway.Delete(classId1);
        }
Пример #2
0
        public async Task <IActionResult> ClassAssignStudentAsync(int id, [FromBody] StudentViewModel model)
        {
            Result result;

            result = await _studentGateway.AssignClass(model.StudentId, model.ClassId);

            return(this.CreateResult(result));
        }
        public void can_assign_class()
        {
            ClassGateway classGateway = new ClassGateway(TestHelpers.ConnectionString);
            string       className1   = TestHelpers.RandomTestName();
            string       level1       = TestHelpers.RandomLevel();

            classGateway.Create(className1, level1);
            Class c1 = classGateway.FindByName(className1);

            StudentGateway sut       = new StudentGateway(TestHelpers.ConnectionString);
            string         firstName = TestHelpers.RandomTestName();
            string         lastName  = TestHelpers.RandomTestName();
            DateTime       birthDate = TestHelpers.RandomBirthDate(_random.Next(5, 10));

            sut.Create(firstName, lastName, birthDate, string.Empty, c1.ClassId);

            Student student;

            {
                student = sut.FindByName(firstName, lastName);
                CheckStudent(student, firstName, lastName, birthDate, c1.ClassId);
            }

            {
                string className2 = TestHelpers.RandomTestName();
                string level2     = "CP";
                classGateway.Create(className2, level2);
                Class c2 = classGateway.FindByName(className2);
                sut.AssignClass(student.StudentId, c2.ClassId);
                student = sut.FindById(student.StudentId);
                CheckStudent(student, firstName, lastName, birthDate, c2.ClassId);

                sut.AssignClass(student.StudentId, 0);
                student = sut.FindById(student.StudentId);
                CheckStudent(student, firstName, lastName, birthDate, 0);

                classGateway.Delete(c2.ClassId);
            }

            sut.Delete(student.StudentId);
            classGateway.Delete(c1.ClassId);
        }
Пример #4
0
        public async Task <IActionResult> AssignClass(int id, [FromBody] AssignedClassViewModels model)
        {
            Result result = await _studentGateway.AssignClass(id, model.ClassId);

            return(this.CreateResult(result));
        }
 public async Task AssignClass(int id, [FromBody] AssignClassViewModel model)
 {
     await _studentGateway.AssignClass(id, model.ClassId);
 }