Пример #1
0
        public void ShouldCreateStudentWithError()
        {
            commandRegister = new StudentInputRegister()
            {
                CourseId  = course.CourseId,
                Birthdate = DateTime.Now,
                FirstName = string.Empty,
                LastName  = string.Empty,
                CPF       = string.Empty,
                Email     = string.Empty,
                Phone     = string.Empty,
                Gender    = string.Empty,
                Country   = string.Empty,
                City      = string.Empty,
                Address   = string.Empty
            };

            StandardResult result = (StandardResult)handler.Handle(commandRegister);

            Assert.IsFalse(result.IsValid);
            Assert.IsTrue(result.Notifications.Any(x => x.Key == "Email" && x.Value != null));
            Assert.IsTrue(result.Notifications.Any(x => x.Key == "CPF" && x.Value != null));
            Assert.IsTrue(result.Notifications.Any(x => x.Key == "FirstName" && x.Value != null));
            Assert.IsTrue(result.Notifications.Any(x => x.Key == "LastName" && x.Value != null));
            Assert.IsTrue(result.Notifications.Any(x => x.Key == "Telefone" && x.Value != null));
            Assert.IsTrue(result.Notifications.Any(x => x.Key == "City" && x.Value != null));
            Assert.IsTrue(result.Notifications.Any(x => x.Key == "Country" && x.Value != null));
        }
Пример #2
0
        public ActionResult Create(CreateStudentViewModel student)
        {
            var input = new StudentInputRegister
            {
                Address   = student.Address,
                Birthdate = student.Birthdate,
                City      = student.City,
                Country   = student.Country,
                CourseId  = student.SelectedCourse,
                CPF       = student.CPF,
                Email     = student.Email,
                FirstName = student.FirstName,
                Gender    = student.Gender,
                LastName  = student.LastName,
                Phone     = student.Phone
            };
            var result = _studentCommand.Handle(input);

            if (!result.IsValid)
            {
                foreach (var n in result.Notifications)
                {
                    ModelState.AddModelError(n.Key, n.Value);
                }
                student.Courses = GetComboboxCourse();
                return(View(student));
            }
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public void Init()
        {
            conection  = new MSSQLDB(new DBConfiguration());
            _SREP      = new StudentRepository(conection);
            _encryptor = new Encryptor();
            handler    = new StudentCommandHandler(_SREP, _encryptor);

            var db = conection.GetCon();

            // Create Course
            course = new Course(Guid.NewGuid(), "LTP5");
            var sql = "INSERT INTO [Course] ([Id], [Name]) VALUES (@Id, @Name)";

            db.Execute(sql, param: new { Id = course.CourseId, Name = course.Name });

            var    cpf      = "964.377.278-02";
            string password = cpf.Replace("-", "").Replace(".", "");

            password = _encryptor.Encrypt(password, out string salt);

            student = new Student(course, DateTime.Now, "Abmael", "Araujo", cpf, "*****@*****.**", "(86) 2802-4826", "M", "Brasil", "Araguaina", "Centro", password, salt);
            _SREP.Create(student);

            commandRegister = new StudentInputRegister()
            {
                CourseId  = course.CourseId,
                Birthdate = DateTime.Now,
                FirstName = "Ester",
                LastName  = "Emily Oliveira",
                CPF       = "494.035.320-68",
                Email     = "*****@*****.**",
                Phone     = "(45) 2509-8770",
                Gender    = "M",
                Country   = "Brasil",
                City      = "Araguaina",
                Address   = "Centro"
            };

            commandUpdate = new StudentInputUpdate()
            {
                CourseId  = course.CourseId,
                Birthdate = DateTime.Now,
                FirstName = "Iago",
                LastName  = "Bernardo Nunes",
                Email     = "*****@*****.**",
                Phone     = "(65) 3544-9294",
                Gender    = "M",
                Country   = "França",
                City      = "Budapeste",
                Address   = "Norte",
                StudentId = student.Id
            };
        }