private void LoadResourceObject(IdempotencyResponseDTO response) { Type targetType = null; var map = GetMapForResource(); foreach (var mapItem in map) { var endPoint = GetApiEndPoint(mapItem.Key); endPoint.SetParameters("[0-9a-zA-Z]+", "[0-9a-zA-Z]+"); var sourceUrl = endPoint.GetUrl(); sourceUrl = sourceUrl.Replace("/", "\\/"); Regex ex = new Regex(sourceUrl); if (ex.IsMatch(response.RequestURL)) { targetType = mapItem.Value; break; } } if (targetType == null) { return; } MethodInfo method = typeof(MangoPayJsonDeserializer).GetMethod("DeserializeString").MakeGenericMethod(targetType); response.Resource = method.Invoke(new MangoPayJsonDeserializer(), new object[] { response.Resource }); }
public void Test_Idempotency() { string key = DateTime.Now.Ticks.ToString(); PayOutBankWireDTO payOut = null; // create bankwire try { WalletDTO wallet = this.GetJohnsWallet(); UserNaturalDTO user = this.GetJohn(); BankAccountDTO account = this.GetJohnsAccount(); PayOutBankWirePostDTO payOutPost = new PayOutBankWirePostDTO(user.Id, wallet.Id, new Money { Amount = 10, Currency = CurrencyIso.EUR }, new Money { Amount = 5, Currency = CurrencyIso.EUR }, account.Id, "Johns bank wire ref"); payOutPost.Tag = "DefaultTag"; payOutPost.CreditedUserId = user.Id; payOut = this.Api.PayOuts.CreateBankWire(key, payOutPost); } catch (Exception ex) { Assert.Fail(ex.Message); } Assert.IsNotNull(payOut); // test existing key IdempotencyResponseDTO result = null; try { result = this.Api.Idempotency.Get(key); } catch (Exception ex) { Assert.Fail(ex.Message); } Assert.IsNotNull(result); // test not existing key result = null; try { result = this.Api.Idempotency.Get(key + "_no"); // expect a response error Assert.Fail(); } catch (Exception ex) { /* catch block intentionally left empty */ } }