public async Task CanAddInvestorAccount() { // arrange var expectedAccount = new InvestorAssetAccount { AssetAccountId = "accountId", OwnerId = "sub", Type = AssetAccountType.Lykke, IntermediaryId = "intermediaryAccountId", MarginAccount = "marginAccountId", BankIdentificationMargin = "bim", ReferenceAccount = "ra", BankIdentificationReference = "bir", WithdrawalAllowed = true, }; var actualAccount = default(InvestorAssetAccount); // hook into the context (somehow) and verify this.AssignRequestDelegate( async httpContext => { if (httpContext.Request.Method.Equals("POST", StringComparison.InvariantCultureIgnoreCase) && httpContext.Request.Path.Value.Equals("/api/externalAssetAccount/investor", StringComparison.InvariantCultureIgnoreCase)) { actualAccount = await httpContext.Request.DeserializeBody <InvestorAssetAccount>().ConfigureAwait(false); if (actualAccount != null) { httpContext.Response.StatusCode = (int)HttpStatusCode.Accepted; return; } } httpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; }); // act await this.httpClient.AddAsync(expectedAccount).ConfigureAwait(false); // assert actualAccount.Should().BeEquivalentTo(expectedAccount); }
public InvestorAssetAccount GetValid(InvestorAssetAccount account) { account.AssetAccountId = Safe(Prompt.GetString("Asset Account Id:", account.AssetAccountId), "Cannot create account without account id"); account.OwnerId = Safe(Prompt.GetString("User Id:", account.OwnerId), "Cannot create an account without owner user id."); account.IntermediaryId = Safe(Prompt.GetString("Intermediary Account:", account.IntermediaryId), "Cannot create an account without intermediary asset account id"); account.Type = account.Type == default ? Enum.Parse <AssetAccountType>(Safe(Prompt.GetString(string.Concat("Type: (", string.Join(" | ", Enum.GetNames(typeof(AssetAccountType))), ")"), account.Type.ToString()), "Cannot create account type without type"), true) : account.Type; account.SettlementCurrency = Prompt.GetString("Currency code (optional):", account.SettlementCurrency); account.MarginAccount = Prompt.GetString("Margin Account (optional):", account.MarginAccount); account.ReferenceAccount = Prompt.GetString("Reference Account (optional):", account.ReferenceAccount); account.BankIdentificationMargin = Prompt.GetString("Bank Identification Margin (optional):", account.BankIdentificationMargin); account.BankIdentificationReference = Prompt.GetString("Bank Identification Reference (optional):", account.BankIdentificationReference); account.WithdrawalAllowed = Prompt.GetYesNo("Withdrawal Allowed default (yes):", true, ConsoleColor.Red, ConsoleColor.DarkRed); // defaults account.SettlementCurrency = string.IsNullOrWhiteSpace(account.SettlementCurrency) ? null : account.SettlementCurrency; account.MarginAccount = string.IsNullOrWhiteSpace(account.MarginAccount) ? null : account.MarginAccount; account.ReferenceAccount = string.IsNullOrWhiteSpace(account.ReferenceAccount) ? null : account.ReferenceAccount; account.BankIdentificationMargin = string.IsNullOrWhiteSpace(account.BankIdentificationMargin) ? null : account.BankIdentificationMargin; account.BankIdentificationReference = string.IsNullOrWhiteSpace(account.BankIdentificationReference) ? null : account.BankIdentificationReference; return(account); }
public static void Configure(CommandLineApplication app, CommandLineOptions options, IConsole console) { // description app.Description = "Creates a new asset account"; app.ExtendedHelpText = $"{Environment.NewLine}Use 'accounts add -i' to enter interactive mode{Environment.NewLine}"; // arguments var argumentAssetAccountId = app.Argument("account", "The asset account id", false); var argumentOwnerId = app.Argument("id", "The user subject identifier of the owner user", false); var argumentIntermediaryId = app.Argument("intermediary", "The intermediary asset account id", false); var argumentType = app.Argument("type", string.Concat("The asset account type (", string.Join(" | ", Enum.GetNames(typeof(AssetAccountType))), ")"), false); // options var optionSettlementCurrency = app.Option("-c|--currency <currency_code>", "The ISO currency code for settlement currency", CommandOptionType.SingleValue); var optionMarginAccount = app.Option("--margin_account <margin_account>", "The margin account id", CommandOptionType.SingleValue); var optionReferenceAccount = app.Option("--reference_account <reference_account>", "The reference account id", CommandOptionType.SingleValue); var optionBankIdentificationMargin = app.Option("--bank_ident_margin <bank_identification_margin>", "The bank identification margin", CommandOptionType.SingleValue); var optionBankIdentificationReference = app.Option("--bank_ident_reference <bank_identification_reference>", "The bank identification reference", CommandOptionType.SingleValue); var optionWithdrawalAllowed = app.Option("--withdrawal_allowed", "withdrawal allowed", CommandOptionType.NoValue); var optionInteractive = app.Option("-i|--interactive", "Enters interactive mode", CommandOptionType.NoValue); // action (for this command) app.OnExecute( () => { AssetAccountType type = default; if ((string.IsNullOrEmpty(argumentAssetAccountId.Value) || string.IsNullOrEmpty(argumentOwnerId.Value) || string.IsNullOrEmpty(argumentIntermediaryId.Value) || !Enum.TryParse(argumentType.Value, out type)) && !optionInteractive.HasValue()) { app.ShowVersionAndHelp(); return; } var withdrawalAllowed = optionWithdrawalAllowed.HasValue(); var reporter = new ConsoleReporter(console, options.Verbose.HasValue(), false); var helper = new AccountHelper(); var account = new InvestorAssetAccount { AssetAccountId = argumentAssetAccountId.Value, OwnerId = argumentOwnerId.Value, IntermediaryId = argumentIntermediaryId.Value, Type = type, MarginAccount = optionMarginAccount.Value(), ReferenceAccount = optionReferenceAccount.Value(), BankIdentificationMargin = optionBankIdentificationMargin.Value(), BankIdentificationReference = optionBankIdentificationReference.Value(), WithdrawalAllowed = withdrawalAllowed, SettlementCurrency = optionSettlementCurrency.Value(), }; reporter.Verbose("Prototype account (from command line arguments):"); reporter.Verbose(JsonConvert.SerializeObject(account)); if (!helper.IsValid(account) || optionInteractive.HasValue()) { try { account = helper.GetValid(account); } catch (NotSupportedException ex) { throw new CommandParsingException(app, $"Operation Aborted. {ex.Message}", ex); } reporter.Verbose("Validated account (from interactive console):"); reporter.Verbose(JsonConvert.SerializeObject(account)); } options.Command = new AddInvestorAssetAccountCommand { account = account }; }); }
public bool IsValid(InvestorAssetAccount account) => !string.IsNullOrEmpty(account.AssetAccountId) && !string.IsNullOrEmpty(account.OwnerId);
public InvestorAssetAccount GetPrototype(InvestorAssetAccount account) => account;