コード例 #1
0
        private static LoginViewModel CreateSut(
            IHudUtility hudUtility                   = null,
            IAlertUtility alertUtility               = null,
            ICredentialStorage credentialStorage     = null,
            ICredentialValidator credentialValidator = null,
            IBackgroundSyncUtility backgroundSync    = null
            )
        {
            if (credentialValidator == null)
            {
                credentialValidator = Substitute.For <ICredentialValidator>();

                credentialValidator.ValidateAsync(Arg.Any <Credentials>())
                .Returns(Task.FromResult(Result.Success));
            }

            if (credentialStorage == null)
            {
                credentialStorage = Substitute.For <ICredentialStorage>();

                credentialStorage.SaveCredentialsAsync(Arg.Any <Credentials>())
                .Returns(Task.FromResult(Result.Success));
            }

            return(new LoginViewModel(
                       credentialValidator,
                       credentialStorage,
                       hudUtility ?? Substitute.For <IHudUtility>(),
                       alertUtility ?? Substitute.For <IAlertUtility>(),
                       backgroundSync ?? Substitute.For <IBackgroundSyncUtility>()
                       ));
        }
コード例 #2
0
ファイル: LoginViewModel.cs プロジェクト: aspnetde/IUBH.TOR
        internal async Task SignInAsync()
        {
            try
            {
                IsBusy = true;

                _hud.Show(LoginMessage);

                var credentials = new Credentials(UserName, Password);

                Result validationResult = await _credentialValidator.ValidateAsync(credentials)
                                          .ConfigureAwait(false);

                if (!validationResult.IsSuccessful)
                {
                    _alerts.ShowError(validationResult.ErrorMessage);
                    return;
                }

                var saveResult = await _credentialStorage.SaveCredentialsAsync(credentials)
                                 .ConfigureAwait(false);

                if (!saveResult.IsSuccessful)
                {
                    _alerts.ShowError(saveResult.ErrorMessage);
                    return;
                }

                _backgroundSync.Enable();

                SignedIn?.Invoke(this, EventArgs.Empty);
            }
            finally
            {
                _hud.Dismiss();

                IsBusy = false;
            }
        }