Ejemplo n.º 1
0
        public async Task Add_Teacher_Test(string forename, string surname, int age)
        {
            //Given
            TeacherDTO teacher = new TeacherDTO()
            {
                forename = forename,
                surname  = surname,
                age      = age
            };

            var teacherRepositoryMock = new Mock <ITeacherRepository>();

            teacherRepositoryMock.Setup(x => x.Add(It.IsAny <Teacher>())).ReturnsAsync(true);

            //When
            TeacherController teacherController = new TeacherController(teacherRepositoryMock.Object);
            var result = await teacherController.AddTeacher(teacher) as ObjectResult;

            var teacherResult = (Teacher)result.Value;


            //Then
            Assert.AreEqual((int)HttpStatusCode.Created, result.StatusCode);
            Assert.AreEqual(teacher.forename, teacherResult.forename);
            Assert.AreEqual(teacher.surname, teacherResult.surname);
            Assert.AreEqual(teacher.age, teacherResult.age);
        }
Ejemplo n.º 2
0
        public void LoadClassTest()
        {
            //Arange
            var number          = "11 A";
            var name            = Guid.NewGuid().ToString();
            var soname          = Guid.NewGuid().ToString();
            var gender          = Guid.NewGuid().ToString();
            var birtgay         = DateTime.Now.AddYears(-18);
            var clas            = "11 A";
            var id              = 10;
            var teachcontroller = new TeacherController();



            //Act
            teachcontroller.AddTeacher(name, soname, gender, birtgay, clas, id);
            var teacher = teachcontroller.LoadTeacher(name, soname);

            teachcontroller.SetClassControll();

            teachcontroller.classController.AddClass(number);
            teachcontroller.classController.AddStudent(number, name, soname, gender, birtgay);
            var cl = teachcontroller.classController.LoadClass(number);

            //Assert
            Assert.AreEqual(cl, teachcontroller.classController.Currentclass);
        }
Ejemplo n.º 3
0
 public void TestAddTeacher()
 {
     TestTeacherController = new TeacherController("E:/NAU/TEST/data.dat");
     for (var i = 0; i < 100; i++)
     {
         TestTeacherController.AddTeacher(new Teacher(i));
     }
     try
     {
         TestTeacherController.AddTeacher(new Teacher(99));
         Assert.Fail();
     }
     catch (Exception e)
     {
         Assert.AreEqual("Teacher with 99 id, is already exist!", e.Message);
     }
     Assert.AreEqual(new Student(5).Id, TestTeacherController.GetTeacher(5).Id);
 }
Ejemplo n.º 4
0
        public void TestInit()
        {
            TestTeacherController = new TeacherController("E:/NAU/TEST/data.dat");
            Assert.IsInstanceOfType(TestTeacherController, typeof(TeacherController));

            Repository <Teacher> tRepo = new Repository <Teacher>();
            TeacherController    tCtrl = new TeacherController(tRepo);

            tCtrl.AddTeacher(new Teacher(14));
            Assert.AreEqual(14, tRepo[0].Id);
        }
Ejemplo n.º 5
0
        public void TestGetTeacher()
        {
            TestTeacherController = new TeacherController("E:/NAU/TEST/data.dat");

            for (var i = 0; i < 50; i++)
            {
                TestTeacherController.AddTeacher(new Teacher(i));
            }

            Assert.AreEqual(10, TestTeacherController.GetTeacher(10).Id);
            Assert.AreEqual(15, TestTeacherController.GetTeacher(15).Id);
            Assert.AreEqual(23, TestTeacherController.GetTeacher(23).Id);
        }
Ejemplo n.º 6
0
        public void TestDeleteTeacher()
        {
            TestTeacherController = new TeacherController("E:/NAU/TEST/data.dat");
            for (var i = 0; i < 50; i++)
            {
                TestTeacherController.AddTeacher(new Teacher(i));
            }

            for (var i = 0; i < 50; i += 5)
            {
                TestTeacherController.RemoveTeacher(TestTeacherController.GetTeacher(i));
            }

            Assert.AreEqual(40, TestTeacherController.GetAll().Count);
        }
Ejemplo n.º 7
0
        public void TestGetAll()
        {
            TestTeacherController = new TeacherController("E:/NAU/TEST/data.dat");

            for (var i = 0; i < 50; i++)
            {
                TestTeacherController.AddTeacher(new Teacher(i));
            }

            var listOfStudents = TestTeacherController.GetAll();
            int tId            = 0;

            foreach (var item in listOfStudents)
            {
                Assert.AreEqual(tId, item.Id);
                tId++;
            }
        }
Ejemplo n.º 8
0
        public void TestChangeTeacher()
        {
            TestTeacherController = new TeacherController("E:/NAU/TEST/data.dat");
            for (var i = 0; i < 50; i++)
            {
                TestTeacherController.AddTeacher(new Teacher(i));
            }

            TestTeacherController.ChangeTeacher(
                TestTeacherController.GetTeacher(43),
                new Teacher(90));

            TestTeacherController.ChangeTeacher(
                TestTeacherController.GetTeacher(42),
                new Teacher(80));

            Assert.AreEqual(90, TestTeacherController.GetTeacher(90).Id);
            Assert.AreEqual(80, TestTeacherController.GetTeacher(80).Id);
        }
