コード例 #1
0
        public void ShouldFailAndStandRemedial()
        {
            var student = new Student
            {
                Id      = 3,
                Courses = new[]
                {
                    new Course {
                        Id = 1, Name = "Math", Mark = 23
                    },
                    new Course {
                        Id = 2, Name = "Science", Mark = 33
                    },
                    new Course {
                        Id = 3, Name = "Literature", Mark = 44
                    },
                    new Course {
                        Id = 4, Name = "Physichal Education", Mark = 70
                    }
                }
            };

            var result = _sut.HasGraduated(_diploma, student);

            Assert.AreEqual(Standing.Remedial, result.Standing);
            Assert.IsFalse(result.Pass);
        }
コード例 #2
0
        public void HasGraduated_Remedial()
        {
            var inputValue1 = false;
            var inputValue2 = STANDING.Remedial;

            //--- average < 50; Mark=40
            var studentsOut = new Student
            {
                Id      = 1,
                Courses = new Course[]
                {
                    new Course {
                        Id = 1, Name = "Math", Mark = 40
                    },
                    new Course {
                        Id = 2, Name = "Science", Mark = 40
                    },
                    new Course {
                        Id = 3, Name = "Literature", Mark = 40
                    },
                    new Course {
                        Id = 4, Name = "Physichal Education", Mark = 40
                    }
                }
            };

            tupleOutput = graduationTracker.HasGraduated(diploma, studentsOut);

            Assert.AreEqual(tupleOutput.Item1, inputValue1);
            Assert.AreEqual(tupleOutput.Item2, inputValue2);
        }
コード例 #3
0
        public void TestHasGraduated(int diplomaId, int studentId)
        {
            var graduated = new List <Tuple <bool, STANDING, bool> >();

            graduated.Add(_tracker.HasGraduated(diplomaId, studentId));
            Assert.IsTrue(graduated.Any());
        }
コード例 #4
0
        public void HasAnyStudentGraduatedWithAvrage()
        {
            var result = _graduationTracker.HasGraduated(_diploma, _lstStudents.FirstOrDefault(a => a.Id == 3));

            Assert.AreEqual(result.Item1, true);
            Assert.AreEqual(result.Item2, Standing.Average);
        }
コード例 #5
0
        public void GraduateIfEnoughCreditsAndHighEnoughAverage()
        {
            var student = new Student
            {
                Id      = 1,
                Courses = new Course[]
                {
                    new Course {
                        Id = 1, Name = "Math", Mark = 50
                    },
                    new Course {
                        Id = 2, Name = "Science", Mark = 50
                    },
                    new Course {
                        Id = 3, Name = "Literature", Mark = 50
                    },
                    new Course {
                        Id = 4, Name = "Physical Education", Mark = 50
                    }
                }
            };

            var hasGraduatedWithStanding = _tracker.HasGraduated(_diploma, student);

            Assert.IsTrue(hasGraduatedWithStanding.Item1);
        }
コード例 #6
0
        public void TestHasCredits()
        {
            var tracker = new GraduationTracker();
            Tuple <bool, STANDING> result;

            //I'm going to assume that we know the students in the Repository and which ones
            //have the criteria to graduate before hand. Otherwise we will have no way of validating
            //the results of the tested function.

            //Student ID 1 - Has an average of 95 - Will Graduate MagnaCumLaude
            result = tracker.HasGraduated(Repository.GetDiploma(1), Repository.GetStudent(1));
            Assert.IsTrue(result.Item1);
            Assert.AreEqual(result.Item2, STANDING.MagnaCumLaude);

            //Student ID 2 - Has an average of 80 - Will Graduate *
            //According to the code it will be MagnaCumLaude but seems like SumaCumLaude isn't used.
            result = tracker.HasGraduated(Repository.GetDiploma(1), Repository.GetStudent(2));
            Assert.IsTrue(result.Item1);
            Assert.AreEqual(result.Item2, STANDING.MagnaCumLaude);

            //Student ID 3 - Has an average of 50 - Will Not Graduate
            result = tracker.HasGraduated(Repository.GetDiploma(1), Repository.GetStudent(3));
            Assert.IsFalse(result.Item1);
            Assert.AreEqual(result.Item2, STANDING.Average);

            //Student ID 4 - Has an average of 40 - Will Not Graduate
            result = tracker.HasGraduated(Repository.GetDiploma(1), Repository.GetStudent(4));
            Assert.IsFalse(result.Item1);
            Assert.AreEqual(result.Item2, STANDING.Remedial);
        }
