public void CalculateStanding_ReturnsCorrectValue()
        {
            var repository = Setup();
            var tracker    = new GraduationTracker(repository.Object);

            Assert.AreEqual(new Tuple <bool, Standing>(false, Standing.Remedial), tracker.CalculateStanding(49));
        }
        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);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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());
        }
        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);
        }
示例#7
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);
        }
        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
        }
示例#9
0
        public void TestNull()
        {
            var tracker = new GraduationTracker();

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

            Assert.IsFalse(result.Item1);
        }
示例#10
0
        public void StudentHasOneCourse_ReturnsTrue()
        {
            var repository = Setup();
            var tracker    = new GraduationTracker(repository.Object);
            var diploma    = AnyDiploma;
            var student    = AnyStudents[2];

            Assert.AreEqual(new Tuple <bool, Standing>(false, Standing.MagnaCumLaude), tracker.HasGraduated(diploma, student));
        }
        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);
        }
        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);
        }
示例#13
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);
        }
示例#14
0
        public void Test1GraduationStanding()
        {
            Diploma diploma = new Diploma();
            Student student = new Student();
            RequirementRepository requRepo = new RequirementRepository();

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

            student = new Student
            {
                Id        = 1,
                DiplomaId = 1,
                Courses   = new Course[]
                {
                    new Course {
                        CourseId = 1, CourseName = "Math", Mark = 95
                    },
                    new Course {
                        CourseId = 2, CourseName = "Science", Mark = 95
                    },
                    new Course {
                        CourseId = 3, CourseName = "Literature", Mark = 95
                    },
                    new Course {
                        CourseId = 4, CourseName = "Physichal Education", Mark = 95
                    }
                }
            };

            var      actual           = new GraduationTracker(requRepo, student, diploma).HasGraduated();
            STANDING expectedStanding = STANDING.MagnaCumLaude;

            // Standing
            Assert.AreEqual(expectedStanding, actual.Item2);
        }
示例#15
0
        public void Test2HasGraduated()
        {
            Diploma diploma = new Diploma();
            Student student = new Student();
            RequirementRepository requRepo = new RequirementRepository();

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

            student = new Student
            {
                Id        = 3,
                DiplomaId = 1,
                Courses   = new Course[]
                {
                    new Course {
                        CourseId = 1, CourseName = "Math", Mark = 50
                    },
                    new Course {
                        CourseId = 2, CourseName = "Science", Mark = 50
                    },
                    new Course {
                        CourseId = 3, CourseName = "Literature", Mark = 50
                    },
                    new Course {
                        CourseId = 4, CourseName = "Physichal Education", Mark = 50
                    }
                }
            };

            var  actual   = new GraduationTracker(requRepo, student, diploma).HasGraduated();
            bool expected = true;

            // Is Graduated
            Assert.AreEqual(expected, actual.Item1);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
示例#20
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));
            }
        }
示例#21
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);
        }
示例#22
0
        public void TestInitialize()
        {
            _sut = new GraduationTracker();

            _diploma = new Diploma
            {
                Id           = 1,
                Credits      = 4,
                Requirements = new[] { 100, 102, 103, 104 }
            };
        }
        public void GraduationTrackersTestsInitialize()
        {
            tracker = new GraduationTracker();
            diploma = new Diploma
            {
                Id           = 1,
                Credits      = 4,
                Requirements = new int[] { 100, 102, 103, 104 }
            };

            studentData = new Student();
        }
示例#24
0
        public void GetStanding()
        {
            // Arrange
            var tracker      = new GraduationTracker();
            var average      = 75;
            var mockStanding = STANDING.Average;

            // Act
            var actualStanding = GraduationTracker.GetStanding(average);

            // Assert
            Assert.AreEqual(mockStanding, actualStanding);
        }
        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);
            }
        }
示例#26
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());
        }
        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());
        }
示例#28
0
        public void TestNull()
        {
            var tracker = new GraduationTracker();

            var notGraduated = new List <Tuple <bool, STANDING> >();
            var result       = tracker.HasGraduated(null, null);

            if (!result.Item1 && result.Item2 == STANDING.None)
            {
                notGraduated.Add(result);
            }

            Assert.AreEqual(notGraduated.Count(), 1);
        }
        public void ShouldGraduateWithMagnaCumLaude()
        {
            // Arrange

            GraduationTracker tracker = new GraduationTracker(new ServiceMock());
            Diploma           diploma = Repository.GetDiploma(1);
            Student           student = Repository.GetStudent(1);

            // Act
            Standing result = tracker.HasGraduated(diploma, student);

            //Assert
            Assert.AreEqual(Standing.MagnaCumLaude, result);
        }
        public void TestNotGraduated()
        {
            var tracker  = new GraduationTracker();
            var diploma  = Repository.GetDiploma(1);
            var students = new List <Student> {
                Repository.GetStudent(5),
                Repository.GetStudent(6),
                Repository.GetStudent(7)
            };

            var notGraduated = students.Select(student => tracker.HasGraduated(diploma, student)).ToList();

            Assert.IsFalse(notGraduated.Any(e => e.Item1)); //Test that there are no students in this group that have graduated
        }