コード例 #1
0
        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());
        }
コード例 #2
0
ファイル: Student.cs プロジェクト: ruthlesshelp/Presentations
        public static Student FindById(int id)
        {
            var student = new Student();

            student.Get(id);

            return student;
        }
コード例 #3
0
        internal Application(
            IRepository<IndividualEntity> individualRepo,
            IRepository<StudentEntity> studentRepo,
            IRepository<ApplicationEntity> applicationRepo)
        {
            _applicationRepo = applicationRepo;

            Student = new Student(individualRepo, studentRepo);
        }
コード例 #4
0
        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.");
        }
コード例 #5
0
        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.");
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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());
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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());
        }