コード例 #7
0
        public void TestHasDiploma()
        {
            var graduated = (from student in _students
                             let hasDiploma = true
                                              where _tracker.HasGraduated(_diploma, student).Item1.Equals(hasDiploma)
                                              select _tracker.HasGraduated(_diploma, student)).ToList();

            Assert.AreEqual(3, graduated.Count, "The number of graduates are not equal to 3");
        }
コード例 #8
0
        public void HasGraduated_StudentWith50Average_AverageStudentTest()
        {
            var diploma = CreateDiploma();
            var student = CreateStudents().Where(s => s.Id == 3).FirstOrDefault();

            tracker = CreateGraduationTracker();

            Assert.IsTrue(tracker.HasGraduated(diploma, student).Graduated);
            Assert.IsTrue(tracker.HasGraduated(diploma, student).Standing == STANDING.Average);
        }
コード例 #9
0
        public void HasGraduated_StudentWith95Average_MagnaCumLaudeTest()
        {
            diploma = CreateDiploma();
            var student = CreateStudents().Where(s => s.Id == 1).FirstOrDefault();

            tracker = CreateGraduationTracker();

            Assert.IsTrue(tracker.HasGraduated(diploma, student).Graduated);
            Assert.IsTrue(tracker.HasGraduated(diploma, student).Standing == STANDING.MagnaCumLaude);
        }
コード例 #10
0
        //Test to check if the test data contains any graduate student;
        public void TestHasgraduate()
        {
            var graduated = new List <Tuple <bool, STANDING> >();

            foreach (var student in students)
            {
                graduated.Add(tracker.HasGraduated(diploma, student));
            }

            Assert.IsTrue(graduated.Any(x => x.Item1 == true));
        }
コード例 #11
0
        public void TestHasGraduated()
        {
            Diploma diploma = mydataprovider.getDiploma();

            Student[] students  = mydataprovider.getStudents();
            var       graduated = new List <Tuple <bool, Standing> >();

            foreach (var student in students)
            {
                graduated.Add(tracker.HasGraduated(diploma, student));
            }

            Assert.IsTrue(graduated.Any());   //Fixed broken test by replacing IsFalse() with IsTrue()
        }
コード例 #12
0
        public void TestGraduationTracker_differentStudents_AddToList()
        {
            //Arrange -> SETUP METHOD

            //Act
            var graduated = new List <Tuple <bool, STANDING> >();

            foreach (var student in _students)
            {
                graduated.Add(_tracker.HasGraduated(_diploma[0], student));
            }
            //Assert
            Assert.IsNotNull(graduated);
        }
コード例 #13
0
        public void TestHasGraduated()
        {
            var tracker = new GraduationTracker();

            IDiploma diploma = Repository.GetDiploma(1);


            // I could have use directly GetStudents but it is private, that's why I used GetStudent() method.
            IStudent[] students = new[]
            {
                Repository.GetStudent(1),
                Repository.GetStudent(2),
                Repository.GetStudent(3),
                Repository.GetStudent(4)
            };

            var graduated = new List <Tuple <bool, STANDING> >();

            foreach (var student in students)
            {
                graduated.Add(tracker.HasGraduated(diploma, student));
            }

            Assert.IsTrue(graduated[0].Item2 == STANDING.MagnaCumLaude);
            Assert.IsTrue(graduated[1].Item2 == STANDING.SumaCumLaude);
            Assert.IsTrue(graduated[2].Item2 == STANDING.Average);
            Assert.IsTrue(graduated[3].Item2 == STANDING.Remedial);
        }
コード例 #14
0
        public void TestStanding(int marks, STANDING standing)
        {
            var students = new[]
            {
                new Student
                {
                    Id      = 1,
                    Courses = new Course[]
                    {
                        new Course {
                            Id = 1, Name = "Math", Mark = marks
                        },
                        new Course {
                            Id = 2, Name = "Science", Mark = marks
                        },
                        new Course {
                            Id = 3, Name = "Literature", Mark = marks
                        },
                        new Course {
                            Id = 4, Name = "Physichal Education", Mark = marks
                        }
                    }
                }
            };
            Mock <IStudentRepository> _mockStuRepository = new Mock <IStudentRepository>();

            _mockStuRepository.Setup(x => x.GetStudents()).Returns(students);
            _mockStuRepository.Setup(r => r.GetStudent(It.IsAny <int>()))
            .Returns <int>(id => students.SingleOrDefault(r => r.Id == id));
            var tracker = new GraduationTracker(_mockRequirementRepository.Object, _mockDiplomaRepository.Object, _mockStuRepository.Object);

            var result = tracker.HasGraduated(1, 1);

            Assert.AreEqual(standing, result.Item2);
        }
