public Student CreateStudent(string firstName, string lastName, DateTime enrollmentDate)
        {
            var student = new Student
            {
                FirstName = firstName.Crop(50),
                LastName = lastName.Crop(50),
                EnrollmentDate = enrollmentDate
            };

            using (var db = _contextFactory.CreateContext())
            {
                db.Students.Add(student);
                db.Save();
                return student;
            }
        }
        public void NotValidIfEnrollmentDateIsGreaterThanMaxEnrollmentDate()
        {
            // Arrange
            var entity = new Student
            {
                FirstName = "Test1",
                LastName = "Test2",
                EnrollmentDate = Settings.MaxEnrollmentDate.AddMilliseconds(1)
            };

            // Act
            var validationResults = new List<ValidationResult>();
            var isValid = Validator.TryValidateObject(entity, new ValidationContext(entity), validationResults, true);

            // Assert
            Assert.False(isValid);
            Assert.Single(validationResults);
            Assert.Single(validationResults[0].MemberNames);
            Assert.Equal("EnrollmentDate", validationResults[0].MemberNames.ElementAt(0));
        }
        public void IsValid()
        {
            // Arrange
            var entity = new Student
            {
                Id = 1,
                FirstName = "Test1",
                LastName = "Test2",
                EnrollmentDate = new DateTime(2015, 9, 1)
            };

            // Act
            var validationResults = new List<ValidationResult>();
            var isValid = Validator.TryValidateObject(entity, new ValidationContext(entity), validationResults, true);

            // Assert
            Assert.True(isValid);
            Assert.NotNull(validationResults);
            Assert.Empty(validationResults);
        }
        public void NotValidIfLasttNameIsGreaterThan50()
        {
            // Arrange
            var entity = new Student
            {
                FirstName = "Test1",
                LastName = new string('A', 51),
                EnrollmentDate = DateTime.Now
            };

            // Act
            var validationResults = new List<ValidationResult>();
            var isValid = Validator.TryValidateObject(entity, new ValidationContext(entity), validationResults, true);

            // Assert
            Assert.False(isValid);
            Assert.Single(validationResults);
            Assert.Single(validationResults[0].MemberNames);
            Assert.Equal("LastName", validationResults[0].MemberNames.ElementAt(0));
        }
        public void NotValidIfLastNameIsNullOrWhiteSpace(string lastName)
        {
            // Arrange
            var entity = new Student
            {
                FirstName = "Test1",
                LastName = lastName,
                EnrollmentDate = new DateTime(2015, 9, 1)
            };

            // Act
            var validationResults = new List<ValidationResult>();
            var isValid = Validator.TryValidateObject(entity, new ValidationContext(entity), validationResults, true);

            // Assert
            Assert.False(isValid);
            Assert.Single(validationResults);
            Assert.Single(validationResults[0].MemberNames);
            Assert.Equal("LastName", validationResults[0].MemberNames.ElementAt(0));
        }