Exemplo n.º 1
0
        public void GetStatementsDelegatedScope()
        {
            // Given
            RecognizedUserInfo recognizedUserInfo = RecognizedUserInfo.Current();
            DelegatedUserInfo  userCredentials    = GetDelegatedUserCredentials();
            IFluentClient      client             = AspenClient.Initialize(AppScope.Delegated)
                                                    .RoutingTo(this.delegatedAppInfoProvider)
                                                    .WithIdentity(this.delegatedAppInfoProvider)
                                                    .Authenticate(userCredentials)
                                                    .GetClient();

            // When
            var statements = client.Financial.GetStatements(recognizedUserInfo.AccountId).ToList();

            PrintOutput("Statements", statements);

            // Then
            Assert.That(statements.Count(), NUnit.Framework.Is.EqualTo(5));
            const string AccountTypesPattern = "^80|81|82|83|84|85$";

            foreach (var statement in statements)
            {
                Assert.That(statement.AccountTypeId, NUnit.Framework.Is.Not.Null.And.Match(AccountTypesPattern));
                Assert.That(statement.Amount, NUnit.Framework.Is.AssignableTo(typeof(decimal)));
                Assert.That(statement.CardAcceptor, NUnit.Framework.Is.Not.Null);
                Assert.That(statement.TranName, NUnit.Framework.Is.Not.Null);
                Assert.That(statement.TranType, NUnit.Framework.Is.Not.Null);
            }
        }
        public void ReedemTokenWithMissmatchedAmount()
        {
            this.userInfo        = GetDelegatedUserCredentials();
            this.delegatedClient = AspenClient.Initialize(AppScope.Delegated)
                                   .RoutingTo(this.delegatedAppInfoProvider)
                                   .WithIdentity(this.delegatedAppInfoProvider)
                                   .Authenticate(this.userInfo)
                                   .GetClient();

            this.autonomousClient = AspenClient.Initialize()
                                    .RoutingTo(this.autonomousAppInfoProvider)
                                    .WithIdentity(this.autonomousAppInfoProvider)
                                    .Authenticate(useCache: false)
                                    .GetClient();

            this.docType   = this.userInfo["DocType"].ToString();
            this.docNumber = this.userInfo["DocNumber"].ToString();
            int amount = new Random().Next(1, 10000);

            ITokenResponseInfo token1 = this.GetToken(amount: amount);

            this.ReeemTokenWithMissmatchedAmount(token1.Token, amount + 1);

            ITokenResponseInfo token2 = this.GetToken(amount: amount);

            this.ReeemTokenWithMissmatchedAmount(token2.Token, amount - 1);
        }
        public void ARecognizedCodeWorks()
        {
            DelegatedUserInfo userCredentials = GetDelegatedUserCredentials();
            IFluentClient     userClient      = AspenClient.Initialize(AppScope.Delegated)
                                                .RoutingTo(this.delegatedAppInfoProvider)
                                                .WithIdentity(this.delegatedAppInfoProvider)
                                                .Authenticate(userCredentials)
                                                .GetClient();

            var randomNickname = TestContext.CurrentContext.Random.GetString(10);
            var response       = userClient.CurrentUser.RequestActivationCode(randomNickname);

            IFluentClient appClient = AspenClient.Initialize()
                                      .RoutingTo(this.autonomousAppInfoProvider)
                                      .WithIdentity(this.autonomousAppInfoProvider)
                                      .Authenticate(useCache: false)
                                      .GetClient();

            // Estas pruebas solo sirven en el ambiente de desarrollo.
            // En otros ambientes esta operación no retorna el código generado.
            Assert.That(response.Code, NUnit.Framework.Is.Not.Null);
            void CodeValidatedSuccessfully() => appClient.Management.ValidateActivationCode(response.Code, randomNickname);

            Assert.DoesNotThrow(CodeValidatedSuccessfully);
        }
        public void PolicyAttemptsIsValidated()
        {
            // Este valor debe corresponder con la política definida para el ApiKey de la solicitud.
            int policyAttempts = 3;

            // Given
            DelegatedUserInfo userCredentials = GetDelegatedUserCredentials();
            IFluentClient     userClient      = AspenClient.Initialize(AppScope.Delegated)
                                                .RoutingTo(this.delegatedAppInfoProvider)
                                                .WithIdentity(this.delegatedAppInfoProvider)
                                                .Authenticate(userCredentials)
                                                .GetClient();

            // When
            string randomNickname = TestContext.CurrentContext.Random.GetString(10);

            // Agotar los intentos definidos en la política.
            for (int index = 1; index < policyAttempts; index++)
            {
                userClient.CurrentUser.RequestActivationCode(randomNickname);
            }

            void RequestCodeFailed() => userClient.CurrentUser.RequestActivationCode(randomNickname);

            AspenException exception = Assert.Throws <AspenException>(RequestCodeFailed);

            //Then
            Assert.That(exception, Is.ExpectedException(HttpStatusCode.ExpectationFailed, "15870", "Solicitud de código de activación inválida"));
            Assert.That(exception.Content["attempt"], NUnit.Framework.Is.EqualTo(policyAttempts));
            Assert.That(exception.Content["remainingTimeLapse"], NUnit.Framework.Is.GreaterThan(0));
        }
        public void XyZ()
        {
            DelegatedUserInfo userCredentials = GetDelegatedUserCredentials();
            IFluentClient     userClient      = AspenClient.Initialize(AppScope.Delegated)
                                                .RoutingTo(this.delegatedAppInfoProvider)
                                                .WithIdentity(this.delegatedAppInfoProvider)
                                                .Authenticate(userCredentials)
                                                .GetClient();

            string randomPinNumber = TestContext.CurrentContext.Random.GetDigits(6);
            var    response        = userClient.CurrentUser.RequestActivationCode();

            userClient.CurrentUser.SetPin(randomPinNumber, response.Code);
        }
        public void TokenLifeCycleWorks()
        {
            this.userInfo        = GetDelegatedUserCredentials();
            this.delegatedClient = AspenClient.Initialize(AppScope.Delegated)
                                   .RoutingTo(this.delegatedAppInfoProvider)
                                   .WithIdentity(this.delegatedAppInfoProvider)
                                   .Authenticate(this.userInfo)
                                   .GetClient();

            this.autonomousClient = AspenClient.Initialize()
                                    .RoutingTo(this.autonomousAppInfoProvider)
                                    .WithIdentity(this.autonomousAppInfoProvider)
                                    .Authenticate(useCache: false)
                                    .GetClient();

            this.docType   = this.userInfo["DocType"].ToString();
            this.docNumber = this.userInfo["DocNumber"].ToString();
            string metadata = Guid.NewGuid().ToString("B");
            int    amount   = new Random().Next(1, 10000);

            ITokenResponseInfo token1 = this.GetToken();

            this.RedeemToken(token1.Token, amount);

            ITokenResponseInfo token3 = this.GetToken(metadata, amount);

            this.RedeemTokenNoAmount(token3.Token);

            ITokenResponseInfo token4 = this.GetToken(metadata, amount);

            this.RedeemTokenNegativeAmount(token4.Token);

            int    accountTypesLength = 6;
            int    index       = new Random(Guid.NewGuid().GetHashCode()).Next(0, accountTypesLength);
            string accountType = Enumerable.Range(80, accountTypesLength).ToList()[index].ToString();

            ITokenResponseInfo token5 = this.GetToken(metadata, amount, accountType);

            this.RedeemToken(token5.Token, amount, metadata, accountType);

            ITokenResponseInfo token6 = this.GetToken(null, amount, accountType);

            this.ReeemTokenWithMissmatchedAccountType(token6.Token, amount);

            ITokenResponseInfo token7 = this.GetToken();

            this.ReeemTokenWithInvalidDocType(token7.Token);
        }
