public void UpdateLessonGrade_IsPassedTrue_Test() { // Create a LessonService class object referance var lessonSvc = new LessonService(); // Create parametters for true test case scnerio var lessonId = 12; var grade = 98.2d; // examaple grade to update the IsPassed value to true and pass the test case //var grade = 60.3d; // example grade to update the IsPassed value to false and fail the test case //Execute a "UpdateLessonGrade" method call with above parametters // The positive test case shoulld update the boolean value IsPassed to "true" for the lesson no 12 if the grade parametter is gretter than MinimumPassingGrade i.e 80 lessonSvc.UpdateLessonGrade(lessonId, grade); // Create a LessonRepository class referance to get the object with "lessonId" 12 to check for the updated "IsPassed" variable value var lessonRepo = new LessonRepository(); var lesson = lessonRepo.GetLesson(lessonId); //Verify the condition with the return type as true to pass the test case //As the lessons and Module repository returns data froo a hardcoded list the object variable value might not get updated but the test case can be tested by updating //the hardcoded values of Lessons Objects in the LessonsRepositiry class Assert.IsTrue(lesson.IsPassed); //The above test case passes if the parametters passes are satisfing the conditions of MinimumPassingGrade and the record is updated as passed (i.e IsPassed=true) }
public void UpdateLessonGrade_GetLessonReturnsDefaultObject_ModuleRepositoryIsCalled() { //arrange Mock <ILessonRepository> mockLessonRepo = new Mock <ILessonRepository>(); mockLessonRepo.Setup(x => x.GetLesson(It.IsAny <int>())).Returns(new Lesson()); Mock <IModuleRepository> mockModuleRepo = new Mock <IModuleRepository>(); mockModuleRepo.Setup(x => x.GetModule(It.IsAny <int>())).Returns(new Module { ModuleId = 0, MinimumPassingGrade = 0, Lessons = new List <Lesson> { new Lesson { LessonId = 0, Grade = 0.0d, IsPassed = true } } }); LessonService lessonService = new LessonService(mockLessonRepo.Object, mockModuleRepo.Object); //act lessonService.UpdateLessonGrade(0, 0.0d); //assert mockLessonRepo.Verify(x => x.GetLesson(It.IsAny <int>()), Times.Once); mockModuleRepo.Verify(x => x.GetModule(It.IsAny <int>()), Times.Once); }
public void UpdateLessonGrade_GetLessonReturnsNull() { //arrange Lesson nullLesson = null; Mock <ILessonRepository> mockLessonRepo = new Mock <ILessonRepository>(); mockLessonRepo.Setup(x => x.GetLesson(It.IsAny <int>())).Returns(nullLesson); Mock <IModuleRepository> mockModuleRepo = new Mock <IModuleRepository>(); mockModuleRepo.Setup(x => x.GetModule(It.IsAny <int>())).Returns(new Module { ModuleId = 0, MinimumPassingGrade = 0, Lessons = new List <Lesson> { new Lesson { LessonId = 0, Grade = 0.0d, IsPassed = true } } }); LessonService lessonService = new LessonService(mockLessonRepo.Object, mockModuleRepo.Object); //act lessonService.UpdateLessonGrade(0, 0.0d); //assert - test fails if no NullReferenceException is thrown }
public void UpdateLessonGrade_Test() { var lesson = new Lesson { LessonId = 12, Grade = 95.4, IsPassed = true }; var module = new Module { ModuleId = 1, MinimumPassingGrade = 93, Lessons = new List <Lesson> { new Lesson { LessonId = 12, Grade = 9.4, IsPassed = false } } }; var mockLessonRepo = new DynamicMock(typeof(ILessonRepository)); var mockModuleRepo = new DynamicMock(typeof(IModuleRepository)); mockLessonRepo.ExpectAndReturn("GetLesson", lesson); mockModuleRepo.GetModule("GetModule", module); var testLessonService = new LessonService(); var retLesson = testLessonService.UpdateLessonGrade(12, 100); Assert.AreEqual(100, retLesson.Grade); Assert.AreEqual(true, retLesson.IsPassed); }
public void IfGradeIsLessThanMinimumPassingGrade_IsPassedShouldBeFalse() { // Arrange var lessonRepository = A.Fake <ILessonRepository>(); var moduleRepository = A.Fake <IModuleRepository>(); var lesson = new Lesson { Grade = 1, IsPassed = false, LessonId = LessonId }; var module = new Module { ModuleId = 1, MinimumPassingGrade = 2, Lessons = new List <Lesson> { lesson } }; A.CallTo(() => lessonRepository.GetLesson(A <int> .Ignored)).Returns(lesson); A.CallTo(() => moduleRepository.GetModule(A <int> .Ignored)).Returns(module); var lessonService = new LessonService(lessonRepository, moduleRepository); // Act lessonService.UpdateLessonGrade(LessonId, Grade); // Assert Assert.Equal(Grade, lesson.Grade); Assert.False(lesson.IsPassed); }
public void UpdateLessonGradeShouldThrowNullExceptionWithInvalidLessonId() { var lessonService = new LessonService(); const int LESSON_ID = 5; // Invalid lesson ID const double LESSON_GRADE = 80.0; Assert.Throws <NullReferenceException>(() => lessonService.UpdateLessonGrade(LESSON_ID, LESSON_GRADE)); }
public void UpdateLessonGrade_Test() { LessonService lessonService = new LessonService(); bool passes = false; //Assert.IsTrue(lessonService.UpdateLessonGrade(12,23.4,out passes) == "Success" && !passes); //Assert.IsTrue(lessonService.UpdateLessonGrade(1, 23.4, out passes) == "Lesson not Found!" && !passes); Assert.IsTrue(lessonService.UpdateLessonGrade(12, 98.4, out passes) == "Success" && passes); }
public void UpdateLessonGradeShouldThrowNullExceptionWhenModuleDoesNotHaveGivenLessonId() { // This test proves that it is a bad idea to request a module using a lesson ID var lessonService = new LessonService(); const int LESSON_ID = 46; // Valid lesson ID, but is not found in a module; therefore, no module is returned const double LESSON_GRADE = 80.0; Assert.Throws <NullReferenceException>(() => lessonService.UpdateLessonGrade(LESSON_ID, LESSON_GRADE)); }
public static void Main(string[] args) { var lessonSvc = new LessonService(new LessonRepository(), new ModuleRepository()); var lessonId = 12; var grade = 98.2d; lessonSvc.UpdateLessonGrade(lessonId, grade); }
public static void Main(string[] args) { var lessonSvc = new LessonService(); var lessonId = 12; var grade = 98.2d; lessonSvc.UpdateLessonGrade(lessonId, grade); }
public void TestGradeFailed() { // Arrange var lessonSvc = new LessonService(); // Act lessonSvc.UpdateLessonGrade(12, 18.2d); // Assert Assert.IsFalse(lessonSvc._lessonRepo.GetLesson(12).IsPassed, "Test grade check failed for not"); }
public void UpdateLessonGrade_TestPassCodeBlock() { // Create Instance of LessonService Class var lessonService = new LessonService(); var lessonId = 12; var grade = 98.2d; lessonService.UpdateLessonGrade(lessonId, grade); Assert.IsTrue(true); }
public void TestGradePassed() { // Arrange var lessonSvc = new LessonService(); // Act //lessonSvc.UpdateLessonGrade(12, 98.2d); lessonSvc.UpdateLessonGrade(12, 98.2d); // Assert Assert.IsTrue(lessonSvc._lessonRepo.GetLesson(12).IsPassed, "Test grade check failed for passed condition"); }
public static void Main(string[] args) { var lessonSvc = new LessonService(); var lessonId = 12; var grade = 98.2d; bool passes = false; lessonSvc.UpdateLessonGrade(lessonId, grade, out passes); }
public void ThrowsException_IfLessonIsNotInModule() { // Arrange var lessonRepository = A.Fake <ILessonRepository>(); var moduleRepository = A.Fake <IModuleRepository>(); A.CallTo(() => moduleRepository.GetModule(A <int> .Ignored)).Returns(null); var lessonService = new LessonService(lessonRepository, moduleRepository); // Act, Assert Assert.Throws <NotFoundException>(() => lessonService.UpdateLessonGrade(LessonId, Grade)); }
public void UpdateLessonGrade_TestPassingGrade() { // Tests if UpdateLessonGrade handles passing valid Lesson ID with passing grade // NOTE: lesson collection does not exist outside of UpdateLessonGrade so no way to test persistent values var lessonSvc = new LessonService(); var lessonId = 12; var grade = 97.1d; lessonSvc.UpdateLessonGrade(lessonId, grade); Assert.IsTrue(true); }
public static void Main(string[] args) { //var keyword is ambiguous, prefer to specify the obejct type whenever possible for ease of reading purposes //mapping interfaces to repository classes ILessonRepository lessonRepo = new LessonRepository(); IModuleRepository moduleRepo = new ModuleRepository(); LessonService lessonSvc = new LessonService(lessonRepo, moduleRepo); int lessonId = 12; double grade = 98.2d; lessonSvc.UpdateLessonGrade(lessonId, grade); }
public void UpdateLessonGrade_Test() { // Arrange var lessonSvc = new LessonService(); // Act var grade = lessonSvc._lessonRepo.GetLesson(12).Grade; lessonSvc.UpdateLessonGrade(12, 98.2d); // Assert var gradeAfterUpdate = lessonSvc._lessonRepo.GetLesson(12).Grade; Assert.AreNotEqual(grade, gradeAfterUpdate, "failed to update grade."); }
public void UpdateLessonGradeShouldSetLessonToFailStatusIfGradeIsBelow80() { const int EXISTING_LESSON_ID = 86; const double PASSING_GRADE = 76; Lesson lesson = _lessonRepo.GetLesson(EXISTING_LESSON_ID); Assert.IsTrue(lesson.IsPassed, "The lesson's passed status was set somewhere else"); var lessonService = new LessonService(); lessonService.UpdateLessonGrade(EXISTING_LESSON_ID, PASSING_GRADE); Assert.IsFalse(lesson.IsPassed, "The lesson's passed status wasn't set correctly"); }
public void UpdateLessonGradeShouldSetLessonToPassStatusIfGradeIs80OrAbove() { const int EXISTING_LESSON_ID = 12; const double PASSING_GRADE = 85; // Let's make sure the lesson's pass status is set to false before we update it Lesson lesson = _lessonRepo.GetLesson(EXISTING_LESSON_ID); Assert.IsFalse(lesson.IsPassed, "The lesson's passed status was set somewhere else"); var lessonService = new LessonService(); lessonService.UpdateLessonGrade(EXISTING_LESSON_ID, PASSING_GRADE); Assert.IsTrue(lesson.IsPassed, "The lesson's passed status wasn't set correctly"); }
public static void Main(string[] args) { var lessonSvc = new LessonService(); var lessonId = 12; var grade = 98.2d; try { lessonSvc.UpdateLessonGrade(lessonId, grade); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void UpdateLessonGrade_Test() { // set up test vars int testLessonId = 12; double testGrade = 90.2d; bool expectedIsPassed = true; // a grade of 90.2 is passing for lesson 12 // perform the update on the lesson var lessonSvc = new LessonService(); lessonSvc.UpdateLessonGrade(testLessonId, testGrade); // get the updated lesson var lesson = lessonSvc.lessonRepo.GetLesson(testLessonId); // test if it worked by comparing the expected Assert.AreEqual(expectedIsPassed, lesson.IsPassed); }
public void UpdateLessonGrade_TestInvalidLesson() { // Tests if UpdateLessonGrade handles passing Lesson IDs that don't exist var lessonSvc = new LessonService(); var lessonId = 86; var grade = 53.2d; try { lessonSvc.UpdateLessonGrade(lessonId, grade); Assert.IsTrue(true); } catch { Assert.Fail(); } }
public void UpdateLessonGrade_NullModuleRepository() { //arrange Mock <ILessonRepository> mockLessonRepo = new Mock <ILessonRepository>(); mockLessonRepo.Setup(x => x.GetLesson(It.IsAny <int>())).Returns(new Lesson { LessonId = 0, Grade = 0.0d, IsPassed = false }); LessonService lessonService = new LessonService(mockLessonRepo.Object, null); //act lessonService.UpdateLessonGrade(0, 0.0d); //assert - test fails if no NullReferenceException is thrown }
public void UpdateLessonGrade_Test() { var moduleRepo = new ModuleRepository(); var lessonService = new LessonService(); var module = moduleRepo.GetModule(lessonId); var grade = new Random().Next(0, 100); var isPassing = module.MinimumPassingGrade <= grade; try { var updatedLesson = lessonService.UpdateLessonGrade(lessonId, grade); Assert.AreEqual(updatedLesson.Grade, grade); Assert.AreEqual(updatedLesson.IsPassed, isPassing); } catch (Exception e) { Console.WriteLine(e); } }
public void IfLessonIsNotInModule_GradeChanges() { // Arrange var lessonRepository = A.Fake <ILessonRepository>(); var moduleRepository = A.Fake <IModuleRepository>(); var lesson = new Lesson { Grade = 0, IsPassed = false, LessonId = LessonId }; A.CallTo(() => lessonRepository.GetLesson(A <int> .Ignored)).Returns(lesson); A.CallTo(() => moduleRepository.GetModule(A <int> .Ignored)).Returns(null); var lessonService = new LessonService(lessonRepository, moduleRepository); // Act Assert.Throws <NotFoundException>(() => lessonService.UpdateLessonGrade(LessonId, Grade)); // Assert Assert.Equal(Grade, lesson.Grade); }