コード例 #15
0
        public void TestHasGraduated_MarksBelowAverage(int marks)
        {
            var students = new[] { new Student
                                   {
                                       Id      = 1,
                                       Courses = new Course[]
                                       {
                                           new Course {
                                               Id = 1, Name = "Math", Mark = marks
                                           },
                                           new Course {
                                               Id = 2, Name = "Science", Mark = marks
                                           },
                                           new Course {
                                               Id = 3, Name = "Literature", Mark = marks
                                           },
                                           new Course {
                                               Id = 4, Name = "Physichal Education", Mark = marks
                                           }
                                       }
                                   } };

            Mock <IStudentRepository> _mockStuRepository = new Mock <IStudentRepository>();

            _mockStuRepository.Setup(x => x.GetStudents()).Returns(students);
            _mockStuRepository.Setup(r => r.GetStudent(It.IsAny <int>()))
            .Returns <int>(id => students.SingleOrDefault(r => r.Id == id));
            var tracker = new GraduationTracker(_mockRequirementRepository.Object, _mockDiplomaRepository.Object, _mockStuRepository.Object);

            var result = tracker.HasGraduated(1, 1);

            Assert.IsFalse(result.Item1);//should return false if not graduated
        }
コード例 #16
0
        //Confirm that graduated students have required credits
        public void TestHasGraduated()
        {
            var tracker = new GraduationTracker();
            //get dummy data objects for testing
            var diploma  = DummyRepository.GetDummyDiploma();
            var students = DummyRepository.GetDummyStudents();


            //confirm that students have graduated as expected
            var graduated = new List <Tuple <bool, STANDING> >();

            foreach (var student in students)
            {
                graduated.Add(tracker.HasGraduated(diploma, student));
            }

            //initialize expected result
            var expected = new List <Tuple <bool, STANDING> >
            {
                Tuple.Create(true, STANDING.SumaCumLaude),
                Tuple.Create(true, STANDING.MagnaCumLaude),
                Tuple.Create(true, STANDING.Average),
                Tuple.Create(false, STANDING.Remedial)
            };

            //compare expected with method result
            Assert.IsTrue(graduated.Count == expected.Count && !graduated.Except(expected).Any());
        }
コード例 #17
0
        public void TestIfCourseIsOffRequirements()
        {
            var tracker = new GraduationTracker();

            var diploma = new Diploma()
            {
                Id           = 1,
                Credits      = 4,
                Requirements = new List <int> {
                    1, 2, 3, 4
                }
            };

            var student = new Student()
            {
                Id      = 34,
                Courses = new List <Course>()
                {
                    new Course {
                        Id = 100, Name = "Math", Mark = 50
                    },
                    new Course {
                        Id = 102, Name = "Science", Mark = 97
                    },
                    new Course {
                        Id = 103, Name = "Literature", Mark = 76
                    },
                    new Course {
                        Id = 104, Name = "Physichal Education", Mark = 48
                    }
                }
            };

            Assert.IsFalse(tracker.HasGraduated(diploma, student).Item1);
        }
コード例 #18
0
        public void TestIfStandingIsSumaCumLaude()
        {
            var tracker = new GraduationTracker();

            var diploma = new Diploma()
            {
                Id           = 1,
                Credits      = 4,
                Requirements = new List <int> {
                    100, 102, 103, 104
                }
            };

            var student = new Student()
            {
                Id      = 34,
                Courses = new List <Course>()
                {
                    new Course {
                        Id = 100, Name = "Math", Mark = 98
                    },
                    new Course {
                        Id = 102, Name = "Science", Mark = 97
                    },
                    new Course {
                        Id = 103, Name = "Literature", Mark = 93
                    },
                    new Course {
                        Id = 104, Name = "Physichal Education", Mark = 98
                    }
                }
            };

            Assert.AreEqual(tracker.HasGraduated(diploma, student).Item2, Standing.SumaCumLaude);
        }
コード例 #19
0
        public void TestNull()
        {
            var tracker = new GraduationTracker();

            var result = tracker.HasGraduated(null, null);

            Assert.IsFalse(result.Item1);
        }
コード例 #20
0
        public void TestStudentHasOptedForAtLeastOneCourses()
        {
            var     tracker = new GraduationTracker();
            var     diploma = Repository.GetDiploma(2);
            Student student = Repository.GetStudent(5);

            Tuple <bool, STANDING> result = tracker.HasGraduated(diploma, student);

            Assert.AreEqual(new Tuple <bool, STANDING>(false, STANDING.Remedial), result);
        }
コード例 #21
0
        private List <Tuple <bool, STANDING> > GraduateList()
        {
            var graduated = new List <Tuple <bool, STANDING> >();

            foreach (var student in _students)
            {
                graduated.Add(_graduationTracker.HasGraduated(_diploma, student));
            }

            return(graduated);
        }
