예제 #1
0
 private void btn_add_teacher_Click(object sender, EventArgs e)
 {
     TeacherName     = tb_teacher_name.Text;
     TeacherSurname  = tb_teacher_surname.Text;
     TeacherAge      = Convert.ToInt32(tb_teacher_age.Text);
     TeacherLogin    = tb_teacher_login.Text;
     TeacherPassword = tb_teacher_password.Text;
     TeacherController.Create();
 }
        public async void Create_OnGet_PopulatesClassList()
        {
            List <Classes> classes = new List <Classes>
            {
                new Classes(),
                new Classes(),
                new Classes()
            };

            mockClassRepository.Setup(p => p.GetAllAsync()).Returns(Task.FromResult(classes));

            var result = await systemUnderTest.Create();

            Assert.IsType <ViewResult>(result);
            var temp      = (ViewResult)result;
            var viewData  = temp.ViewData;
            var classList = (SelectList)viewData["ClassId"];

            Assert.Equal(3, classList.Count());
        }
예제 #3
0
        public void CreateTeacherShouldDisplayTheView()
        {
            //ARRANGE
            var controller = new TeacherController(null, null, null, null, null, null, null);

            var result = controller.Create() as ViewResult;

            //ASSERT
            Assert.NotNull(result);
            Assert.NotNull(result.Model);
            Assert.That(result.ViewName, Is.EqualTo("Create"));
        }
예제 #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            var a = teacherName.Text;
            var b = teacherSurName.Text;
            var c = int.Parse(teacherAge.Text);

            TeacherController.Create(a, b, c);

            Choose choose = new Choose();

            this.Hide();
            choose.Show();
        }
        public void CannotCreateWithMissingValues()
        {
            Mock <IGenericService <Teacher> > teacherServiceMock = new Mock <IGenericService <Teacher> >();

            Teacher teacher = new Teacher()
            {
                Id                    = 100,
                FirstName             = "Robin",
                LastName              = "Schellius",
                ResponsibleForCourses = null
            };

            ClaimsPrincipal identity = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "123")
            }));

            teacherServiceMock.Setup(m => m.Insert(It.IsAny <Teacher>())).Returns((Teacher model) =>
            {
                if (!string.IsNullOrWhiteSpace(model.FullName) && model.ResponsibleForCourses != null)
                {
                    return(1);
                }

                return(0);
            });

            TeacherController controller = new TeacherController(teacherServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = identity
                    }
                }
            };

            ViewResult result = controller.Create(teacher) as ViewResult;

            Assert.NotNull(result);
            Assert.NotNull(result.Model);
            Assert.True(string.IsNullOrEmpty(result.ViewName) || result.ViewName == "Edit");
        }
        public void ShouldCreateCorrectly()
        {
            Mock <IGenericService <Teacher> > teacherServiceMock = new Mock <IGenericService <Teacher> >();

            Teacher teacher = new Teacher()
            {
                Id        = 100,
                FirstName = "Robin",
                LastName  = "Schellius"
            };

            ClaimsPrincipal identity = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "123")
            }));

            teacherServiceMock.Setup(m => m.Insert(It.IsAny <Teacher>())).Returns((Teacher model) =>
            {
                if (!string.IsNullOrWhiteSpace(model.FullName))
                {
                    return(1);
                }

                return(0);
            });

            TeacherController controller = new TeacherController(teacherServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = identity
                    }
                }
            };

            RedirectToActionResult result = controller.Create(teacher) as RedirectToActionResult;

            Assert.Equal("Index", result?.ActionName);
        }
예제 #7
0
        public async void Create_Errors()
        {
            TeacherControllerMockFacade mock = new TeacherControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiTeacherResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiTeacherResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTeacherRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTeacherResponseModel> >(mockResponse.Object));
            TeacherController controller = new TeacherController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiTeacherRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTeacherRequestModel>()));
        }
예제 #8
0
        public async void Create_No_Errors()
        {
            TeacherControllerMockFacade mock = new TeacherControllerMockFacade();

            var mockResponse = new CreateResponse <ApiTeacherResponseModel>(new FluentValidation.Results.ValidationResult());

            mockResponse.SetRecord(new ApiTeacherResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTeacherRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTeacherResponseModel> >(mockResponse));
            TeacherController controller = new TeacherController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiTeacherRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiTeacherResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTeacherRequestModel>()));
        }
예제 #9
0
        public void CreateTeacherShouldSaveTheTeacher()
        {
            //ARRANGE
            const string userName = "******";
            const string password = "******";
            var          model    = new CreateTeacherViewModel {
                UserName = userName, Password = password
            };

            var userLogic = new Mock <IUserLogic>();

            userLogic
            .Setup(x => x.CreateUser(It.IsAny <User>()))
            .Returns(true)
            .Verifiable("Should store user");


            userLogic
            .Setup(x => x.ResetPassword(It.IsAny <string>(), password))
            .Returns(true)
            .Verifiable("Should set the teachers password");

            userLogic
            .Setup(x => x.AddToRole(It.IsAny <string>(), "Teacher"))
            .Verifiable("Should add to role.");

            var controller = new TeacherController(userLogic.Object, null, null, null, null, null, null);

            //ACT
            var result = controller.Create(model) as RedirectToRouteResult;

            //ASSERT
            userLogic.Verify();

            Assert.NotNull(result);
            Assert.AreEqual("Manage", result.RouteValues["Action"]);
        }
예제 #10
0
파일: Program.cs 프로젝트: HYMPYT/BD_ZU
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;

            int table  = 0;
            int action = 0;

            do
            {
                table = FirstMenu();
                if (table == 0)
                {
                    return;
                }

                BaseController controller = null;

                switch (table)
                {
                case 1:
                    action     = SecondMenu("Faculty");
                    controller = new FacultyController();
                    break;

                case 2:
                    action     = SecondMenu("Group");
                    controller = new GroupController();
                    break;

                case 3:
                    action     = SecondMenu("Lectures");
                    controller = new LecturesPlanController();
                    break;

                case 4:
                    action     = SecondMenu("Student");
                    controller = new StudentController();
                    break;

                case 5:
                    action     = SecondMenu("Subject");
                    controller = new SubjectController();
                    break;

                case 6:
                    action     = SecondMenu("Teacher");
                    controller = new TeacherController();
                    break;
                }


                switch (action)
                {
                case 1:
                    controller.Create();
                    break;

                case 2:
                    controller.Read();
                    break;

                case 3:
                    controller.Update();
                    break;

                case 4:
                    controller.Delete();
                    break;

                case 5:
                    controller.Find();
                    break;
                }
            } while (true);
        }