private static CourseListViewModel CreateViewModel( ICourseUpdater courseUpdater = null, ICourseRepository repository = null, IPreferencesUtility preferences = null, IDateTimeUtility dateTime = null, IDbConnection dbConnection = null, ISecureStorageUtility secureStorage = null, IBackgroundSyncUtility backgroundSync = null, IMessenger messenger = null ) { if (courseUpdater == null) { courseUpdater = Substitute.For <ICourseUpdater>(); courseUpdater.TryUpdateAsync().Returns( Task.FromResult(Result.WithSuccess(new CourseUpdateInfo(true))) ); } if (repository == null) { repository = Substitute.For <ICourseRepository>(); repository.All().Returns(new Course[0]); } var utcNow = DateTime.UtcNow; if (dateTime == null) { dateTime = Substitute.For <IDateTimeUtility>(); dateTime.UtcNow.Returns(utcNow); } if (preferences == null) { preferences = Substitute.For <IPreferencesUtility>(); preferences.LastCourseUpdateCheck.CompareTo(utcNow.AddMinutes(-30)); } dbConnection = dbConnection ?? Substitute.For <IDbConnection>(); secureStorage = secureStorage ?? Substitute.For <ISecureStorageUtility>(); backgroundSync = backgroundSync ?? Substitute.For <IBackgroundSyncUtility>(); messenger = messenger ?? Substitute.For <IMessenger>(); return(new CourseListViewModel( courseUpdater, repository, preferences, dateTime, dbConnection, secureStorage, backgroundSync, messenger )); }
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; }
public CourseListViewModel( ICourseUpdater courseUpdater, ICourseRepository repository, IPreferencesUtility preferences, IDateTimeUtility dateTime, IDbConnection dbConnection, ISecureStorageUtility secureStorage, IBackgroundSyncUtility backgroundSync, IMessenger messenger ) { _courseUpdater = courseUpdater; _repository = repository; _preferences = preferences; _dateTime = dateTime; _dbConnection = dbConnection; _secureStorage = secureStorage; _backgroundSync = backgroundSync; _messenger = messenger; Courses = new CourseListItem[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 )); }