コード例 #22
0
        public void TestEmptyListItems()
        {
            var tracker = new GraduationTracker();

            var diploma = new Diploma();
            var student = new Student();

            var result = tracker.HasGraduated(diploma, student);

            Assert.IsFalse(result.Item1);
        }
コード例 #23
0
        public void TestFailedMissedRequirements()
        {
            // Total credits are met
            // Standing is met
            // Requirements are not met
            var tracker = new GraduationTracker();

            var diploma = new Diploma
            {
                Id           = 1,
                Credits      = 4,
                Requirements = new int[] { 100, 102, 103, 104 }
            };

            var student = new Student
            {
                Id      = 3,
                Courses = new Course[]
                {
                    new Course {
                        Id = 1, Name = "Math", Mark = 49, Credits = 1
                    },
                    new Course {
                        Id = 2, Name = "Science", Mark = 49, Credits = 1
                    },
                    new Course {
                        Id = 3, Name = "Literature", Mark = 49, Credits = 1
                    },
                    new Course {
                        Id = 4, Name = "Physichal Education", Mark = 49, Credits = 1
                    },
                    new Course {
                        Id = 5, Name = "Bird identification", Mark = 100, Credits = 1
                    },
                    new Course {
                        Id = 6, Name = "Underwater basketweaving", Mark = 100, Credits = 1
                    },
                    new Course {
                        Id = 7, Name = "Sitting", Mark = 100, Credits = 1
                    },
                    new Course {
                        Id = 8, Name = "Naptime", Mark = 100, Credits = 1
                    },
                    new Course {
                        Id = 9, Name = "Spacing out", Mark = 100, Credits = 1
                    }
                }
            };

            var result       = tracker.HasGraduated(diploma, student);
            var hasGraduated = result.Item1;

            Assert.IsFalse(hasGraduated);
        }
コード例 #24
0
        public void TestWithInvalidDiplomaThrowsException()
        {
            var tracker = new GraduationTracker();

            var graduated = new List <Tuple <bool, STANDING> >();

            foreach (var student in StudentMock.GetStudentMock())
            {
                graduated.Add(tracker.HasGraduated(null, student));
            }
        }
コード例 #25
0
        public void HasGraduated_StandingRemedial_False()
        {
            var remedialStudent = Repository.GetStudent(4);
            var diploma         = Repository.GetDiploma(1);
            var tracker         = new GraduationTracker();

            var result = tracker.HasGraduated(diploma, remedialStudent);

            Assert.AreEqual(result.Item1, false);
            Assert.AreEqual(result.Item2, STANDING.Remedial);
        }
コード例 #26
0
        public void HasGraduated_StandingAverage_True()
        {
            var averageStudent = Repository.GetStudent(3);
            var diploma        = Repository.GetDiploma(1);
            var tracker        = new GraduationTracker();

            var result = tracker.HasGraduated(diploma, averageStudent);

            Assert.AreEqual(result.Item1, true);
            Assert.AreEqual(result.Item2, STANDING.Average);
        }
コード例 #27
0
        public void HasGraduated_StandingMagnaCumLaude_True()
        {
            var magnaCumLaudeStudent = Repository.GetStudent(1);
            var diploma = Repository.GetDiploma(1);
            var tracker = new GraduationTracker();

            var result = tracker.HasGraduated(diploma, magnaCumLaudeStudent);

            Assert.AreEqual(result.Item1, true);
            Assert.AreEqual(result.Item2, STANDING.MagnaCumLaude);
        }
コード例 #28
0
        public void TestHasCredits()
        {
            var tracker = new GraduationTracker();

            var graduated = new List <Tuple <bool, STANDING> >();

            foreach (var student in StudentMock.GetStudentMock())
            {
                graduated.Add(tracker.HasGraduated(DiplomaMock.GetDiplomaMock(), student));
            }

            Assert.IsFalse(!graduated.Where(x => x.Item1 == false).Any());
        }
コード例 #29
0
        public void HasGraduated_StandingNone_Exception()
        {
            var unknownStudent = Repository.GetStudent(0);
            var diploma        = Repository.GetDiploma(1);
            var tracker        = new GraduationTracker();

            try {
                var result = tracker.HasGraduated(diploma, unknownStudent);
                Assert.IsTrue(false);
            }catch (Exception) {
                Assert.IsTrue(true);
            }
        }
コード例 #30
0
        public void TestHasCredits()
        {
            var tracker = new GraduationTracker();

            var graduated = new List <Tuple <bool, Standing> >();

            foreach (var student in _lstStudents)
            {
                graduated.Add(tracker.HasGraduated(_diploma, student));
            }

            Assert.IsTrue(graduated.Any());
        }