Inheritance: ILessonModel
Esempio n. 1
0
 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();
 }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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();
        }