Exemplo n.º 7
0
        public void GetBalancesDelegatedScope()
        {
            // Given
            RecognizedUserInfo recognizedUserInfo = RecognizedUserInfo.Current();
            DelegatedUserInfo  userCredentials    = GetDelegatedUserCredentials();
            IFluentClient      client             = AspenClient.Initialize(AppScope.Delegated)
                                                    .RoutingTo(this.delegatedAppInfoProvider)
                                                    .WithIdentity(this.delegatedAppInfoProvider)
                                                    .Authenticate(userCredentials)
                                                    .GetClient();

            // When
            List <IBalanceInfo> balances = client.Financial.GetBalances(recognizedUserInfo.AccountId).ToList();

            // Then
            Assert.That(balances.Count(), NUnit.Framework.Is.EqualTo(5));
        }
        public void PinNumberRequiresAllInputs()
        {
            // Given
            DelegatedUserInfo userCredentials = GetDelegatedUserCredentials();
            IFluentClient     client          = AspenClient.Initialize(AppScope.Delegated)
                                                .RoutingTo(this.delegatedAppInfoProvider)
                                                .WithIdentity(this.delegatedAppInfoProvider)
                                                .Authenticate(userCredentials)
                                                .GetClient();

            // When
            void NotAcceptable() => client.CurrentUser.SetPin(null, null);

            AspenException exception = Assert.Throws <AspenException>(NotAcceptable);

            // Then
            Assert.That(exception, Is.ExpectedException(HttpStatusCode.NotAcceptable, "15860", "no puede ser nulo ni vacío"));
        }
        public void PinNumberLengthMustBeRecognized()
        {
            // Given
            DelegatedUserInfo userCredentials = GetDelegatedUserCredentials();
            IFluentClient     client          = AspenClient.Initialize(AppScope.Delegated)
                                                .RoutingTo(this.delegatedAppInfoProvider)
                                                .WithIdentity(this.delegatedAppInfoProvider)
                                                .Authenticate(userCredentials)
                                                .GetClient();
            // When
            string tooLongPinNumber = TestContext.CurrentContext.Random.GetDigits(7);

            void PinNotAcceptable() => client.CurrentUser.SetPin(tooLongPinNumber, "123456");

            AspenException exception = Assert.Throws <AspenException>(PinNotAcceptable);

            // Then
            Assert.That(exception, Is.ExpectedException(HttpStatusCode.NotAcceptable, "15860", "Pin es muy largo o muy corto"));
        }
        public void InvalidCodeDoesNotWorks()
        {
            // Given
            DelegatedUserInfo userCredentials = GetDelegatedUserCredentials();
            IFluentClient     userClient      = AspenClient.Initialize(AppScope.Delegated)
                                                .RoutingTo(this.delegatedAppInfoProvider)
                                                .WithIdentity(this.delegatedAppInfoProvider)
                                                .Authenticate(userCredentials)
                                                .GetClient();

            IFluentClient appClient = AspenClient.Initialize()
                                      .RoutingTo(this.autonomousAppInfoProvider)
                                      .WithIdentity(this.autonomousAppInfoProvider)
                                      .Authenticate(useCache: false)
                                      .GetClient();

            // When
            var randomNickname = TestContext.CurrentContext.Random.GetString(10);

            // Esta prueba puede funcionar o no, dependiendo del sistema para envió de SMS.
            // Por eso se hacen aserciones en diferentes escenarios.
            try
            {
                var response = userClient.CurrentUser.RequestActivationCode(randomNickname);
                // Estas pruebas solo sirven en el ambiente de desarrollo.
                // En otros ambientes esta operación no retorna el código generado.
                Assert.That(response.Code, NUnit.Framework.Is.Not.Null);
                var randomCode = TestContext.CurrentContext.Random.GetDigits(6);
                appClient.Management.ValidateActivationCode(randomCode, randomNickname);
            }
            catch (AspenException exception) when(exception.EventId == "20100")
            {
                Assert.That(exception, Is.ExpectedException(HttpStatusCode.ServiceUnavailable, message: "No fue posible enviar el mensaje"));
            }
            catch (AspenException exception) when(exception.EventId == "15868")
            {
                Assert.That(exception, Is.ExpectedException(HttpStatusCode.ExpectationFailed, message: "Código de activación o identificador es invalido"));
                Assert.That(exception.Content["currentAttempt"], NUnit.Framework.Is.GreaterThan(0));
                Assert.That(exception.Content["successful"], NUnit.Framework.Is.EqualTo(false));
            }
        }
        public void PinNumberCannotBeConsecutiveDescending()
        {
            // Given
            DelegatedUserInfo userCredentials = GetDelegatedUserCredentials();
            IFluentClient     client          = AspenClient.Initialize(AppScope.Delegated)
                                                .RoutingTo(this.delegatedAppInfoProvider)
                                                .WithIdentity(this.delegatedAppInfoProvider)
                                                .Authenticate(userCredentials)
                                                .GetClient();

            // When
            const string InvalidPinNumber     = "654321";
            string       randomActivationCode = TestContext.CurrentContext.Random.GetDigits(6);

            void NotAcceptable() => client.CurrentUser.SetPin(InvalidPinNumber, randomActivationCode);

            AspenException exception = Assert.Throws <AspenException>(NotAcceptable);

            // Then
            Assert.That(exception, Is.ExpectedException(HttpStatusCode.NotAcceptable, "15860", "Utilice caracteres que no sean consecutivos"));
        }
        public void RequestAnActivationCodeWorks()
        {
            // Given
            DelegatedUserInfo userCredentials = GetDelegatedUserCredentials();
            IFluentClient     userClient      = AspenClient.Initialize(AppScope.Delegated)
                                                .RoutingTo(this.delegatedAppInfoProvider)
                                                .WithIdentity(this.delegatedAppInfoProvider)
                                                .Authenticate(userCredentials)
                                                .GetClient();

            ServiceController sc = new ServiceController("Processa.Services.Aspen.Host.Dev");
            //sc.ExecuteCommand(129);

            // When

            // Estas pruebas solo sirven en el ambiente de desarrollo.
            // En otros ambientes esta operación no retorna el código generado.
            var randomNickname = TestContext.CurrentContext.Random.GetString(10);

            // Esta prueba puede funcionar o no, dependiendo del sistema para envió de SMS.
            // Por eso se hacen aserciones en diferentes escenarios.
            try
            {
                var activationCode = userClient.CurrentUser.RequestActivationCode(randomNickname);
                PrintOutput("Code", activationCode);
                Assert.That(activationCode.Code, NUnit.Framework.Is.Not.Null);
                Assert.That(activationCode.Successful, NUnit.Framework.Is.EqualTo(true));
                Assert.That(activationCode.TimeLapseMinutes, NUnit.Framework.Is.GreaterThanOrEqualTo(0));
                Assert.That(activationCode.Nickname, NUnit.Framework.Is.EqualTo(randomNickname));

                string pinNumber = "161616";
                Assert.DoesNotThrow(() => userClient.CurrentUser.SetPin(pinNumber, activationCode.Code, randomNickname));
            }
            catch (AspenException exception)
            {
                Assert.That(exception, Is.ExpectedException(HttpStatusCode.ServiceUnavailable, "20100", "No fue posible enviar el mensaje"));
            }
        }
        public void PinNumberUnknown()
        {
            // Given
            DelegatedUserInfo userCredentials = GetDelegatedUserCredentials();
            IFluentClient     client          = AspenClient.Initialize(AppScope.Delegated)
                                                .RoutingTo(this.delegatedAppInfoProvider)
                                                .WithIdentity(this.delegatedAppInfoProvider)
                                                .Authenticate(userCredentials)
                                                .GetClient();

            // When
            // PinNumber que cumple con TODAS las políticas de validaciones.
            const string WellFormedPinNumber  = "741269";
            string       randomActivationCode = TestContext.CurrentContext.Random.GetDigits(6);

            void ExpectationFailed() => client.CurrentUser.SetPin(WellFormedPinNumber, randomActivationCode);

            AspenException exception = Assert.Throws <AspenException>(ExpectationFailed);

            // Then
            Assert.That(exception, Is.ExpectedException(HttpStatusCode.ExpectationFailed, "15868", "No se encontró una invitación"));
            Assert.That(exception.Content["remainingTimeLapse"], NUnit.Framework.Is.Null);
        }