Ejemplo n.º 9
0
        private static void Regestration()
        {
            Console.WriteLine("Введите Имя");
            string name = Console.ReadLine();

            Console.WriteLine("Введите Фамилию");
            string soname = Console.ReadLine();

            Console.WriteLine("Введите Пол");
            string gender = Console.ReadLine();

            Console.WriteLine("Введите Дату Рождения");
            DateTime dateTime = DateTime.Parse(Console.ReadLine());

            Console.WriteLine("Введите Свой класс");
            string clas = Console.ReadLine();

            Console.WriteLine("Введите свой Id");
            int id = int.Parse(Console.ReadLine());

            teacherController.AddTeacher(name, soname, gender, dateTime, clas, id);
        }
Ejemplo n.º 10
0
        public void AddTeacherTest()
        {
            var name            = Guid.NewGuid().ToString();
            var soname          = Guid.NewGuid().ToString();
            var gender          = Guid.NewGuid().ToString();
            var birtgay         = DateTime.Now.AddYears(-18);
            var clas            = "11 A";
            var id              = 10;
            var teachcontroller = new TeacherController();

            //Act

            teachcontroller.AddTeacher(name, soname, gender, birtgay, clas, id);
            var teacher          = teachcontroller.LoadTeacher(name, soname);
            var teachcontroller2 = new TeacherController();
            var teacher2         = teachcontroller2.LoadTeacher(name, soname);

            //Assert
            Assert.AreEqual(teacher.Name, teacher2.Name);
            Assert.AreEqual(teacher.SoName, teacher2.SoName);
            Assert.AreEqual(teacher.gender, teacher2.gender);
            Assert.AreEqual(teacher.BirtDay, teacher2.BirtDay);
        }
Ejemplo n.º 11
0
        private void btnAproveAdding_Click(object sender, EventArgs e)
        {
            string idPreflex = "TC";

            teacher = new Teacher();
            if (cbxIsAdmin.Checked)
            {
                teacher.Type = Teacher.TeacherType.Adminstrator;
            }
            else if (cbxIsMinistry.Checked)
            {
                teacher.Type = Teacher.TeacherType.Ministry;
            }
            else
            {
                teacher.Type = Teacher.TeacherType.Teacher;
            }
            foreach (Subject subject in subjects)
            {
                if (subject.Name == cbbSubject.Text)
                {
                    teacher.Subject = subject;
                }
            }
            teacher.ID        = idPreflex + teacherID.Remove(0, 2);
            teacher.FirstName = txtFirstname.Text;
            teacher.SurName   = txtSurename.Text;
            teacher.Avatar    = ptbAvatar.Image;
            teacher.Position  = txtPostition.Text;
            if (cbbSex.SelectedIndex == -1)
            {
                cbbSex.Focus();
                return;
            }
            teacher.Sex      = Convert.ToBoolean(cbbSex.SelectedIndex);
            teacher.DateBorn = dateBorn.Value;
            teacher.Address  = txtAddress.Text;
            teacher.Phone    = txtPhoneNunber.Text;
            teacher.Mail     = txtTeacherMail.Text;
            if (mode == Mode.Add)
            {
                lbInformation.Text = "Đang thêm giáo viên có mã ID: " + teacher.ID;
                lbInformation.Show();
                mainProgressbar.Show();
                worker         = new BackgroundWorker();
                worker.DoWork += (s, e) =>
                {
                    doneSuccess = teacherController.AddTeacher(teacher);
                };
                worker.RunWorkerCompleted += (s, e) =>
                {
                    lbInformation.Hide();
                    mainProgressbar.Hide();
                    if (!doneSuccess)
                    {
                        MetroMessageBox.Show(this, "Đã có lỗi xảy ra trong quá trình thêm giáo viên.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MetroMessageBox.Show(this, "Đã thêm thành công giáo viên có ID: " + teacher.ID, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                };
            }
            else
            {
                lbInformation.Text = "Đang cập nhật giáo viên có mã ID: " + teacher.ID;
                lbInformation.Show();
                mainProgressbar.Show();
                worker         = new BackgroundWorker();
                worker.DoWork += (s, e) =>
                {
                    doneSuccess = teacherController.UpdateTeacher(teacherID, teacher);
                };
                worker.RunWorkerCompleted += (s, e) =>
                {
                    lbInformation.Hide();
                    mainProgressbar.Hide();
                    if (!doneSuccess)
                    {
                        MetroMessageBox.Show(this, "Đã có lỗi xảy ra trong quá trình cập nhật giáo viên.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MetroMessageBox.Show(this, "Đã cập nhật thành công giáo viên có ID: " + teacher.ID, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                };
            }
            worker.RunWorkerAsync();
        }