Exemple #1
0
        public void MarriedPersonHasFamily()
        {
            Person p1 = new Person() { Gender = "M" };
            Person p2 = new Person() { Gender = "F" };
            p1.Marry(p2);

            Assert.NotNull(p1.Family);
            Assert.NotNull(p2.Family);
            Assert.Same(p1.Family, p2.Family);
        }
Exemple #2
0
        public void FamilyHasHusbandAndWife()
        {
            Person p1 = new Person() { Gender = "M" };

            Person p2 = new Person() { Gender = "F" };

            Family f = p1.Marry(p2);

            Assert.Same(f.Husband, p1);

            Assert.Same(f.Wife, p2);
        }
Exemple #3
0
            public void ThrowsExceptionIfAgeLessThan20Years()
            {
                Person p1 = new Person();
                Person p2 = new Person();
                int thisYear = DateTime.Now.Year;

                p1.BirthYear = thisYear - 15; // 15 yo.
                p2.BirthYear = thisYear - 30; // 30 yo.

                //Assert.Throws(typeof(Exception), () => {
                //  p1.Marry(p2);
                //});

                Assert.Throws<Exception>(() => {
                  p1.Marry(p2);
                });
            }
Exemple #4
0
            public void ShouldReturnFamily()
            {
                Person p1 = new Person();
                Person p2 = new Person();

                p1.Gender = "M";
                p2.Gender = "F";

                Family f = p1.Marry(p2);

                Assert.NotNull(f);
            }
Exemple #5
0
            public void MaleCannotMarryToMale()
            {
                Person p1 = new Person();
                Person p2 = new Person();
                p1.Gender = "M";
                p2.Gender = "M";

                Assert.Throws<Exception>(() => {
                  p1.Marry(p2);
                });
            }
Exemple #6
0
            public void MaleCanMarryToFemale()
            {
                Person p1 = new Person();
                Person p2 = new Person();
                p1.Gender = "M";
                p2.Gender = "F";

                Assert.DoesNotThrow(() => {
                  p1.Marry(p2);
                });
            }
Exemple #7
0
            public void ThrowExceptionIfAgeLessThan20Years()
            {
                Person p1 = new Person();
                Person p2 = new Person();
                int thisYear = DateTime.Now.Year;
                p1.BirthYear = thisYear;    //0
                p2.BirthYear = thisYear;    //0

                // Generics
                Assert.Throws<Exception>(() =>
                {
                    p1.Marry(p2);
                });
            }
Exemple #8
0
            public void MaleCanMarryToFemaleIfAgeGreaterThan20()
            {
                Person p1 = new Person();
                Person p2 = new Person();

                int thisYear = DateTime.Now.Year;
                p1.BirthYear = thisYear - 30;     //20
                p2.BirthYear = thisYear - 30;     //20

                p1.Gender = "M";
                p2.Gender = "F";

                Assert.DoesNotThrow(() =>
                {
                    p1.Marry(p2);
                });
            }