示例#1
0
        public void Controller_SortByDate_Success()
        {
            StudentController studentController = new StudentController();

            string[] data   = { "University", "Leia", "Female", "20151231145934" };
            IEntity  entity = EntityFactory.CreateEntity(EntityType.Student, data);

            studentController.Add(entity);

            data[1] = "Wilson";
            data[3] = "20181231145934";
            IEntity entity2 = EntityFactory.CreateEntity(EntityType.Student, data);

            studentController.Add(entity2);

            data[1] = "Ammy";
            data[3] = "20121231145934";
            IEntity entity3 = EntityFactory.CreateEntity(EntityType.Student, data);

            studentController.Add(entity3);

            IDictionary <string, object> filters = new Dictionary <string, object>();

            filters.Add("Gender", "F");
            var entities = studentController.Get(filters);

            Assert.AreEqual(((Student)(entities[0])).Name, "Wilson");
            Assert.AreEqual(((Student)(entities[1])).Name, "Leia");
            Assert.AreEqual(((Student)(entities[2])).Name, "Ammy");
        }
示例#2
0
        public async Task Add_WhenExceptionIsThrown_ReturnsInternalServerError()
        {
            //Arrange
            _mapper.Setup(m => m.Map <StudentAddModel>(It.IsAny <StudentDto>())).Returns(_fixture.Create <StudentAddModel>());
            _service.Setup(s => s.Add(It.IsAny <StudentDto>())).Throws(new Exception());

            //Act
            var result = await _sut.Add(_fixture.Create <StudentAddModel>());

            //Assert
            result.AssertHasValueAndStatusCode(HttpStatusCode.InternalServerError);
        }
示例#3
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (AdminProfil.Addtype == 0)
     {
         var Add    = new StudentController();
         var Telebe = new Student();
         Telebe.Name       = Name.Text;
         Telebe.Surname    = Surname.Text;
         Telebe.Username   = Username.Text;
         Telebe.Age        = Age.Text;
         Telebe.Teacher_Id = idmellim;
         Telebe.Password   = Password.Text;
         Telebe.Class_Id   = Convert.ToInt32(Class.SelectedItem.ToString());
         Add.Add(Telebe);
     }
     if (AdminProfil.Addtype == 1)
     {
         var Add    = new TeacherController();
         var mellim = new Teacher();
         mellim.Name       = Name.Text;
         mellim.Surname    = Surname.Text;
         mellim.Username   = Username.Text;
         mellim.Age        = Age.Text;
         mellim.Student_id = idmellim;
         mellim.Password   = Password.Text;
         mellim.Class_id   = idmellim;
         Add.Add(mellim);
     }
 }
        public void AddStudent_ServiceMethodIsCalled()
        {
            var controller = new StudentController(StudentServiceMock.Object, CollegeRulesMock.Object, StudentPathProviderMock.Object);

            controller.Add(Fakes.GetStudent());

            StudentServiceMock.Verify(x => x.Add(It.IsAny <Student>()), Times.Once);
        }
示例#5
0
        public void Controller_FilterOperation_Success()
        {
            StudentController studentController = new StudentController();

            string[] data   = { "University", "Leia", "Female", "20151231145934" };
            IEntity  entity = EntityFactory.CreateEntity(EntityType.Student, data);

            studentController.Add(entity);

            data[1] = "Wilson";
            IEntity entity2 = EntityFactory.CreateEntity(EntityType.Student, data);

            studentController.Add(entity2);

            IDictionary <string, object> filters = new Dictionary <string, object>();

            filters.Add("Name", "Leia");
            var count = studentController.Get(filters).Count;

            Assert.AreEqual(count, 1);
        }
示例#6
0
        public void GivenStudent_WhenIdNull_ThenReturnMsgError()
        {
            var student = new Student
            {
                Id          = null,
                FirstName   = "Livint",
                LastName    = "Lucian",
                Enrollments = new List <Enrollment>()
            };

            Assert.That(() => studentController.Add(student),
                        Throws.TypeOf <Exception>().With.Message.EqualTo("Student doesn't have an unique id."));
        }
示例#7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Student student = new Student(txtStudentName.Text);
                studentController.Add(student);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            ListUpdate();
        }
示例#8
0
        private void AddBtn_Click(object sender, EventArgs e) // Add a user
        {
            string username = StudentName.Text.ToUpper();

            if (username.Equals(""))
            {
                MessageBox.Show("Provide a student name.");
            }
            else
            {
                _StudentController.Add(username);
                UpdateStudentCount();
                UpdateListBox(StudentModel.AllStudents);
            }
            StudentName.Text = "";
        }
示例#9
0
        public void GiveGrade_WhenStudentNotExist_ThenReturnError()
        {
            Student student = new Student();

            //Given
            Mock <SchoolContext> mockedSchoolContext = new Mock <SchoolContext>();
            var result = mockedSchoolContext.Setup(x => x.Students.Count());

            //When
            StudentController studentController = new StudentController(mockedSchoolContext.Object);

            studentController.Add(student);
            var newResult = mockedSchoolContext.Setup(x => x.Students.Count());

            //Assert
            Assert.That(result, Is.LessThan(newResult));
        }
示例#10
0
        public void Controller_DeleteOperation_Success()
        {
            StudentController studentController = new StudentController();

            string[] data   = { "University", "Leia", "Female", "20151231145934" };
            IEntity  entity = EntityFactory.CreateEntity(EntityType.Student, data);

            studentController.Add(entity);

            IDictionary <string, object> filters = new Dictionary <string, object>();
            var createdEntity = studentController.Get(filters)[0];

            studentController.Delete(createdEntity.Id);

            var count = studentController.Get(filters).Count;

            Assert.AreEqual(count, 0);
        }
示例#11
0
        public void Controller_UpdateOperation_Success()
        {
            StudentController studentController = new StudentController();

            string[] data   = { "University", "Leia", "Female", "20151231145934" };
            IEntity  entity = EntityFactory.CreateEntity(EntityType.Student, data);

            studentController.Add(entity);

            IDictionary <string, object> filters = new Dictionary <string, object>();
            var createdEntity = studentController.Get(filters)[0];

            ((Student)createdEntity).Name = "Updated";
            studentController.Update(createdEntity.Id, createdEntity);

            var updatedEntity = studentController.Get(filters)[0];

            Assert.AreEqual(((Student)(updatedEntity)).Name, "Updated");
        }
        public async Task AddStudent_DuplicateUsername_ReturnBadRequest()
        {
            //arrange
            var dbContext  = DbContextMocker.GetDbContext(nameof(AddStudent_DuplicateUsername_ReturnBadRequest));
            var controller = new StudentController(dbContext);

            //act
            var result = await controller.Add(new CreateStudentModel()
            {
                FullName = "ali mohamed",
                Password = "******",
                SchoolId = 1,
                Username = "******"
            });

            var badRequest = result as BadRequestObjectResult;

            dbContext.Dispose();

            //assert
            Assert.NotNull(badRequest);
            Assert.Equal(400, badRequest.StatusCode);
        }
        public async Task AddStudent_ValidUsername_ReturnBadRequest()
        {
            //arrange
            var dbContext  = DbContextMocker.GetDbContext(nameof(AddStudent_ValidUsername_ReturnBadRequest));
            var controller = new StudentController(dbContext);

            //act
            var result = await controller.Add(new CreateStudentModel()
            {
                FullName = "ali",
                Password = "******",
                SchoolId = 1,
                Username = "******"
            });

            var okResult = result as OkResult;

            dbContext.Dispose();

            //assert
            Assert.NotNull(okResult);
            Assert.Equal(200, okResult.StatusCode);
        }