public void GetLectureByExternalId_ReturnsNull_WhenLectureDoesntExist()
        {
            // Arrange
            List <Lecture> testLectures = new List <Lecture>
            {
                new Lecture {
                    ExternalId = 1, Id = 3123, Title = "Lecture 1"
                },
                new Lecture {
                    ExternalId = 2, Id = 4324, Title = "Lecture 2"
                }
            };

            IRepository <Lecture> repository = new RepositoryMock <Lecture>();

            testLectures.ForEach(lecture => repository.Add(lecture));

            ILecturesService service = SetupLecturesService(repository);

            int lectureId = 6;

            // Act
            Lecture returnedLecture = service.GetLectureByExternalId(lectureId);

            // Assert
            Assert.IsNull(returnedLecture);
        }
        public void GetLectureByExternalId_ThrowsArgumentOutOfRangeException_WhenLectureIdIsZero()
        {
            // Arrange
            ILecturesService service = SetupLecturesService();

            int lectureId = 0;

            // Act & Assert
            Assert.Throws <ArgumentOutOfRangeException>(() => service.GetLectureByExternalId(lectureId));
        }
        private void AddOrUpdateLecture(IEnumerable <IContent> content, Func <IContent, bool> isActive)
        {
            IContent lectureContent = content.FirstOrDefault(x => x.ContentType.Alias == nameof(DocumentTypes.Lecture));
            IContent moduleContent  = content.FirstOrDefault(x => x.ContentType.Alias == nameof(DocumentTypes.Module));

            if (lectureContent != null && lectureContent.HasIdentity)
            {
                ILecturesService lecturesService = DependencyResolver.Current.GetService(typeof(ILecturesService)) as ILecturesService;
                if (lecturesService == null)
                {
                    throw new InvalidOperationException("LecturesService failed to instantiate");
                }

                Lecture lecture = lecturesService.GetLectureByExternalId(lectureContent.Id);
                if (lecture == null)
                {
                    lecture = new Lecture
                    {
                        ExternalId = lectureContent.Id,
                        Title      = lectureContent.Name
                    };
                }

                IContent courseParentNode = lectureContent.Ancestors().FirstOrDefault(x => x.ContentType.Alias == nameof(DocumentTypes.Course));
                if (courseParentNode?.ContentType.Alias == nameof(DocumentTypes.Course))
                {
                    string courseId = (string)courseParentNode.Properties[(nameof(DocumentTypes.Course.CourseId))].Value;
                    if (string.IsNullOrWhiteSpace(courseId))
                    {
                        throw new ArgumentException($"Course with Id: {courseParentNode.Id} doesn't have a CourseId field present");
                    }

                    lecture.CourseId = int.Parse(courseId);
                }

                lecture.IsActive = isActive(lectureContent);
                lecturesService.AddOrUpdate(lecture);
            }
            else if (moduleContent != null)
            {
                ILecturesService lecturesService = DependencyResolver.Current.GetService(typeof(ILecturesService)) as ILecturesService;
                if (lecturesService == null)
                {
                    throw new InvalidOperationException("LecturesService failed to instantiate");
                }

                bool isModuleActive = isActive(moduleContent);
                foreach (IContent lect in moduleContent.Descendants().Where(x => x.ContentType.Alias == nameof(DocumentTypes.Lecture)))
                {
                    Lecture lecture = lecturesService.GetLectureByExternalId(lect.Id);
                    lecture.IsActive = isModuleActive && isActive(lect);
                    lecturesService.AddOrUpdate(lecture);
                }
            }
        }