示例#1
0
        public void ThenTheResponseContainsNoErrors()
        {
            string responseContent = _endpointHelper.GetBills();
            GetBillListResponse billListResponse = JsonConvert.DeserializeObject <GetBillListResponse>(responseContent);

            Assert.IsFalse(billListResponse.HasError);
        }
        public void ThenTheResponseContainsAnErrorWithExpiredCode()
        {
            string responseContent = _endpointHelper.GetBills();
            GetBillListResponse billListResponse = JsonConvert.DeserializeObject <GetBillListResponse>(responseContent);

            Assert.IsTrue(billListResponse.HasError);
            Assert.IsTrue(billListResponse.Error.ErrorCode == ErrorCode.USER_SESSION_EXPIRED);
        }
        public void ThenTheResponseContainsAnErrorWithInvalidCredentialsCode()
        {
            string responseContent = _endpointHelper.GetBills();
            GetBillListResponse billListResponse = JsonConvert.DeserializeObject <GetBillListResponse>(responseContent);

            Assert.IsTrue(billListResponse.HasError);
            Assert.IsTrue(billListResponse.Error.ErrorCode == ErrorCode.SESSION_INVALID);
        }
        public void Initialize()
        {
            _fakeAccountHelper = new FakeAccountHelper();
            Guid validSessionId = _fakeAccountHelper.GenerateValidCredentials();

            _endpointHelper = new EndpointHelper();
            _endpointHelper.Setup()
            .SetAuthenticationToken(validSessionId.ToString());

            string responseContent = _endpointHelper.GetBills();

            _getBillListResponse = JsonConvert.DeserializeObject <GetBillListResponse>(responseContent);
        }
示例#5
0
        public void Initialize()
        {
            _fakeAccountHelper = new FakeAccountHelper();
            Guid validSessionId = _fakeAccountHelper.GenerateValidCredentials();

            _endpointHelper = new EndpointHelper();
            _billId         = _endpointHelper.Setup()
                              .SetAuthenticationToken(validSessionId.ToString())
                              .AddBill(typeof(WhenTheUserSuppliesAValidId).Name)
                              .ReturnAddedBillIds()[0];
            string responseContent = _endpointHelper.GetBills(_billId);

            _getBillListResponse = JsonConvert.DeserializeObject <GetBillListResponse>(responseContent);
        }
