public void Validate_WithInvalidDateOfBirth_ExpectInvalidOperationException(
            int year,
            int month,
            int dayOfMonth,
            int todayYear,
            int todayMonth,
            int todayDayOfMonth)
        {
            // Arrange
            var classUnderTest =
                new Student(null, null)
                {
                    Today = new DateTime(todayYear, todayMonth, todayDayOfMonth),
                    DateOfBirth = new DateTime(year, month, dayOfMonth),
                };

            // Act
            TestDelegate act = () => classUnderTest.Validate();

            // Assert
            Assert.Throws<InvalidOperationException>(act,
                "Exception was not thrown for DOB {0} applying on {1}",
                classUnderTest.DateOfBirth.ToShortDateString(),
                classUnderTest.Today.ToShortDateString());
        }
Beispiel #2
0
        public static Student FindById(int id)
        {
            var student = new Student();

            student.Get(id);

            return student;
        }
        internal Application(
            IRepository<IndividualEntity> individualRepo,
            IRepository<StudentEntity> studentRepo,
            IRepository<ApplicationEntity> applicationRepo)
        {
            _applicationRepo = applicationRepo;

            Student = new Student(individualRepo, studentRepo);
        }
        public void given_today_is_2015_05_17_given_student_dob_19930517_when_validated_expect_no_exception()
        {
            // Arrange
            var classUnderTest =
                new Student(null, null)
                {
                    Today = new DateTime(2015, 5, 17),
                    DateOfBirth = new DateTime(1993, 5, 17),
                };

            // Act
            classUnderTest.Validate();

            // Assert
            Assert.Pass("No exception thrown.");
        }
        public void Validate_WithValidDateOfBirth_ExpectNoException(
            int year,
            int month,
            int dayOfMonth,
            int todayYear,
            int todayMonth,
            int todayDayOfMonth)
        {
            // Arrange
            var classUnderTest =
                new Student(null, null)
                {
                    Today = new DateTime(todayYear, todayMonth, todayDayOfMonth),
                    DateOfBirth = new DateTime(year, month, dayOfMonth),
                };

            // Act
            classUnderTest.Validate();

            // Assert
            Assert.Pass("No exception thrown.");
        }
        public void Save_WithValidNewStudent_ExpectIndividualDalCreateIsCalledOnce()
        {
            // Arrange
            var today = new DateTime(2003, 5, 17);

            const int ExpectedStudentId = 897931;

            var stubStudentRepo = new Mock<IRepository<StudentEntity>>();
            stubStudentRepo
                .Setup(e => e.Retrieve(ExpectedStudentId))
                .Returns(default(StudentEntity));
            stubStudentRepo
                .Setup(e => e.Create(It.IsAny<StudentEntity>()))
                .Returns(ExpectedStudentId);

            var mockIndividualRepo = new Mock<IRepository<IndividualEntity>>();
            mockIndividualRepo
                .Setup(e => e.Create(It.IsAny<IndividualEntity>()))
                .Returns(ExpectedStudentId);

            var classUnderTest =
                new Student(mockIndividualRepo.Object, stubStudentRepo.Object)
                {
                    Today = today,
                    DateOfBirth = today.AddYears(-19),
                };

            // Act
            classUnderTest.Save();

            // Assert
            Assert.AreEqual(ExpectedStudentId, classUnderTest.Id);
            mockIndividualRepo
                .Verify(e => e.Create(It.IsAny<IndividualEntity>()), Times.Once());
        }
        public void Save_WithInvalidDateOfBirth_ExpectInvalidOperationException(
            int age)
        {
            // Arrange
            var today = new DateTime(2003, 5, 17);

            var classUnderTest =
                new Student(null, null)
                {
                    Today = today,
                    DateOfBirth = today.AddYears(-1 * age),
                };

            // Act
            TestDelegate act = () => classUnderTest.Save();

            // Assert
            Assert.Throws<InvalidOperationException>(act,
                "Exception was not thrown for age {0}", age);
        }
        public void Save_WithAnExistingStudentImproperlyCreated_ExpectInvalidOperationException()
        {
            // Arrange
            var today = new DateTime(2003, 5, 17);

            const int ExpectedStudentId = 897931;

            var stubIndividualRepo = new Mock<IRepository<IndividualEntity>>();
            stubIndividualRepo
                .Setup(e => e.Update(It.IsAny<IndividualEntity>()));

            var stubStudentRepo = new Mock<IRepository<StudentEntity>>();
            stubStudentRepo
                .Setup(e => e.Retrieve(ExpectedStudentId))
                .Returns(default(StudentEntity));
            stubStudentRepo
                .Setup(e => e.Create(It.IsAny<StudentEntity>()))
                .Returns(23);

            var classUnderTest =
                new Student(stubIndividualRepo.Object, stubStudentRepo.Object)
                {
                    Id = ExpectedStudentId,
                    Today = today,
                    DateOfBirth = today.AddYears(-19),
                };

            // Act
            TestDelegate act = () => classUnderTest.Save();

            // Assert
            Assert.Throws<InvalidOperationException>(act);
        }
        public void GivenAnExistingStudentWhenSavedExpectIndividualDalUpdateIsCalledOnce()
        {
            // Arrange
            var today = new DateTime(2003, 5, 17);

            const int expectedStudentId = 897931;
            var studentEntity = new StudentEntity { Id = expectedStudentId, };

            var stubStudentRepo = new Mock<IRepository<StudentEntity>>();
            stubStudentRepo
                .Setup(e => e.Retrieve(expectedStudentId))
                .Returns(studentEntity);

            var mockIndividualRepo = new Mock<IRepository<IndividualEntity>>();
            mockIndividualRepo
                .Setup(e => e.Update(It.IsAny<IndividualEntity>()));

            var classUnderTest =
                new Student(mockIndividualRepo.Object, stubStudentRepo.Object)
                {
                    Id = expectedStudentId,
                    Today = today,
                    DateOfBirth = today.AddYears(-19),
                };

            // Act
            classUnderTest.Save();

            // Assert
            Assert.AreEqual(expectedStudentId, classUnderTest.Id);
            mockIndividualRepo
                .Verify(e => e.Update(It.IsAny<IndividualEntity>()), Times.Once());
        }
        public void GivenStudentAgeOf13WhenSavingExpectInvalidOperationException()
        {
            // Arrange
            var today = new DateTime(2003, 5, 17);

            var classUnderTest =
                new Student(null, null)
                {
                    Today = today,
                    DateOfBirth = today.AddYears(-1 * 13),
                };

            // Act
            TestDelegate act = () => classUnderTest.Save();

            // Assert
            Assert.Throws<InvalidOperationException>(act,
                "Exception was not thrown for age {0}", 13);
        }
        public void given_today_is_2015_05_17_given_student_dob_20150518WhenValidatedExpectInvalidOperationException()
        {
            // Arrange
            var classUnderTest =
                new Student(null, null)
                {
                    Today = new DateTime(2015, 5, 17),
                    DateOfBirth = new DateTime(2015, 5, 18),
                };

            // Act
            TestDelegate act = () => classUnderTest.Validate();

            // Assert
            Assert.Throws<InvalidOperationException>(act,
                "Exception was not thrown for DOB {0} applying on {1}",
                classUnderTest.DateOfBirth.ToShortDateString(),
                classUnderTest.Today.ToShortDateString());
        }