protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); //very important line for dialog before startup ShutdownMode = ShutdownMode.OnExplicitShutdown; StartupInit(); bool startApplication = true; if (LoginWndVm.IsPasswordDefined()) { LoginWnd dlg = new LoginWnd(); bool? result = dlg.ShowDialog(); startApplication = result.HasValue && result.Value; } if (startApplication) { StartupUri = new Uri("Views/MainWindow.xaml", UriKind.Relative); } else { _log.Error("Wrong password"); // wrong password Shutdown(1); } }
public void GivenAFailureOfLogin_TheIsProcessingStatusShouldBackToFalseAnyway() { var vm = new LoginWndVm(_clientFactory, _credentialPersist) { UserName = "******", Password = "******" }; var changeCount = 0; vm.PropertyChanged += (sender, args) => { if (args.PropertyName == PropertyName.Get((LoginWndVm v) => v.IsProcessing)) { changeCount++; } }; _clientFactory.When(x => x.Login(Arg.Any <string>(), Arg.Any <string>())).Do(x => { throw new Exception(); }); Assert.Throws <Exception>(async() => { await vm.Login(); }); _clientFactory.Received(1).Login(vm.UserName, vm.Password).IgnoreAsyncWarning(); Assert.That(changeCount, Is.EqualTo(2), "IsProcessing should be changed twice, first it's changed to busy, and then back to false."); Assert.False(vm.IsProcessing, "Status should back to non-busy"); }
public LoginWnd() { InitializeComponent(); _viewModel = DataContext as LoginWndVm; _viewModel.LoadCredential(); Loaded += LoginWnd_Loaded; }
public async void CanLogin() { var vm = new LoginWndVm(_clientFactory, _credentialPersist) { UserName = "******", Password = "******" }; await vm.Login(); _clientFactory.Received(1).Login(vm.UserName, vm.Password).IgnoreAsyncWarning(); }
public void GivenAFailedLogin_NoCredentialShouldBeSaved() { var vm = new LoginWndVm(_clientFactory, _credentialPersist) { UserName = "******", Password = "******" }; _clientFactory.When(x => x.Login(Arg.Any <string>(), Arg.Any <string>())).Do(x => { throw new Exception(); }); Assert.Throws <Exception>(async() => { await vm.Login(); }); _credentialPersist.DidNotReceive().Save(Arg.Any <LoginCredential>()); }
public void GivenAEmptyUserName_NoNeedToSaveCredential() { var vm = new LoginWndVm(_clientFactory, _credentialPersist) { UserName = "" }; vm.SaveCredential(); _credentialPersist.DidNotReceive().Save(Arg.Any <LoginCredential>()); vm = new LoginWndVm(_clientFactory, _credentialPersist) { UserName = null }; vm.SaveCredential(); _credentialPersist.DidNotReceive().Save(Arg.Any <LoginCredential>()); }
public void GivenAnEmptyCredential_ShouldntBePopulated() { var vm = new LoginWndVm(_clientFactory, _credentialPersist) { UserName = "", Password = "" }; var expectedCredential = new LoginCredential() { UserName = "", Password = "" }; _credentialPersist.Load().Returns(expectedCredential); vm.LoadCredential(); _credentialPersist.Received(1).Load(); Assert.IsEmpty(vm.UserName); Assert.IsEmpty(vm.Password); }
public void CanLoadCredential() { var vm = new LoginWndVm(_clientFactory, _credentialPersist) { UserName = "", Password = "" }; var expectedCredential = new LoginCredential() { UserName = "******", Password = "******" }; _credentialPersist.Load().Returns(expectedCredential); vm.LoadCredential(); _credentialPersist.Received(1).Load(); Assert.That(vm.UserName, Is.EqualTo(expectedCredential.UserName)); Assert.That(vm.Password, Is.EqualTo(expectedCredential.Password)); }
public async void ShouldChangeTheIsProcessingStatusWhenLogin() { var vm = new LoginWndVm(_clientFactory, _credentialPersist) { UserName = "******", Password = "******" }; var changeCount = 0; vm.PropertyChanged += (sender, args) => { if (args.PropertyName == PropertyName.Get((LoginWndVm v) => v.IsProcessing)) { changeCount++; } }; await vm.Login(); _clientFactory.Received(1).Login(vm.UserName, vm.Password).IgnoreAsyncWarning(); Assert.That(changeCount, Is.EqualTo(2), "IsProcessing should be changed twice, first it's changed to busy, and then back to false."); Assert.False(vm.IsProcessing, "Status should back to non-busy"); }
public LoginWnd() { _viewModel = new LoginWndVm(); DataContext = _viewModel; InitializeComponent(); }