public void CreateLesson_InvalidModel_ThrowsInvalidLessonException() { ILessonModel lesson = new Lesson(); A.CallTo(() => _entityValidator.ValidateEntity(lesson)).Returns(new EntityValidationResult(false)); Assert.Throws<InvalidLessonException>(() => _lessonService.CreateLesson(lesson)); A.CallTo(() => _lessonRepository.CreateLesson(A<ILessonDto>.Ignored)).MustNotHaveHappened(); }
public void CreateLesson_ValidNonOverlappingModel_Created() { ILessonModel lesson = new Lesson(); A.CallTo(() => _entityValidator.ValidateEntity(lesson)).Returns(new EntityValidationResult(true)); A.CallTo(() => _lessonRepository.GetLessons()).Returns(Enumerable.Empty<ILessonDto>().AsQueryable()); _lessonService.CreateLesson(lesson); A.CallTo(() => _lessonRepository.CreateLesson(A<ILessonDto>.Ignored)).MustHaveHappened(); }
public void CreateLesson_ValidOverlappingModel_ThrowsOverlappingException() { var group = A.Fake<IGroupModel>(); A.CallTo(() => group.GroupId).Returns(2); ILessonModel lesson = new Lesson { Date = new DateTime(2014, 1, 1), Group = group }; var lessonDto = A.Fake<ILessonDto>(); A.CallTo(() => lessonDto.GroupId).Returns(2); A.CallTo(() => lessonDto.Date).Returns(new DateTime(2014, 1, 1)); A.CallTo(() => _entityValidator.ValidateEntity(lesson)).Returns(new EntityValidationResult(true)); A.CallTo(() => _lessonRepository.GetLessons()).Returns(new[] { lessonDto }.AsQueryable()); Assert.Throws<LessonDateOverlappingException>(() => _lessonService.CreateLesson(lesson)); A.CallTo(() => _lessonRepository.CreateLesson(A<ILessonDto>.Ignored)).MustNotHaveHappened(); }
public void UpdateLesson_NotExistingModel_ThrowEntityNotFoundException() { ILessonModel lesson = new Lesson { LessonId = 42 }; A.CallTo(() => _entityValidator.ValidateEntity(lesson)).Returns(new EntityValidationResult(true)); A.CallTo(() => _lessonRepository.GetLessons()).Returns(Enumerable.Empty<ILessonDto>().AsQueryable()); A.CallTo(() => _lessonRepository.GetLessonById(42)).Returns(null); Assert.Throws<EntityNotFoundException>(() => _lessonService.UpdateLesson(lesson)); A.CallTo(() => _lessonRepository.UpdateLesson(A<ILessonDto>.Ignored)).MustNotHaveHappened(); }
public void UpdateLesson_ExistingAndValidNonOverlappingModel_Updated() { ILessonModel lesson = new Lesson { LessonId = 42 }; A.CallTo(() => _entityValidator.ValidateEntity(lesson)).Returns(new EntityValidationResult(true)); A.CallTo(() => _lessonRepository.GetLessons()).Returns(Enumerable.Empty<ILessonDto>().AsQueryable()); A.CallTo(() => _lessonRepository.GetLessonById(42)).Returns(A.Dummy<ILessonDto>()); _lessonService.UpdateLesson(lesson); A.CallTo(() => _lessonRepository.UpdateLesson(A<ILessonDto>.Ignored)).MustHaveHappened(); }