public async Task Conductor_ConductWithTests() { var root = new Conductor <StateScreen> .Collection.AllActive(); var child1 = new StateScreen { DisplayName = "screen1" }; var child2 = new StateScreen(TimeSpan.FromSeconds(3)) { DisplayName = "screen2" }; var child3 = new StateScreen() { DisplayName = "screen3" }; root.Items.Add(child1); root.Items.Add(child2); root.Items.Add(child3); await ScreenExtensions.TryActivateAsync(root).ConfigureAwait(false); await ScreenExtensions.TryDeactivateAsync(root, true).ConfigureAwait(false); Assert.True(child1.IsClosed, "child 1 should be closed"); Assert.True(child2.IsClosed, "child 2 should be closed"); Assert.True(child3.IsClosed, "child 3 should be closed"); }
public async Task Screen_ConductWithTests() { var root = new Screen(); var child1 = new StateScreen { DisplayName = "screen1" }; // simulate a long deactivation process var child2 = new StateScreen(TimeSpan.FromSeconds(3)) { DisplayName = "screen2" }; var child3 = new StateScreen() { DisplayName = "screen3" }; child1.ConductWith(root); child2.ConductWith(root); child3.ConductWith(root); await ScreenExtensions.TryActivateAsync(root).ConfigureAwait(false); await ScreenExtensions.TryDeactivateAsync(root, true).ConfigureAwait(false); Assert.True(child1.IsClosed, "child 1 should be closed"); Assert.True(child2.IsClosed, "child 2 should be closed"); Assert.True(child3.IsClosed, "child 3 should be closed"); }
private static void SetDPIState() { // do this early to avoid changing the image popup try { Logger.Instance().Log("Major Version Number:", Environment.OSVersion.Version.Major.ToString(), true); Logger.Instance().Log("Minor Version Number:", Environment.OSVersion.Version.Minor.ToString(), true); if (Environment.OSVersion.Version.Major > 6 || (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor >= 3)) { Logger.Instance().Log("DPI Awareness", "Display settings: Major >6 Settings PerMonitor DPI Aware", true); ScreenExtensions.ProcessDPIAwareness awareness; ScreenExtensions.GetProcessDpiAwareness(Process.GetCurrentProcess().Handle, out awareness); Logger.Instance().Log("DPI", "DPI Awareness equals: " + awareness.ToString(), true); ScreenExtensions.SetProcessDpiAwareness(ScreenExtensions.ProcessDPIAwareness.ProcessPerMonitorDPIAware); } } catch (Exception e)//this exception occures if OS does not implement this API, just ignore it. { Logger.Instance().Log("Dpiaware", "OS does not support DPI Settings: Exception:" + e, true); } try { ScreenExtensions.ProcessDPIAwareness awareness2; ScreenExtensions.GetProcessDpiAwareness(Process.GetCurrentProcess().Handle, out awareness2); Logger.Instance().Log("DPI", "DPI Awareness After Setting equals: " + awareness2.ToString(), true); } catch { } }
public void TryCloseClosesIScreenState() { var screen = new Mock <IScreenState>(); ScreenExtensions.TryClose(screen.Object); screen.Verify(x => x.Close()); }
public void FilterScenario() { var viewModel = new PostListViewModel(navigationMock.Object, service.Object, progressBarMock.Object, windowmanager.Object, backgroundLoader.Object); ScreenExtensions.TryActivate(viewModel); viewModel.SearchText = "3"; Assert.IsTrue(viewModel.OriginList.Count == 5); Assert.IsTrue(viewModel.PostList.Count == 1); viewModel.SearchText = " "; Assert.IsTrue(viewModel.PostList.Count == 5); viewModel.SearchText = string.Empty; Assert.IsTrue(viewModel.PostList.Count == 5); viewModel.SearchText = "abc"; Assert.IsTrue(viewModel.PostList.Count == 2); viewModel.SearchText = "777"; Assert.IsTrue(viewModel.PostList.Count == 1); viewModel.SearchText = "5"; Assert.IsTrue(viewModel.PostList.Count == 1); }
/// <summary> /// Changes the active item. /// </summary> /// <param name="newItem">The new item to activate.</param> /// <param name="closePrevious">Indicates whether or not to close the previous active item.</param> protected virtual void ChangeActiveItem(object newItem, bool closePrevious) { ScreenExtensions.TryDeactivate(ActiveItem, closePrevious); if (ActiveItem != null && closePrevious) { var activescreen = ActiveItem as PersitableScreen; if ((activescreen != null) && _viewModels.ContainsValue(activescreen)) { _viewModels.Remove(activescreen.UriString); } } var screen = newItem as PersitableScreen; if (screen != null) { newItem = EnsureItem(screen); } if (IsActive) { ScreenExtensions.TryActivate(newItem); } _activeItem = newItem; NotifyOfPropertyChange("ActiveItem"); OnActivationProcessed(_activeItem, true); }
public void Run_update_after_configure() { restore = true; settings.LastUpdate = null; settings.UserName = null; settings.Password = null; session.Flush(); shell.Reload(); manager.DialogOpened.OfType <SettingsViewModel>().Subscribe(m => { ScreenExtensions.TryActivate(m); m.Settings.Value.UserName = "******"; m.Settings.Value.Password = "******"; var results = m.Save().ToList(); Deactivate(m); Close(m); }); shell.StartCheck(); Assert.That(shell.Settings.Value.UserName, Is.Not.Null); Assert.That(shell.Settings.Value.Password, Is.Not.Null); Assert.That(manager.MessageBoxes[0], Does.Contain("необходимо заполнить учетные данные")); Assert.That(manager.MessageBoxes[1], Does.Contain("База данных программы не заполнена")); Assert.That(manager.MessageBoxes[2], Does.Contain("Обновление завершено успешно")); Assert.That(command, Is.InstanceOf <UpdateCommand>()); }
public void TryDeactivateDeactivatesIScreenState() { var screen = new Mock <IScreenState>(); ScreenExtensions.TryDeactivate(screen.Object); screen.Verify(x => x.Deactivate()); }
public void TryDisposeDisposesIDisposable() { var screen = new Mock <IDisposable>(); ScreenExtensions.TryDispose(screen.Object); screen.Verify(x => x.Dispose()); }
public override void ActivateItem(T item) { if (item != null && item.Equals(ActiveItem)) { if (IsActive) { ScreenExtensions.TryActivate(item); OnActivationProcessed(item, true); } return; } CloseStrategy.Execute(new[] { ActiveItem }, (canClose, items) => { if (canClose) { ChangeActiveItem(item, true); } else { OnActivationProcessed(item, false); } }); }
public void Rebuild_address() { var model = new OrdersViewModel(); var addresses = new[] { new Address("Тестовый адрес доставки 1") { Id = 1 }, new Address("Тестовый адрес доставки 2") { Id = 2 }, }; Activate(model, addresses); model.AddressSelector.All.Value = true; model.AddressSelector.Addresses[1].IsSelected = false; ScreenExtensions.TryDeactivate(model, true); model = new OrdersViewModel(); addresses = new[] { new Address("Тестовый адрес доставки 1") { Id = 2 }, new Address("Тестовый адрес доставки 3") { Id = 3 }, }; Activate(model, addresses); Assert.IsTrue(model.AddressSelector.All.Value); Assert.IsFalse(model.AddressSelector.Addresses[0].IsSelected); Assert.IsTrue(model.AddressSelector.Addresses[1].IsSelected); }
public override void Dispose() { ScreenExtensions.TryDispose(rootViewModel); container?.Dispose(); base.Dispose(); }
/// <inheritdoc /> protected override void OnDeactivate(bool close) { Module.Deactivate(close); ScreenExtensions.TryDeactivate(CurrentWorkspace, close); base.OnDeactivate(close); }
protected override void OnStart(object rootObject) { var shell = (ShellViewModel)rootObject; StructureHelper.SetRootObject(shell); ScreenExtensions.TryActivate(shell); ScreenExtensions.TryActivate(StructureHelper.GetLogin()); }
public override void Dispose() { ScreenExtensions.TryDispose(this._rootViewModel); if (this.container != null) this.container.Dispose(); base.Dispose(); }
public void TitleWithoutFileEndsWithUntitled() { var sut = new TitleBarViewModel(_shell, _eventAggregatorMock.Object); ScreenExtensions.TryActivate(sut); Assert.That(sut.Title, Does.EndWith("untitled").IgnoreCase); ScreenExtensions.TryDeactivate(sut, close: true); }
protected override void OnDeactivate(bool close) { ScreenExtensions.TryDeactivate(ChildWindow, close); base.OnDeactivate(close); // ReSharper disable DelegateSubtraction UserContext.CurrentChanged -= CurrentChanged; // ReSharper restore DelegateSubtraction }
public void OnInitializeLoadsCredentials() { credentials.Setup(c => c.GetCredentialsAsync()).ReturnsAsync(new Credentials("acc", "tok")); ScreenExtensions.TryActivate(loginViewModel); Assert.Equal("acc", loginViewModel.Account); Assert.Equal("tok", loginViewModel.Token); }
public void ApplicationIconIsNotNull() { var titleBar = new TitleBarViewModel(_shell, _eventAggregatorMock.Object); var sut = new MainWindowViewModel(_shell, titleBar, CreateResourceManager().Object); ScreenExtensions.TryActivate(sut); Assert.That(sut.Icon, Is.Not.Null); ScreenExtensions.TryDeactivate(sut, close: true); }
public override void Dispose() { base.Dispose(); ScreenExtensions.TryDispose(_rootViewModel); if (Kernel != null) { Kernel.Dispose(); } }
public void Initialize() { _dataServiceMock = CreateDataServiceMock(); _windowManagerMock = new Mock <IWindowManager>(); _eventAggregatorMock = CreateEventAggregatorMock(); _viewModelFactoryMock = CreateViewModelFactoryMock(); Subject = CreateSut(); ScreenExtensions.TryActivate(Subject); }
public async Task ActivateAsync(object activationArgs) { if (IsInteractive(activationArgs)) { // Initialize services that you need before app activation // take into account that the splash screen is shown while this code runs. await InitializeAsync(); // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (Window.Current.Content == null) { // Create a Shell or Frame to act as the navigation context if (_shell?.Value == null) { var frame = new Frame(); NavigationService = _container.RegisterNavigationService(frame); Window.Current.Content = frame; } else { var viewModel = ViewModelLocator.LocateForView(_shell.Value); ViewModelBinder.Bind(viewModel, _shell.Value, null); ScreenExtensions.TryActivate(viewModel); NavigationService = _container.GetInstance <INavigationService>(); Window.Current.Content = _shell?.Value; } } } var activationHandler = GetActivationHandlers() .FirstOrDefault(h => h.CanHandle(activationArgs)); if (activationHandler != null) { await activationHandler.HandleAsync(activationArgs); } if (IsInteractive(activationArgs)) { var defaultHandler = new DefaultActivationHandler(_defaultNavItem, NavigationService); if (defaultHandler.CanHandle(activationArgs)) { await defaultHandler.HandleAsync(activationArgs); } // Ensure the current window is active Window.Current.Activate(); // Tasks after activation await StartupAsync(); } }
public override void Dispose() { ScreenExtensions.TryDispose(_rootViewModel); if (_container != null) { _container.Dispose(); } base.Dispose(); }
public override void Dispose() { ScreenExtensions.TryDispose(this._rootViewModel); if (this.kernel != null) { this.kernel.Dispose(); } base.Dispose(); }
public void SolveWithValidModelReturnsSuccessStatus() { var sut = CreateValidWorkspace(); ScreenExtensions.TryActivate(sut); var actualStatus = sut.SolveModel(); Assert.That(actualStatus.IsSuccess, Is.True); ScreenExtensions.TryDeactivate(sut, true); }
public override void Dispose() { base.Dispose(); ScreenExtensions.TryDispose(this._rootViewModel); if (this.serviceProvider != null) { this.serviceProvider.Dispose(); } }
public async Task ActivateAsync(object activationArgs) { if (IsInteractive(activationArgs)) { // Initialize things like registering background task before the app is loaded await InitializeAsync(); // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (Window.Current.Content == null) { // Create a Frame to act as the navigation context and navigate to the first page if (_shell?.Value == null) { var frame = new Frame(); NavigationService = _container.RegisterNavigationService(frame); Window.Current.Content = frame; } else { var viewModel = ViewModelLocator.LocateForView(_shell.Value); ViewModelBinder.Bind(viewModel, _shell.Value, null); ScreenExtensions.TryActivate(viewModel); NavigationService = _container.GetInstance <INavigationService>(); Window.Current.Content = _shell?.Value; } } } var activationHandler = GetActivationHandlers() .FirstOrDefault(h => h.CanHandle(activationArgs)); if (activationHandler != null) { await activationHandler.HandleAsync(activationArgs); } if (IsInteractive(activationArgs)) { var defaultHandler = new DefaultLaunchActivationHandler(_defaultNavItem, NavigationService); if (defaultHandler.CanHandle(activationArgs)) { await defaultHandler.HandleAsync(activationArgs); } // Ensure the current window is active Window.Current.Activate(); // Tasks after activation await StartupAsync(); } }
public void Initialize() { _documentManagerMock = CreateDocumentManagerMock(); _dataServiceMock = CreateDataServiceMock(); _windowManagerMock = new Mock <IWindowManager>(); _eventAggregatorMock = CreateEventAggregatorMock(); _viewModelFactoryMock = CreateViewModelFactoryMock(); _workspaceLoader = new Mock <IWorkspaceLoader>(); Shell = CreateSut(); ScreenExtensions.TryActivate(Shell); }
public void ShouldTryLoadingEmailAndNews() { var windowManagerMock = new Mock <IMetroWindowManager>(); windowManagerMock.Setup(x => x.ShowProgressAndDoAsync(It.IsAny <Func <Task> >())); var viewModel = new HomeViewModel(accountServiceEmptyMock.Object, newsServiceEmptyMock.Object, windowManagerMock.Object); ScreenExtensions.TryActivate(viewModel); windowManagerMock.Verify(x => x.ShowProgressAndDoAsync(It.IsAny <Func <Task> >()), Times.Once); }
/// <summary> /// Called when deactivating. /// </summary> /// <param name="close">Inidicates whether this instance will be closed.</param> protected override void OnDeactivate(bool close) { if (close) { items.OfType <IDeactivate>().Apply(x => x.Deactivate(true)); items.Clear(); } else { ScreenExtensions.TryDeactivate(ActiveItem, false); } }