Exemplo n.º 14
0
        public void GetAccountsDelegatedScope()
        {
            // Given
            DelegatedUserInfo userCredentials = GetDelegatedUserCredentials();
            IFluentClient     client          = AspenClient.Initialize(AppScope.Delegated)
                                                .RoutingTo(this.delegatedAppInfoProvider)
                                                .WithIdentity(this.delegatedAppInfoProvider)
                                                .Authenticate(userCredentials)
                                                .GetClient();

            // When
            List <IAccountInfo> accounts = client.Financial.GetAccounts().ToList();

            // Then
            Assert.That(accounts.Count(), NUnit.Framework.Is.EqualTo(1));
            List <AccountProperty> properties = accounts.First().Properties.ToList();

            Assert.That(properties.Count(), NUnit.Framework.Is.EqualTo(4));
            Assert.That(properties.SingleOrDefault(p => p.Key == "LastTranName"), NUnit.Framework.Is.Not.Null);
            Assert.That(properties.SingleOrDefault(p => p.Key == "LastTranDate"), NUnit.Framework.Is.Not.Null);
            Assert.That(properties.SingleOrDefault(p => p.Key == "LastTranCardAcceptor"), NUnit.Framework.Is.Not.Null);
            Assert.That(properties.SingleOrDefault(p => p.Key == "CardStatusName"), NUnit.Framework.Is.Not.Null);
        }
        public void ReedemTokenWithMissmatchedMetadata()
        {
            this.userInfo        = GetDelegatedUserCredentials();
            this.delegatedClient = AspenClient.Initialize(AppScope.Delegated)
                                   .RoutingTo(this.delegatedAppInfoProvider)
                                   .WithIdentity(this.delegatedAppInfoProvider)
                                   .Authenticate(this.userInfo)
                                   .GetClient();

            this.autonomousClient = AspenClient.Initialize()
                                    .RoutingTo(this.autonomousAppInfoProvider)
                                    .WithIdentity(this.autonomousAppInfoProvider)
                                    .Authenticate(useCache: false)
                                    .GetClient();

            this.docType   = this.userInfo["DocType"].ToString();
            this.docNumber = this.userInfo["DocNumber"].ToString();
            string metadata = Guid.NewGuid().ToString("B");
            var    amount   = new Random().Next(1, 10000);

            ITokenResponseInfo token = this.GetToken(metadata);

            this.ReeemTokenWithMissmatchedMetadata(token.Token, amount);
        }