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 GivenReedemTokenWhenAmountIsInvalidThenAnExceptionIsThrows() { IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); void ValidateSingleUseTokenAvoidingValidation(object amount) => ((AspenClient)client.Financial).ValidateSingleUseTokenAvoidingValidation("CC", "52080323", "000000", accountType: "80", amount: amount); // Cuando se establece vacío, la serialización lo interpreta como nulo AspenException exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(string.Empty)); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'Amount' no puede ser nulo ni vacío"); // Valor menor a cero... exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(-1)); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'Amount' debe ser mayor que cero"); // Valor menor a cero... exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation("-1")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'Amount' debe ser mayor que cero"); // Cuando no es un valor entero falla por serialización. exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(" ")); AssertAspenResponseException( exception, "15883", HttpStatusCode.BadRequest, @"Valor inesperado al analizar los datos de solicitud en formato JSON"); // Cuando no es un valor entero falla por serialización. exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation("XXX")); AssertAspenResponseException( exception, "15883", HttpStatusCode.BadRequest, @"Valor inesperado al analizar los datos de solicitud en formato JSON"); // Cuando no es un valor entero falla por serialización. exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation("10000000000000000")); AssertAspenResponseException( exception, "15883", HttpStatusCode.BadRequest, @"Valor inesperado al analizar los datos de solicitud en formato JSON"); }
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 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 GetAccountsAutonomousScope() { // Given RecognizedUserInfo recognizedUserInfo = RecognizedUserInfo.Current(); IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); // When List <IAccountInfo> accounts = client.Financial.GetAccounts(recognizedUserInfo.DocType, recognizedUserInfo.DocNumber).ToList(); PrintOutput("Accounts", accounts); // 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); }
/// <summary> /// Sends a POST request using specified fluent builder as an asynchronous operation. /// </summary> /// <param name="fluentClient">The <see cref="IFluentClient"/> used to send request.</param> /// <param name="builder">The fluent builder factory.</param> /// <returns>The task object representing the asynchronous operation.</returns> /// <exception cref="ArgumentNullException"><paramref name="fluentClient" /> or <paramref name="builder" /> is <see langword="null" />.</exception> public static async Task <HttpResponseMessage> PostAsync(this IFluentClient fluentClient, Action <FormBuilder> builder) { if (fluentClient == null) { throw new ArgumentNullException(nameof(fluentClient)); } if (builder == null) { throw new ArgumentNullException(nameof(builder)); } var httpClient = fluentClient.HttpClient; var requestMessage = new HttpRequestMessage(HttpMethod.Post, httpClient.BaseAddress); requestMessage.SetContentSerializer(fluentClient.ContentSerializer); var fluentBuilder = new FormBuilder(requestMessage); builder(fluentBuilder); var response = await FluentDispatcher.SendAsync(httpClient, requestMessage).ConfigureAwait(false); return(response); }
public void GetStatementsAutonomousScope() { // Given RecognizedUserInfo recognizedUserInfo = RecognizedUserInfo.Current(); IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); // When var statements = client.Financial.GetStatements(recognizedUserInfo.DocType, recognizedUserInfo.DocNumber, 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 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 GetAccountsByAliasRecognizedUser() { IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); string channelId = "94ED400D-5D26-4160-A3AA-EC45A2B4AD39"; string enrollmentAlias = "386034126"; IEnumerable <IAccountInfo> response = client.Financial.GetAccountsByAlias(channelId, enrollmentAlias); CollectionAssert.IsEmpty(response); }
public void GetStatementsByAliasRecognizedUser() { IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); string channelId = "AB621914-0355-41AF-A69E-E5C4F282AF4A"; string enrollmentAlias = "39301076"; var response = client.Financial.GetStatementsByAlias(channelId, enrollmentAlias, "5259838650470180"); CollectionAssert.IsEmpty(response); }
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); }
public void GetBalancesAutonomousScope() { // Given RecognizedUserInfo recognizedUserInfo = RecognizedUserInfo.Current(); IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); // When List <IBalanceInfo> balances = client.Financial.GetBalances(recognizedUserInfo.DocType, recognizedUserInfo.DocNumber, recognizedUserInfo.AccountId).ToList(); // Then Assert.That(balances.Count(), NUnit.Framework.Is.EqualTo(5)); }
public void GivenReedemTokenWhenMetadataIsInvalidThenAnExceptionIsThrows() { IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); void ValidateSingleUseTokenAvoidingValidation(string metadata) => ((AspenClient)client.Financial).ValidateSingleUseTokenAvoidingValidation("CC", "52080323", "000000", accountType: "80", amount: 10000, metadata: metadata); void ValidateSingleUseToken(string metadata) => client.Financial.ValidateSingleUseToken("CC", "52080323", "000000", accountType: "80", amount: 10000, metadata: metadata); // Aunque el metadata no es obligatorio, no se acepta el vacío. AspenException exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(string.Empty)); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'Metadata' no puede ser vacío"); exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(" ")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'Metadata' no puede ser vacío"); string[] metadatas = { "áéíóú", "ÁÉÍÓÚ", $"{Guid.NewGuid()}-{Guid.NewGuid()}" }; foreach (string metadata in metadatas) { exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken(metadata)); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'Metadata' debe coincidir con el patrón ^[ -~]{1,50}$"); } }
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)); }
/// <summary> /// Sends a GET request using specified fluent <paramref name="builder"/> as an asynchronous operation. /// </summary> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <param name="fluentClient">The <see cref="IFluentClient"/> used to send request.</param> /// <param name="builder">The fluent builder factory.</param> /// <returns>The task object representing the asynchronous operation.</returns> /// <exception cref="ArgumentNullException"><paramref name="fluentClient" /> or <paramref name="builder" /> is <see langword="null" />.</exception> public static async Task <TResponse> GetAsync <TResponse>(this IFluentClient fluentClient, Action <QueryBuilder> builder) { if (fluentClient == null) { throw new ArgumentNullException(nameof(fluentClient)); } if (builder == null) { throw new ArgumentNullException(nameof(builder)); } var response = await fluentClient.GetAsync(builder).ConfigureAwait(false); var data = await response.DeserializeAsync <TResponse>().ConfigureAwait(false); return(data); }
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 GetAccountsByAliasUnrecognizedUser() { IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); string channelId = "94ED400D-5D26-4160-A3AA-EC45A2B4AD39"; string enrollmentAlias = "70511510"; void UnrecognizedUser() => client.Financial.GetAccountsByAlias(channelId, enrollmentAlias); AspenException exception = Assert.Throws <AspenException>(UnrecognizedUser); Assert.That(exception, Is.ExpectedException( HttpStatusCode.NotFound, "15881", "No se ha encontrado información de enrolamiento con los valores suministrados")); }
/// <summary> /// Sends a request using specified request message as an asynchronous operation. /// </summary> /// <param name="fluentClient">The <see cref="IFluentClient"/> used to send request.</param> /// <param name="requestMessage">The request message to send.</param> /// <returns>The task object representing the asynchronous operation.</returns> /// <exception cref="ArgumentNullException"><paramref name="fluentClient" /> or <paramref name="requestMessage" /> is <see langword="null" />.</exception> public static async Task <HttpResponseMessage> SendAsync(this IFluentClient fluentClient, HttpRequestMessage requestMessage) { if (fluentClient == null) { throw new ArgumentNullException(nameof(fluentClient)); } if (requestMessage == null) { throw new ArgumentNullException(nameof(requestMessage)); } var httpClient = fluentClient.HttpClient; requestMessage.SetContentSerializer(fluentClient.ContentSerializer); var response = await FluentDispatcher.SendAsync(httpClient, requestMessage).ConfigureAwait(false); return(response); }
public void ValidateCodeDoesWorksIfInvalidCodeIsProvided() { IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); string randomCode = "899129"; string randomNickname = "70446311550"; void ValidationFailed() => client.Management.ValidateActivationCode(randomCode, randomNickname); AspenException exception = Assert.Throws <AspenException>(ValidationFailed); Assert.That(exception, Is.ExpectedException( HttpStatusCode.ExpectationFailed, "15868", "No se encontró una invitación con los valores de búsqueda proporcionados")); }
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); }
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); }
public void GivenReedemTokenWhenDocTypeIsMissingOrNotRecognizedThenAnExceptionIsThrows() { IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); void ValidateSingleUseTokenAvoidingValidation(string invalidDocType) => ((AspenClient)client.Financial).ValidateSingleUseTokenAvoidingValidation(invalidDocType, "52080323", "000000", accountType: "80", amount: 10000); void ValidateSingleUseToken(string invalidDocType) => client.Financial.ValidateSingleUseToken(invalidDocType, "52080323", "000000", accountType: "80", amount: 10000); // Tipo de documento nulo... AspenException exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(null)); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'DocType' no puede ser nulo ni vacío"); // Tipo de documento vacío... exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(string.Empty)); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'DocType' no puede ser nulo ni vacío"); // Tipo de documento espacios en blanco... exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(" ")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'DocType' no puede ser nulo ni vacío"); // Tipo de documento no reconocido... exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("X")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'X' no se reconoce como un tipo de identificación"); // Tipo de documento no reconocido... exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("XX")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'XX' no se reconoce como un tipo de identificación"); // Tipo de documento no reconocido... exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("XXXXX")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'XXXXX' no se reconoce como un tipo de identificación"); // Tipo de documento no reconocido... exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("1")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'1' no se reconoce como un tipo de identificación"); // Tipo de documento no reconocido... exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("10")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'10' no se reconoce como un tipo de identificación"); // Tipo de documento no reconocido... exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("10000")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'10000' no se reconoce como un tipo de identificación"); }
public void GivenReedemTokenWhenDocNumberIsMissingOrInvalidThenAnExceptionIsThrows() { IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); void ValidateSingleUseTokenAvoidingValidation(string invalidDocNumber) => ((AspenClient)client.Financial).ValidateSingleUseTokenAvoidingValidation("CC", invalidDocNumber, "000000", accountType: "80", amount: 10000); void ValidateSingleUseToken(string invalidDocNumber) => client.Financial.ValidateSingleUseToken("CC", invalidDocNumber, "000000", accountType: "80", amount: 10000); // Número de documento nulo... AspenException exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(null)); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'DocNumber' no puede ser nulo ni vacío"); // Número de documento vacío... exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(string.Empty)); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'DocNumber' no puede ser nulo ni vacío"); // Número de documento espacios en blanco... exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(" ")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'DocNumber' no puede ser nulo ni vacío"); // Número de documento solo letras... exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("XXXXX")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'DocNumber' debe coincidir con el patrón ^\d{1,18}$"); // Número de documento letras y números... exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("X1X2X3X4X5")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'DocNumber' debe coincidir con el patrón ^\d{1,18}$"); // Número de documento números y espacios... exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken(" 123 456 ")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'DocNumber' debe coincidir con el patrón ^\d{1,18}$"); // Caracteres especiales... exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("*123456*")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'DocNumber' debe coincidir con el patrón ^\d{1,18}$"); // Número de documento excede longitud... string randomDocNumber = new Random().Next().ToString("00000000000000000000"); exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken(randomDocNumber)); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'DocNumber' debe coincidir con el patrón ^\d{1,18}$"); }
public void GivenReedemTokenWhenAccountTypeIsMissingOrInvalidThenAnExceptionIsThrows() { IFluentClient client = AspenClient.Initialize() .RoutingTo(this.autonomousAppInfoProvider) .WithIdentity(this.autonomousAppInfoProvider) .Authenticate() .GetClient(); void ValidateSingleUseTokenAvoidingValidation(string accountType) => ((AspenClient)client.Financial).ValidateSingleUseTokenAvoidingValidation("CC", "52080323", "000000", accountType: accountType, amount: 10000); void ValidateSingleUseToken(string accountType) => client.Financial.ValidateSingleUseToken("CC", "52080323", "000000", accountType: accountType, amount: 10000); // Aunque el tipo de cuenta no es obligatorio, no se acepta el vacío. AspenException exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(string.Empty)); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'AccountType' no puede ser vacío"); exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken(" ")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'AccountType' no puede ser vacío"); exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("XX")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'AccountType' debe coincidir con el patrón ^\d{1,3}$"); exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("XXXXX")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'AccountType' debe coincidir con el patrón ^\d{1,3}$"); exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("8*")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'AccountType' debe coincidir con el patrón ^\d{1,3}$"); exception = Assert.Throws <AspenException>(() => ValidateSingleUseToken("8000")); AssertAspenResponseException( exception, "15852", HttpStatusCode.BadRequest, @"'AccountType' debe coincidir con el patrón ^\d{1,3}$"); // No requiere el tipo de cuenta y puede ser nulo. exception = Assert.Throws <AspenException>(() => ValidateSingleUseTokenAvoidingValidation(null)); AssertAspenResponseException( exception, "15875", HttpStatusCode.NotFound, @"Falló la redención del token. No se encontró un token con los valores proporcionados"); // No requiere el tipo de cuenta y no requiere ser incluido en el body. exception = Assert.Throws <AspenException>(() => ((AspenClient)client.Financial).ValidateSingleUseTokenAvoidingValidation( "CC", "52080323", "000000", null, 10000, excludeAccountType: true)); AssertAspenResponseException( exception, "15875", HttpStatusCode.NotFound, @"Falló la redención del token. No se encontró un token con los valores proporcionados"); }