public void GetUserInfo_WhenExecucted_SetInteractionToSuccess()
        {
            var wascalled = false;

            _viewModel.FinishInteraction = () => wascalled = true;
            _dropboxService.GetDropUserInfo().Returns(new DropboxUserInfo()
            {
                AccessToken = "", AccountId = "", AccountInfo = ""
            });
            _viewModel.SetAccessTokenAndUserInfo(new Uri(redirectUri));
            Assert.IsTrue(_interaction.Success);
            Assert.IsTrue(wascalled);
        }
Exemplo n.º 2
0
        public void SetAccessTokenAndUserInfo(Uri eUri)
        {
            // if url doesnt start with redirecturl that means that current url for recieveing token isn't reach yet
            if (eUri.ToString().StartsWith(_dropboxData.RedirectUri, StringComparison.OrdinalIgnoreCase) == false)
            {
                return;
            }

            try
            {
                var accessToken       = _dropboxService.ParseAccessToken(eUri);
                var currentUserInfo   = _dropboxService.GetDropUserInfo(accessToken);
                var newDropboxAccount = new DropboxAccount
                {
                    AccessToken = currentUserInfo.AccessToken,
                    AccountInfo = currentUserInfo.AccountInfo,
                    AccountId   = currentUserInfo.AccountId
                };
                Interaction.DropboxAccount = newDropboxAccount;
                Interaction.Result         = DropboxAccountInteractionResult.Success;
            }
            catch (ArgumentException)
            {
                Interaction.Result = DropboxAccountInteractionResult.AccesTokenParsingError;
                _logger.Warn("Cannot parse dropbox access token. New Account can't be created.");
            }
            catch (Exception e)
            {
                Interaction.Result = DropboxAccountInteractionResult.Error;
                _logger.Warn($"Unexpected exception during determination of dropbox token.{Environment.NewLine}{e}");
            }

            FinishInteraction();
        }
        public async Task <DropboxUserInfo> GetDropboxUserInfo()
        {
            try
            {
                var token = await GetDropboxToken();

                var tokenEndpointDecoded = JsonConvert.DeserializeObject <Dictionary <string, string> >(token);
                var dbUserInfo           = _dropboxService.GetDropUserInfo(tokenEndpointDecoded["access_token"]);
                return(dbUserInfo);
            }
            catch (DropboxAuthException ex)
            {
                _logger.Error(ex, "An error in DropboxUserInfoManager occured.");
                throw;
            }
        }
        public void SetAccessTokenAndUserInfo_ArgumentUriIsRedirectUrl_ParseAccessTokenBeforeGetDropUserInfo()
        {
            var redirectUri = new Uri(_redirectUri + "/SomethingSomethingDarkSide");

            _viewModel.FinishInteraction = () => { };
            _dropboxService.GetDropUserInfo(Arg.Any <string>()).Returns(new DropboxUserInfo());

            _viewModel.SetAccessTokenAndUserInfo(redirectUri);

            Received.InOrder(() =>
            {
                var accessToken = _dropboxService.ParseAccessToken(redirectUri);
                _dropboxService.GetDropUserInfo(accessToken);
            });
        }
        public void SetAccessTokenAndUserInfo(Uri eUri)
        {
            // if url doesnt start with redirecturl that means that current url for recieveing token isn't reach yet
            if (eUri.ToString().StartsWith(_dropboxData.RedirectUri, StringComparison.OrdinalIgnoreCase) == false)
            {
                return;
            }

            try
            {
                _dropboxService.ParseAccessToken(eUri);
                var currentUserInfo = _dropboxService.GetDropUserInfo();
                Interaction.AccessToken = currentUserInfo.AccessToken;
                Interaction.AccountInfo = currentUserInfo.AccountInfo;
                Interaction.AccountId   = currentUserInfo.AccountId;
                RefreshBrowser          = true;
                Interaction.Success     = true;
            }
            catch (ArgumentException)
            {
                _logger.Info("Cannot parse access token.");
            }
            FinishInteraction();
        }