Пример #1
0
 public CourseUpdater(
     ICoursePageHtmlDownloader downloader,
     ICoursePageHtmlParser parser,
     ICourseSetComparer comparer,
     ICourseRepository repository,
     IUnitOfWork unitOfWork,
     IDateTimeUtility dateTime,
     IPreferencesUtility preferences
     )
 {
     _downloader  = downloader;
     _parser      = parser;
     _comparer    = comparer;
     _repository  = repository;
     _unitOfWork  = unitOfWork;
     _dateTime    = dateTime;
     _preferences = preferences;
 }
Пример #2
0
        private static CourseUpdater CreateCourseUpdater(
            ICoursePageHtmlDownloader downloader = null,
            ICoursePageHtmlParser parser         = null,
            ICourseSetComparer comparer          = null,
            ICourseRepository repository         = null,
            IUnitOfWork unitOfWork          = null,
            IDateTimeUtility dateTime       = null,
            IPreferencesUtility preferences = null
            )
        {
            if (downloader == null)
            {
                downloader = Substitute.For <ICoursePageHtmlDownloader>();

                downloader.TryDownloadCoursePageHtmlAsync(Arg.Any <string>())
                .Returns(Task.FromResult(Result.WithSuccess <string>()));
            }

            if (parser == null)
            {
                parser = Substitute.For <ICoursePageHtmlParser>();

                parser.TryParseCoursePage(Arg.Any <string>())
                .Returns(Result.WithSuccess(new RawCourse[0]));
            }

            if (repository == null)
            {
                repository = Substitute.For <ICourseRepository>();
                repository.All().Returns(new Course[0]);
            }

            if (unitOfWork == null)
            {
                unitOfWork = Substitute.For <IUnitOfWork>();

                var session = Substitute.For <IUnitOfWorkSession>();
                unitOfWork.OpenSession().Returns(session);

                session.Commit().Returns(Result.Success);
            }

            if (dateTime == null)
            {
                dateTime = Substitute.For <IDateTimeUtility>();
                dateTime.UtcNow.Returns(DateTime.UtcNow);
            }

            comparer    = comparer ?? new CourseSetComparer();
            preferences = preferences ?? Substitute.For <IPreferencesUtility>();

            return(new CourseUpdater(
                       downloader,
                       parser,
                       comparer,
                       repository,
                       unitOfWork,
                       dateTime,
                       preferences
                       ));
        }