Beispiel #1
0
            public DepositAssetAccount GetValid(DepositAssetAccount deposit)
            {
                deposit.AssetAccountId = Safe(Prompt.GetString("Asset Account Id:", deposit.AssetAccountId), "Cannot deposit without specifying account id");
                deposit.ReferenceId    = Safe(Prompt.GetString("Reference Id:", deposit.ReferenceId), "Cannot deposit without specifying reference id");
                var amountString = Safe(Prompt.GetString("Amount:", string.Format(new NumberFormatInfo()
                {
                    NumberDecimalDigits = deposit.Precision
                }, "{0:F}", deposit.Amount)), "Cannot deposit without specifying some amount");

                deposit.Amount             = Convert.ToDecimal(amountString, CultureInfo.InvariantCulture);
                deposit.SettlementCurrency = Safe(Prompt.GetString("Currency code:", deposit.SettlementCurrency), "Cannot deposit without specifying currency code");
                deposit.ReferenceText      = Prompt.GetString("Reference Text:", deposit.ReferenceText);

                deposit.Precision = this.GetPrecision(amountString);

                return(deposit);
            }
Beispiel #2
0
        public async Task CanDepositToAssetAccount()
        {
            // arrange
            var expectedDepositDto = new DepositAssetAccount
            {
                AssetAccountId     = "AA1111",
                ReferenceId        = "RF001",
                ReferenceText      = "Integration test AccountManagement.CanDepositToAssetAccount",
                Amount             = 25000.365m,
                Precision          = 3,
                SettlementCurrency = "EUR"
            };

            var actualDepositDto = default(DepositAssetAccount);

            this.AssignRequestDelegate(
                async httpContext =>
            {
                // The url and method types should match
                if (httpContext.Request.Method.Equals("PATCH", StringComparison.InvariantCultureIgnoreCase) &&
                    httpContext.Request.Path.Value.Equals($"/api/externalAssetAccount/{expectedDepositDto.AssetAccountId}/deposit", StringComparison.InvariantCultureIgnoreCase))
                {
                    actualDepositDto = await httpContext.Request.DeserializeBody <DepositAssetAccount>().ConfigureAwait(false);

                    if (actualDepositDto != null)
                    {
                        httpContext.Response.StatusCode = (int)HttpStatusCode.Accepted;

                        return;
                    }
                }

                httpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            });

            // act
            await this.httpClient.DepositAsync(expectedDepositDto).ConfigureAwait(false);

            // assert
            actualDepositDto.Should().BeEquivalentTo(expectedDepositDto);
        }
Beispiel #3
0
        public static void Configure(CommandLineApplication app, CommandLineOptions options, IConsole console)
        {
            // description
            app.Description      = "Deposits to an asset account";
            app.ExtendedHelpText = $"{Environment.NewLine}Use 'accounts deposit -i' to enter interactive mode{Environment.NewLine}";

            // arguments
            var argumentAssetAccountId     = app.Argument("account", "The asset account id to deposit", false);
            var argumentReferenceId        = app.Argument("reference", "The unique reference identifier for this transaction", false);
            var argumentAmount             = app.Argument("amount", "The amount to deposit", false);
            var argumentSettlementCurrency = app.Argument("currency", "The ISO currency code for settlement currency", false);

            // options
            var optionInteractive   = app.Option("-i|--interactive", "Enters interactive mode", CommandOptionType.NoValue);
            var optionReferenceText = app.Option("-t|--info", "The reference text which describes about this transaction", CommandOptionType.SingleValue);

            // action (for this command)
            app.OnExecute(
                () =>
            {
                if ((string.IsNullOrWhiteSpace(argumentAssetAccountId.Value) ||
                     string.IsNullOrWhiteSpace(argumentReferenceId.Value) ||
                     string.IsNullOrWhiteSpace(argumentSettlementCurrency.Value) ||
                     string.IsNullOrWhiteSpace(argumentAmount.Value)) &&
                    !optionInteractive.HasValue())
                {
                    app.ShowVersionAndHelp();
                    return;
                }

                if (!decimal.TryParse(argumentAmount.Value, out decimal amount) &&
                    !optionInteractive.HasValue())
                {
                    app.ShowVersionAndHelp();
                    return;
                }

                var reporter = new ConsoleReporter(console, options.Verbose.HasValue(), false);
                var helper   = new DepositHelper();

                var deposit = new DepositAssetAccount
                {
                    AssetAccountId     = argumentAssetAccountId.Value,
                    ReferenceId        = argumentReferenceId.Value,
                    ReferenceText      = optionReferenceText.Value(),
                    Amount             = amount,
                    SettlementCurrency = argumentSettlementCurrency.Value,
                    Precision          = string.IsNullOrEmpty(argumentAmount.Value)
                            ? 0
                            : helper.GetPrecision(argumentAmount.Value)
                };

                reporter.Verbose("Prototype deposit (from command line arguments):");
                reporter.Verbose(JsonConvert.SerializeObject(deposit));

                if (!helper.IsValid(deposit) || optionInteractive.HasValue())
                {
                    try
                    {
                        deposit = helper.GetValid(deposit);
                    }
                    catch (NotSupportedException ex)
                    {
                        throw new CommandParsingException(app, $"Operation Aborted. {ex.Message}", ex);
                    }

                    reporter.Verbose("Validated deposit (from interactive console):");
                    reporter.Verbose(JsonConvert.SerializeObject(deposit));
                }

                options.Command = new DepositAssetAccountCommand {
                    deposit = deposit
                };
            });
        }
Beispiel #4
0
 public bool IsValid(DepositAssetAccount deposit) =>
 !string.IsNullOrWhiteSpace(deposit.AssetAccountId) &&
 !string.IsNullOrWhiteSpace(deposit.ReferenceId) &&
 !string.IsNullOrWhiteSpace(deposit.SettlementCurrency) &&
 deposit.Amount > 0;
Beispiel #5
0
 public DepositAssetAccount GetPrototype(DepositAssetAccount deposit) => deposit;