public void Delete_RemoveItem(UniverseSources source) { var universe = Universe(source); var property = new AsyncProperty(universe.Properties().Create("")); Assert.IsTrue(universe.Properties().Any()); property.Delete(); Assert.IsFalse(universe.Properties().Any()); }
public async Task TestRefreshCommand_AwaitsCurrentProject() { _objectUnderTest.RefreshCommand.Execute(null); AsyncProperty asyncProperty = _objectUnderTest.RefreshCommand.LatestExecution; Assert.IsFalse(asyncProperty.IsCompleted); _currentProjectSource.SetResult(new Project()); await asyncProperty; Assert.IsTrue(asyncProperty.IsCompleted); }
public async Task TestOnTaskComplete_SetsValueToResult() { const string defaultObject = "default"; const string resultObject = "result"; var objectUnderTest = new AsyncProperty <object>(_tcs.Task, defaultObject); _tcs.SetResult(resultObject); await objectUnderTest.SafeTask; Assert.AreEqual(resultObject, objectUnderTest.Value); }
/// <summary> /// Send request to get logs following prior requests. /// </summary> public void LoadNextPage() { IsAutoReloadChecked = false; if (string.IsNullOrWhiteSpace(_nextPageToken) || string.IsNullOrWhiteSpace(Project) || AsyncAction.IsPending) { return; } AsyncAction = new AsyncProperty(LoadLogsAsync()); }
public async Task TestOnTaskComplete_KeepsValueDefaultOnException() { var defaultObject = new object(); var objectUnderTest = new AsyncProperty <object>(_tcs.Task, defaultObject); _tcs.SetException(new Exception()); await objectUnderTest.SafeTask; Assert.AreEqual(defaultObject, objectUnderTest.Value); }
private void StartLoadProjects() { if (CredentialsStore.Default.CurrentAccount != null) { LoadTask = AsyncPropertyUtils.CreateAsyncProperty(LoadProjectsAsync()); } else { LoadTask = null; } }
public async Task TestCreate_SetsResultantValue() { const string expectedResult = "Expected Result"; AsyncProperty <string> result = AsyncProperty.Create( Task.FromResult(new object()), o => expectedResult); await result.SafeTask; Assert.AreEqual(expectedResult, result.Value); }
public void TestSelectProjectCommand_SkipsUpdatesWhenCanceled() { AsyncProperty <Project> originalCurrentProjectProperty = _objectUnderTest.CurrentProjectAsync; _userPromptServiceMock.Setup(p => p.PromptUser(It.IsAny <PickProjectIdWindowContent>())) .Returns(() => null); _objectUnderTest.SelectProjectCommand.Execute(null); _credentialsStoreMock.Verify(cs => cs.UpdateCurrentProject(It.IsAny <Project>()), Times.Never); Assert.AreEqual(originalCurrentProjectProperty, _objectUnderTest.CurrentProjectAsync); }
public async Task EditName_Execute(UniverseSources source) { var property = new AsyncProperty(Universe(source).Properties().Create("")); var command = new EditPropertyValue(property); var value = "Test2"; Assert.IsTrue(command.CanExecute(value)); await command.ExecuteAsync(value); Assert.AreEqual(value, property.Value()); }
public void TestInvalidateAllPropertiesEmptyAccountName() { CredentialStoreMock.SetupGet(cs => cs.CurrentAccount) .Returns(new UserAccount { AccountName = "" }); AsyncProperty oldAction = _objectUnderTest.AsyncAction; _objectUnderTest.InvalidateAllProperties(); Assert.AreEqual(oldAction, _objectUnderTest.AsyncAction); }
private void GetCurrentGame() { Thread.Sleep(20000); CurrentGameInfo = new Task <RiotAPI.CurrentGameAPI.CurrentGameInfo>(() => { try { return(RiotAPI.CurrentGameAPI.BySummoner("NA1", Account.SummonerID)); } catch (Exception x) { Log("Failed to get game data: " + x); return(null); } }); }
public CategoryStatsViewModel(IUseCase <CategoryDuration> categoryDurationUseCase, IUseCase <String, DailyCategoryDuration> dailyCategoryDurationUseCase, Mediator mediator) { this.categoryDurationUseCase = categoryDurationUseCase; this.dailyCategoryDurationUseCase = dailyCategoryDurationUseCase; this.mediator = mediator; categoryList = new TaskRunner <IEnumerable <CategoryDuration> >(categoryDurationUseCase.Get, this); dailyCategoryList = new TaskRunner <IEnumerable <DailyCategoryDuration> >(GetDailyCategories, this); this.mediator.Register(MediatorMessages.REFRESH_LOGS, new Action(ReloadAll)); }
public UserStatsViewModel(IUseCase <UserLoggedTime> userLoggedTimeUseCase, IUseCase <String, UsageOverview> usageOverviewUseCase, Mediator mediator) { this.userLoggedTimeUseCase = userLoggedTimeUseCase; this.usageOverviewUseCase = usageOverviewUseCase; this.mediator = mediator; usersList = new TaskRunner <IEnumerable <UserLoggedTime> >(userLoggedTimeUseCase.Get, this); dailyUsageList = new TaskRunner <IEnumerable <UsageOverview> >(GetSubContent, this); this.mediator.Register(MediatorMessages.REFRESH_LOGS, new Action(ReloadAll)); }
public AppStatsViewModel(IUseCase <AppDuration> appDurationUseCase, IUseCase <String, DailyAppDuration> dailyAppDurationUseCase, Mediator mediator) { this.appDurationUseCase = appDurationUseCase; this.dailyAppDurationUseCase = dailyAppDurationUseCase; this.mediator = mediator; appsList = new TaskRunner <IEnumerable <AppDuration> >(appDurationUseCase.Get, this); dailyAppList = new TaskRunner <IEnumerable <DailyAppDuration> >(GetDailyApp, this); this.mediator.Register(MediatorMessages.REFRESH_LOGS, new Action(ReloadAll)); }
public async Task DeleteAsync_InvokePropertyDeleted(UniverseSources source) { var universe = Universe(source); var property = new AsyncProperty(universe.Properties().Create("")); var eventInvoked = false; property.PropertyDeleted += (sender, args) => { eventInvoked = true; }; await property.DeleteAsync(); Assert.IsTrue(eventInvoked); Assert.IsFalse(universe.Properties().Any()); }
public ScreenshotsStatsViewModel(IUseCase <ScreenshotOverview> screenshotModelUseCase, IUseCase <String, DailyScreenshotModel> dailyScreenshotModelUseCase, Mediator mediator) { this.screenshotModelUseCase = screenshotModelUseCase; this.dailyScreenshotModelUseCase = dailyScreenshotModelUseCase; this.mediator = mediator; screenshotList = new TaskRunner <IEnumerable <ScreenshotOverview> >(screenshotModelUseCase.Get, this); dailyScreenshotsList = new TaskRunner <IEnumerable <DailyScreenshotModel> >(GetDailyScreenshots, this); this.mediator.Register(MediatorMessages.REFRESH_LOGS, new Action(ReloadAll)); }
private void StartLoadProjects() { if (CredentialsStore.Default.CurrentAccount != null) { LoadTask = new AsyncProperty(LoadProjectsAsync()); HasAccount = true; } else { LoadTask = null; HasAccount = false; } }
public async Task ChangeAsync_InvokePropertyChanged(UniverseSources source) { var property = new AsyncProperty(Universe(source).Properties().Create("")); var eventInvoked = false; property.PropertyChanged += (sender, args) => { eventInvoked = true; }; var value = "Test"; await property.ChangeAsync(value); Assert.IsTrue(eventInvoked); Assert.AreEqual(value, property.Value()); }
public ScreenshotsViewModel(IAppSettingsService settingsService, IScreenshotService screenshotService, IWindowService windowService, Mediator mediator) { this.settingsService = settingsService; this.screenshotService = screenshotService; this.windowService = windowService; this.mediator = mediator; logList = new TaskObserver <IEnumerable <ScreenshotModel> >(screenshotService.GetAsync, this, OnScreenshotGet); this.mediator.Register(MediatorMessages.REFRESH_LOGS, new Action(logList.Reload)); }
public async Task TestValue_RaisesPropertyChangedWhenSet() { const string defaultObject = "default"; const string resultObject = "result"; var objectUnderTest = new AsyncProperty <object>(_tcs.Task, defaultObject); var changedProperties = new List <string>(); objectUnderTest.PropertyChanged += (sender, args) => changedProperties.Add(args.PropertyName); _tcs.SetResult(resultObject); await objectUnderTest.SafeTask; CollectionAssert.Contains(changedProperties, nameof(objectUnderTest.Value)); }
static void Main(string[] args) { UseMyInterfaceAsync(new MyAsyncClass()).Wait(); var factory = MyAsyncClassFactory.createAsync().Result; Console.WriteLine(factory); var funType = new MyFundamentalType(); funType.Initialisation.Wait(); Console.WriteLine(funType); var data = new AsyncProperty().Data.GetValue(); Console.WriteLine(data); }
private void UpdateUserProfile() { if (_plusDataSource.Value != null) { var profileTask = _plusDataSource.Value.GetProfileAsync(); ProfilePictureAsync = AsyncPropertyUtils.CreateAsyncProperty(profileTask, x => x?.Image.Url); ProfileNameAsync = AsyncPropertyUtils.CreateAsyncProperty( profileTask, x => x?.Emails.FirstOrDefault()?.Value, Resources.CloudExplorerLoadingMessage); } else { ProfilePictureAsync = null; ProfileNameAsync = new AsyncProperty <string>(Resources.CloudExplorerSelectAccountMessage); } }
/// <summary> /// This method uses similar logic as populating resource descriptors. /// Refers to <seealso cref="PopulateResourceTypesAsync"/>. /// </summary> private async Task PopulateLogIdsAsync() { if (ResourceTypeSelector.SelectedMenuItem == null) { Debug.WriteLine("Code bug, _selectedMenuItem should not be null."); return; } CancellationTokenSource = null; var item = ResourceTypeSelector.SelectedMenuItem as ResourceValueItemViewModel; List <string> keys = item == null ? null : new List <string> { item.ResourceValue }; IList <string> logIdRequestResult = await DataSource.ListProjectLogNamesAsync(ResourceTypeSelector.SelectedTypeNmae, keys); LogIdList = new LogIdsList(logIdRequestResult); LogIdList.PropertyChanged += (sender, args) => AsyncAction = new AsyncProperty(ReloadAsync()); }
/// <summary> /// Send an advanced filter to Logs Viewer and display the results. /// </summary> /// <param name="advancedSearchText">The advance filter in text format.</param> public void FilterLog(string advancedSearchText) { IsAutoReloadChecked = false; if (string.IsNullOrWhiteSpace(advancedSearchText)) { return; } ShowAdvancedFilter = true; var filter = new StringBuilder(); filter.AppendLine(advancedSearchText); if (!advancedSearchText.ToLowerInvariant().Contains("timestamp")) { filter.AppendLine($"timestamp<=\"{DateTime.UtcNow.AddDays(1):O}\""); } AdvancedFilterText = filter.ToString(); AsyncAction = new AsyncProperty(ReloadAsync()); }
public AppDetailsViewModel(IUseCaseAsync <AppModel> appUseCase, IUseCase <String, Int32, AppSummary> appSummaryUseCase, IUseCase <String, IEnumerable <DateTime>, WindowSummary> windowSummaryUseCase, IUseCase <String, IEnumerable <String>, IEnumerable <DateTime>, WindowDurationOverview> windowDurationUseCase, Mediator mediator) { this.appUseCase = appUseCase; this.appSummaryUseCase = appSummaryUseCase; this.windowSummaryUseCase = windowSummaryUseCase; this.windowDurationUseCase = windowDurationUseCase; this.mediator = mediator; appList = new TaskObserver <IEnumerable <AppModel> >(appUseCase.GetAsync, this); appSummaryList = new TaskRunner <IEnumerable <AppSummary> >(GetAppSummary, this); windowSummaryList = new TaskRunner <IEnumerable <WindowSummary> >(GetWindowSummary, this); windowDurationList = new TaskRunner <IEnumerable <WindowDurationOverview> >(GetWindowDuration, this); this.mediator.Register(MediatorMessages.APPLICATION_ADDED, new Action <Aplication>(ApplicationAdded)); this.mediator.Register(MediatorMessages.REFRESH_LOGS, new Action(ReloadAll)); }
public async Task TestTarget_UnregistersOnPropertyChanged() { var oldPropertySource = new TaskCompletionSource <string>(); var newPropertySource = new TaskCompletionSource <string>(); _objectUnderTest.CanceledContent = ExpectedContent; _objectUnderTest.SuccessContent = new object(); var oldProperty = new AsyncProperty(oldPropertySource.Task); var newProperty = new AsyncProperty(newPropertySource.Task); _objectUnderTest.Target = oldProperty; _objectUnderTest.Target = newProperty; newPropertySource.SetCanceled(); await _objectUnderTest.Target; oldPropertySource.SetResult(""); await oldProperty; Assert.AreEqual(ExpectedContent, _objectUnderTest.Content); }
public AppxFilesViewModel( string packageFile, IAppxFileViewer fileViewer, FileInvoker fileInvoker) : base(packageFile) { this.fileViewer = fileViewer; this.fileInvoker = fileInvoker; var rootContainersTask = this.GetRootContainers(); var nodesCollection = new ObservableCollection <AppxFileViewModel>(); this.Nodes = nodesCollection; this.View = new DelegateCommand(this.OnView); var containers = new AsyncProperty <IList <AppxDirectoryViewModel> >(); this.Containers = containers; #pragma warning disable 4014 containers.Loaded += this.OnContainersLoaded; containers.Load(rootContainersTask); #pragma warning restore 4014 }
public DaySummaryViewModel(IUseCase <DateTime, LogSummary> logSummaryUseCase, IUseCase <DateTime, AppSummary> appSummaryUseCase, IUseCase <String, DateTime, WindowSummary> windowSummaryUseCase, IUseCase <DateTime, UsageByTime> usageByTimeUseCase, IUseCase <DateTime, CategoryDuration> categoryDurationUseCase, Mediator mediator) { this.logSummaryUseCase = logSummaryUseCase; this.appSummaryUseCase = appSummaryUseCase; this.windowSummaryUseCase = windowSummaryUseCase; this.usageByTimeUseCase = usageByTimeUseCase; this.categoryDurationUseCase = categoryDurationUseCase; this.mediator = mediator; logsList = new TaskRunner <IEnumerable <LogSummary> >(GetLogSummary, this); appsList = new TaskRunner <IEnumerable <AppSummary> >(GetAppsSummary, this); usageList = new TaskRunner <IEnumerable <UsageByTime> >(GetUsageSummary, this); windowsList = new TaskRunner <IEnumerable <WindowSummary> >(GetWindowsSummary, this); categoryList = new TaskRunner <IEnumerable <CategoryDuration> >(GetCategories, this); this.mediator.Register(MediatorMessages.REFRESH_LOGS, new Action(ReloadContent)); }
/// <summary> /// Initializes an instance of <seealso cref="LogsViewerViewModel"/> class. /// </summary> /// <param name="toolWindowIdNumber"></param> public LogsViewerViewModel(int toolWindowIdNumber) { IsVisibleUnbound = true; _package = GoogleCloudExtensionPackage.Instance; _toolWindowIdNumber = toolWindowIdNumber; RefreshCommand = new ProtectedCommand(OnRefreshCommand); LogItemCollection = new ListCollectionView(_logs); LogItemCollection.GroupDescriptions.Add(new PropertyGroupDescription(nameof(LogItem.Date))); CancelRequestCommand = new ProtectedCommand(CancelRequest); SimpleTextSearchCommand = new ProtectedCommand(() => { EventsReporterWrapper.ReportEvent(LogsViewerSimpleTextSearchEvent.Create()); AsyncAction = new AsyncProperty(ReloadAsync()); }); FilterSwitchCommand = new ProtectedCommand(SwapFilter); SubmitAdvancedFilterCommand = new ProtectedCommand(() => { EventsReporterWrapper.ReportEvent(LogsViewerAdvancedFilterEvent.Create()); AsyncAction = new AsyncProperty(ReloadAsync()); }); AdvancedFilterHelpCommand = new ProtectedCommand(ShowAdvancedFilterHelp); DateTimePickerModel = new DateTimePickerViewModel( TimeZoneInfo.Local, DateTime.UtcNow, isDescendingOrder: true); DateTimePickerModel.DateTimeFilterChange += (sender, e) => AsyncAction = new AsyncProperty(ReloadAsync()); ResourceTypeSelector = new ResourceTypeMenuViewModel(() => DataSource); ResourceTypeSelector.PropertyChanged += (sender, args) => { if (args.PropertyName == null || args.PropertyName == nameof(ResourceTypeMenuViewModel.SelectedMenuItem)) { LogIdList = null; AsyncAction = new AsyncProperty(ReloadAsync()); } }; OnDetailTreeNodeFilterCommand = new ProtectedAsyncCommand <ObjectNodeTree>(FilterOnTreeNodeValueAsync); OnAutoReloadCommand = new ProtectedCommand(AutoReload); }
public UserAccountViewModel(IUserAccount userAccount) { UserAccount = userAccount; AccountName = userAccount.AccountName; Task <Person> personTask; try { IDataSourceFactory dataSourceFactory = DataSourceFactory.Default; IGPlusDataSource dataSource = dataSourceFactory.CreatePlusDataSource(userAccount.GetGoogleCredential()); personTask = dataSource.GetProfileAsync(); } catch (Exception) { personTask = Task.FromResult <Person>(null); } // TODO: Show the default image while it is being loaded. ProfilePictureAsync = AsyncProperty.Create(personTask, x => x?.Image.Url); NameAsync = AsyncProperty.Create(personTask, x => x?.DisplayName, Resources.UiLoadingMessage); }