Example #1
0
        public async Task given_an_existing_identifier_getcharge_return_charge_response_ok()
        {
            string requestUri            = string.Format("http://localhost:10001/api/charge/{0}", identifier);
            string jsonVideo             = SerializeCharge(true);
            HttpResponseMessage response = CreateResponse(jsonVideo);

            client.GetAsync(Arg.Any <string>()).Returns(response);
            var chargeRepositoryServiceClient = new ChargeRepositoryServiceApiClient(client);

            var result = await chargeRepositoryServiceClient.Get(identifier);

            result.Should().BeOfType <ChargeResponseOK>();
            await client.Received(1).GetAsync(Arg.Any <string>());
        }
Example #2
0
        public async virtual Task <ChargeResponse> Get(string identifier)
        {
            string requestUri          = string.Format("{0}/api/charges/{1}", server, identifier);
            HttpResponseMessage result = null;

            try {
                result = await client.GetAsync(requestUri);

                if (result.StatusCode == HttpStatusCode.OK)
                {
                    ChargeResponse response = JsonConvert.DeserializeObject <ChargeResponse>(result.Content.ReadAsStringAsync().GetAwaiter().GetResult());
                    if (response.alreadyExist)
                    {
                        return(new ChargeResponseOK());
                    }
                }
                throw new Exception("TODO");
            }
            catch (Exception ex) {
                return(new ChargeResponseException()
                {
                    Message = ex.Message
                });
            }
        }