示例#6
0
        public GetBillListResponse GetBillList(int?id, int?page, int?resultsPerPage)
        {
            var response = new GetBillListResponse();

            try
            {
                if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false)
                {
                    response.AddError("The authorization credentails were invalid", Request.Headers["Authorization"].ToString(), ErrorCode.SESSION_INVALID);
                    return(response);
                }

                ActiveUser user = _userService.GetUserInformationFromAuthHeader(Request.Headers["Authorization"].ToString());
                if (user.HouseId == 0)
                {
                    response.AddError("You must belong to a household to get bills", ErrorCode.USER_NOT_IN_HOUSEHOLD);
                    return(response);
                }

                _recurringBillWorker.GenerateNextMonthsBills(user.HouseId);

                if (id == null)
                {
                    Pagination pagination = new Pagination
                    {
                        Page           = page ?? 0,
                        ResultsPerPage = resultsPerPage ?? int.MaxValue
                    };
                    response.Bills = _billRepository.GetAllBasicBillDetails(pagination, user.HouseId);
                }
                else
                {
                    response.Bills.Add(_billRepository.GetBasicBillDetails((int)id, user.HouseId));
                }
            }
            catch (ErrorCodeException exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", exception.Code);
            }
            catch (Exception exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", id);
            }

            return(response);
        }
        public async Task <V> CallServiceAsync <U, V>(U request) where U : RequestBase where V : ResponseBase, new()
        {
            var response = new V();

            try
            {
                switch (request.GetType().Name)
                {
                case nameof(RegistroUsuariosGetAllRequest):
                    response = await ProcessCallAsyncObtenerDatos(request as RegistroUsuariosGetAllRequest) as V;     //SadmApi.RegistroUsuariosGetAll(request as RegistroUsuariosGetAllRequest) as V;

                    break;

                case nameof(PAGOSRequest):
                    response = new ResponseBase() as V;
                    await SadmApi.RealizarPago(request as PAGOSRequest);

                    break;

                case nameof(ObtenerUrlPagosRequest):
                    response = await ProcessCallPagosAsync(request as ObtenerUrlPagosRequest) as V;

                    break;

                case nameof(GetAppTokenRequest):
                    response = await SadmApi.GetAppToken(request as GetAppTokenRequest) as V;

                    break;

                case nameof(SignUpRequest):
                    response = await SadmApi.SignUp(request as SignUpRequest) as V;

                    var a = response;
                    break;

                case nameof(RecoverPasswordRequest):
                    response = new RecoverPasswordResponse {
                        Message = (await SadmApi.RecoverPassword(request as RecoverPasswordRequest))
                    } as V;
                    break;

                case nameof(UpdateUserRequest):
                    response = new UpdateUserResponse {
                        Message = (await SadmApi.UpdateUser(request as UpdateUserRequest)).Replace("\"", string.Empty)
                    } as V;
                    break;

                case nameof(LoginRequest):
                    response = await ProcessCallAsync(request as LoginRequest) as V;

                    break;

                case nameof(PasswordRecoveryRequest):
                    response = await SimulateSuccessfulAsync <PasswordRecoveryResponse>() as V;

                    break;

                case nameof(AddContractRequest):
                    var  reqAux      = new AddContractRequest();
                    bool errorExiste = false;
                    //bool errordiverso = true;

                    var response1 = new AddContractResponse {
                        ContractId = (await SadmApi.AddNis(request as AddContractRequest)).Replace("\"", string.Empty)
                    };
                    //if(response.== @"\0|El Servicio No Puede Agregarse, Ya Se Encuentra Asociado\")
                    response = response1 as V;
                    if (response1.ContractId.Contains("El Servicio No Puede Agregarse, Ya Se Encuentra Asociado"))
                    {
                        response.AddError("El Servicio No Puede Agregarse, Ya Se Encuentra Asociado");
                    }
                    else if (response1.ContractId.ToUpper().Contains("EL RECIBO INDICADO NO EXISTE"))
                    {
                        response.AddError("El recibo indicado no existe");
                    }
                    else if (response1.ContractId.Contains("La Lectura Ingresada Es Incorrecta"))
                    {
                        response.AddError("La Lectura Ingresada Es Incorrecta");
                    }

                    break;

                case nameof(RemoveContractRequest):
                    response = new RemoveContractResponse {
                        ContractId = (await SadmApi.RemoveNis(request as RemoveContractRequest)).Replace("\"", string.Empty)
                    } as V;

                    break;

                case nameof(GetContractListRequest):
                    var tmp = await SadmApi.GetBalanceList(request as GetContractListRequest);

                    tmp = tmp.Substring(1, tmp.Length - 2);
                    tmp = tmp.Replace("\\", string.Empty);
                    var contractList = Newtonsoft.Json.JsonConvert.DeserializeObject <IList <Balance> >(tmp);
                    response = new GetBalanceListResponse {
                        BalanceList = contractList
                    } as V;
                    break;

                case nameof(AddReportRequest):
                    response = new AddReportResponse {
                        ReportId = (await SadmApi.AddReport((request as AddReportRequest).Report)).Replace("\"", string.Empty)
                    } as V;
                    break;

                case nameof(GetReportListRequest):
                    response = await SadmApi.GetReportList((request as GetReportListRequest).UserId) as V;

                    break;

                case nameof(UpdateMyDataRequest):
                    var updateMyDataRequest = await SadmApi.Update(request as UpdateMyDataRequest);

                    response = new UpdateMyDataResponse() as V;
                    break;

                case nameof(GetBillListRequest):
                    var responseAux = await SadmApi.GetBillList(request as GetBillListRequest);

                    var billList = Newtonsoft.Json.JsonConvert.DeserializeObject <IList <Bill> >(responseAux);
                    response = new GetBillListResponse {
                        BillList = billList
                    } as V;
                    break;

                case nameof(UpdateBillDeliveryConfigurationRequest):
                    var respAux = await SadmApi.UpdateBillDeliveryConfiguration(request as UpdateBillDeliveryConfigurationRequest);

                    var success = respAux == "\"1\"";
                    response = new UpdateBillDeliveryConfigurationResponse {
                        Result = success
                    } as V;
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            catch (Exception ex)
            {
                response.AddError("Ocurrió un error, vuelve a intentarlo más tarde.");
            }
            return(response);
        }