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 )); }
private async Task <Result> TryUpdateCoursesAsync() { var updateDateTime = _dateTime.UtcNow; var courseUpdateResult = await _courseUpdater.TryUpdateAsync().ConfigureAwait(false); if (!courseUpdateResult.IsSuccessful) { ErrorMessage = courseUpdateResult.ErrorMessage; State = CourseListState.Error; return(courseUpdateResult); } _preferences.LastCourseUpdateCheck = updateDateTime; return(Result.Success); }