Exemple #1
0
        public virtual Tuple <LanguageCloudIdentityApiModel, string> StudioSignIn()
        {
            if (LanguageCloudIdentityApi == null)
            {
                return(new Tuple <LanguageCloudIdentityApiModel, string>(null, string.Empty));
            }

            var success = LanguageCloudIdentityApi.TryLogin(out var message);

            if (success)
            {
                var model = new LanguageCloudIdentityApiModel
                {
                    AccessToken          = LanguageCloudIdentityApi.AccessToken,
                    ActiveAccountId      = LanguageCloudIdentityApi.ActiveAccountId,
                    ActiveUserId         = LanguageCloudIdentityApi.ActiveUserId,
                    ActiveTenantId       = LanguageCloudIdentityApi.ActiveTenantId,
                    ApiKey               = LanguageCloudIdentityApi.ApiKey,
                    StudioApplicationKey = LanguageCloudIdentityApi.StudioApplicationKey,
                    StudioClientId       = LanguageCloudIdentityApi.StudioClientId,
                    AccountName          = LanguageCloudIdentityApi.LanguageCloudCredential?.AccountName,
                    Email = LanguageCloudIdentityApi.LanguageCloudCredential?.Email,
                };

                return(new Tuple <LanguageCloudIdentityApiModel, string>(model, message));
            }

            return(new Tuple <LanguageCloudIdentityApiModel, string>(null, message));
        }
Exemple #2
0
        public void SignInCommand_CredentialIsValid_ReturnsTrue(Authentication.AuthenticationType type)
        {
            var credential = _common.GetDefaultCredential(type);

            var connectionService = Substitute.For <Service.ConnectionService>(null, null, null);

            connectionService.Credential.Returns(credential);


            if (type == Authentication.AuthenticationType.Studio)
            {
                connectionService.IsValidStudioCredential(out Arg.Any <string>()).Returns(x =>
                {
                    x[0] = "Credential is not valid!";
                    return(false);
                });

                var languageCloudIdentityApiModel = new LanguageCloudIdentityApiModel
                {
                    AccessToken = credential.Token,
                    Email       = credential.Name
                };
                connectionService.StudioSignIn()
                .Returns(new Tuple <LanguageCloudIdentityApiModel, string>(languageCloudIdentityApiModel, string.Empty));
            }
            else
            {
                var authorizationResponse = new AuthorizationResponse
                {
                    AccessToken = credential.Token
                };
                connectionService.SignIn(Arg.Any <string>(), Arg.Any <string>())
                .Returns(Task.FromResult(new Tuple <AuthorizationResponse, string>(authorizationResponse, string.Empty)));
            }

            var userDetails = new UserDetails
            {
                AccountId = 0123,
                UserId    = type != Authentication.AuthenticationType.Client ? "abc123" : null,
                ClientId  = type == Authentication.AuthenticationType.Client ? "abc123" : null,
            };

            connectionService.GetUserDetails(Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(new Tuple <UserDetails, string>(userDetails, string.Empty)));

            var model = Substitute.For <CredentialsViewModel>(null, connectionService);

            Assert.False(model.IsSignedIn, "Expected: 'False' Found: 'True'");

            model.SignInCommand.Execute(null);
            Assert.True(model.IsSignedIn, "Expected: 'True' Found: 'False'");
        }
        public void Connect_CredentialIsInvalidAndAttemptConnection_ReturnsFalse(Authentication.AuthenticationType type)
        {
            var credential = _common.GetDefaultCredential(type);

            credential.ValidTo = DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0, 0, 0));

            var connectionService = Substitute.For <Service.ConnectionService>(null, null, null);

            connectionService.Credential.Returns(credential);

            if (type == Authentication.AuthenticationType.Studio)
            {
                connectionService.IsValidStudioCredential(out Arg.Any <string>()).Returns(x =>
                {
                    x[0] = "Credential has expired";
                    return(false);
                });

                var languageCloudIdentityApiModel = new LanguageCloudIdentityApiModel
                {
                    AccessToken = string.Empty,
                    Email       = string.Empty
                };
                connectionService.StudioSignIn()
                .Returns((languageCloudIdentityApiModel, "Invalid Credentials!"));
            }
            else
            {
                var authorizationResponse = new AuthorizationResponse
                {
                    AccessToken = string.Empty
                };
                connectionService.SignIn(Arg.Any <string>(), Arg.Any <string>())
                .Returns(Task.FromResult((authorizationResponse, "Invalid Credentials!")));
            }

            var userDetails = new UserDetails
            {
                AccountId = 0123,
                UserId    = type != Authentication.AuthenticationType.Client ? "abc123" : null,
                ClientId  = type == Authentication.AuthenticationType.Client ? "abc123" : null,
            };

            connectionService.GetUserDetails(Arg.Any <string>())
            .Returns(Task.FromResult((userDetails, string.Empty)));

            var result = connectionService.Connect(credential);

            Assert.False(result.Item1, "Expected value: false");
        }
        public void Connect_CredentialIsValid_ReturnsTrue(Authentication.AuthenticationType type)
        {
            var credential = _common.GetDefaultCredential(type);

            var connectionService = Substitute.For <Service.ConnectionService>(null, null, null);

            connectionService.Credential.Returns(credential);

            if (type == Authentication.AuthenticationType.Studio)
            {
                connectionService.IsValidStudioCredential(out Arg.Any <string>()).Returns(x =>
                {
                    x[0] = string.Empty;
                    return(true);
                });

                var languageCloudIdentityApiModel = new LanguageCloudIdentityApiModel
                {
                    AccessToken = credential.Token,
                    Email       = credential.Name
                };
                connectionService.StudioSignIn().Returns((languageCloudIdentityApiModel, string.Empty));

                var userDetails = new UserDetails
                {
                    AccountId = 0123,
                    UserId    = "abc123",
                    ClientId  = null
                };
                connectionService.GetUserDetails(Arg.Any <string>()).Returns(
                    Task.FromResult((userDetails, string.Empty)));
            }

            var result = connectionService.Connect(credential);

            Assert.True(result.Item1, "Expected value: true");
        }