public async Task Invoice_Must_Have_The_Expected_AdditionalData() { const string expectedKey = "key"; const string expectedValue = "value"; _builder.AddAdditionalData(expectedKey, expectedValue); var invoice = await _builder.BuildAsync(); Assert.IsNotNull(invoice.AdditionalData); Assert.IsTrue(invoice.AdditionalData.ContainsKey(expectedKey)); Assert.AreEqual(expectedValue, invoice.AdditionalData[expectedKey]); }
public static IInvoiceBuilder AddMellatCumulativeAccounts(this IInvoiceBuilder builder, IEnumerable <MellatCumulativeDynamicAccount> accounts) { if (accounts == null) { throw new ArgumentNullException(nameof(accounts)); } if (!accounts.Any()) { throw new ArgumentException("Accounts cannot be an empty collection.", nameof(accounts)); } List <MellatCumulativeDynamicAccount> allAccounts = null; builder.ChangeAdditionalData(data => { if (data.ContainsKey(MellatHelper.CumulativeAccountsKey)) { allAccounts = (List <MellatCumulativeDynamicAccount>)data[MellatHelper.CumulativeAccountsKey]; } else { allAccounts = new List <MellatCumulativeDynamicAccount>(); } allAccounts.AddRange(accounts); }); builder.AddAdditionalData(MellatHelper.CumulativeAccountsKey, allAccounts); return(builder); }
/// <summary> /// Uses the given account to communicate with the gateway. /// </summary> /// <param name="builder"></param> /// <param name="accountName">Name of the account.</param> public static IInvoiceBuilder UseAccount(this IInvoiceBuilder builder, string accountName) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (accountName.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(accountName)); } builder.AddAdditionalData(GatewayAccountKeyName, accountName); return(builder); }
/// <summary> /// Appends the given dictionary to the additional data of the invoice. /// </summary> /// <param name="builder"></param> /// <param name="additionalData"></param> public static IInvoiceBuilder AddAdditionalData(this IInvoiceBuilder builder, IDictionary <string, object> additionalData) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (additionalData == null) { throw new ArgumentNullException(nameof(additionalData)); } foreach (var data in additionalData) { builder.AddAdditionalData(data.Key, data.Value); } return(builder); }
public static IInvoiceBuilder AddMellatCumulativeAccounts(this IInvoiceBuilder builder, IList <MellatCumulativeDynamicAccount> accounts) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (accounts == null) { throw new ArgumentNullException(nameof(accounts)); } if (accounts.Count == 0) { throw new ArgumentException("accounts cannot be an empty collection.", nameof(accounts)); } IList <MellatCumulativeDynamicAccount> existingAccounts; if (builder.AdditionalData.ContainsKey(MellatHelper.CumulativeAccountsKey)) { existingAccounts = (IList <MellatCumulativeDynamicAccount>)builder.AdditionalData[MellatHelper.CumulativeAccountsKey]; } else { existingAccounts = new List <MellatCumulativeDynamicAccount>(); } foreach (var account in accounts) { existingAccounts.Add(account); } builder.AdditionalData.Remove(MellatHelper.CumulativeAccountsKey); builder.AddAdditionalData(MellatHelper.CumulativeAccountsKey, existingAccounts); builder.UseGateway(Gateway.Mellat); return(builder); }