コード例 #1
0
        public async Task CashTransfer_NoFee_ExistedSettings_Test()
        {
            // arrange

            var assertCalls = new AssertCalls();

            var settings             = GetSettingsModel();
            var feesClient           = InitializeFeesClient(null, settings);
            var accountsClient       = InitializeAccountsClient();
            var matchingEngineClient = InitializeMatchingEngineClient(null, AssertMatchingEngineClientInput, assertCalls);
            var logger = InitializeLogger <CashOperations>(AssertLoggerWarning, assertCalls);

            var cashOperations = new CashOperations(matchingEngineClient, feesClient, accountsClient, logger);

            var model = new CashTransferModel(Btc, CashTransferVolume, AccountId, FromWalletId, ToWalletId, Description);

            // act

            await cashOperations.CashTransferAsync(BrokerId, model);

            // assert

            void AssertMatchingEngineClientInput(CashTransferOperation cashTransferOperation)
            {
                AssertCashTransferOperation(cashTransferOperation, CashTransferVolume);

                AssertFees(cashTransferOperation.Fees, 0);
            }

            Assert.Equal(2, assertCalls.Count);
        }
コード例 #2
0
        public async Task CashOut_ExistedFee_ExistedSettings_PositiveVolumeToNegative_Test()
        {
            // arrange

            var assertCalls = new AssertCalls();

            var feeModel             = GetCashOperationsFeeModel(CashOutNegativeVolume, CashType.CashOut);
            var settings             = GetSettingsModel();
            var feesClient           = InitializeFeesClient(feeModel, settings);
            var accountsClient       = InitializeAccountsClient();
            var matchingEngineClient = InitializeMatchingEngineClient(AssertMatchingEngineClientInput, null, assertCalls);
            var logger = InitializeLogger <CashOperations>(AssertLoggerWarning, assertCalls);

            var cashOperations = new CashOperations(matchingEngineClient, feesClient, accountsClient, logger);

            // Volume is positive here and will 'converted' to negative
            var model = new CashInOutModel(Btc, CashOutPositiveVolume, AccountId, WalletId, Description);

            // act

            await cashOperations.CashOutAsync(BrokerId, model);

            // assert

            void AssertMatchingEngineClientInput(CashInOutOperation cashInOutOperation)
            {
                AssertCashInOutOperation(cashInOutOperation, CashOutNegativeVolume);

                AssertFees(cashInOutOperation.Fees, CashOutNegativeVolume / 100);
            }

            Assert.Equal(1, assertCalls.Count);
        }
コード例 #3
0
        public async Task CashOut_NoFee_NoSettings_Test()
        {
            // arrange

            var assertCalls = new AssertCalls();

            var matchingEngineClient = InitializeMatchingEngineClient(AssertMatchingEngineClientInput, null, assertCalls);
            var feesClient           = InitializeFeesClient(null, null);
            var accountsClient       = InitializeAccountsClient();
            var logger = InitializeLogger <CashOperations>(AssertLoggerWarning, assertCalls);

            var cashOperations = new CashOperations(matchingEngineClient, feesClient, accountsClient, logger);

            var model = new CashInOutModel(Btc, CashOutNegativeVolume, AccountId, WalletId, Description);

            // act

            await cashOperations.CashOutAsync(BrokerId, model);

            // assert

            void AssertMatchingEngineClientInput(CashInOutOperation cashInOutOperation)
            {
                AssertCashInOutOperation(cashInOutOperation, CashOutNegativeVolume);

                AssertFees(cashInOutOperation.Fees, 0);
            }

            Assert.Equal(2, assertCalls.Count);
        }
コード例 #4
0
        protected ILogger <T> InitializeLogger <T>(
            Action <LogLevel, EventId, object, Exception, object> assertMethod, AssertCalls assertCalls)
        {
            var loggerMock = new Mock <ILogger <T> >();

            loggerMock.Setup(x => x.Log(
                                 It.IsAny <LogLevel>(),
                                 It.IsAny <EventId>(),
                                 It.Is <It.IsAnyType>((v, t) => true),
                                 It.IsAny <Exception>(),
                                 It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)))
            .Callback((LogLevel logLevel, EventId eventId, object state, Exception e, object callback) =>
            {
                if (logLevel == LogLevel.Information)
                {
                    return;
                }

                assertMethod(logLevel, eventId, state, e, callback);

                assertCalls.Count++;
            });

            return(loggerMock.Object);
        }
コード例 #5
0
        private IMatchingEngineClient InitializeMatchingEngineClient(
            Action <CashInOutOperation> cashInOutAssertMethod,
            Action <CashTransferOperation> cashTransferAssertMethod,
            AssertCalls assertCalls)
        {
            var matchingEngineClientMock = new Mock <IMatchingEngineClient>();
            var cashOperationsApiMock    = new Mock <ICashOperationsApi>();

            if (cashInOutAssertMethod != null)
            {
                cashOperationsApiMock.Setup(x => x.CashInOutAsync(It.IsAny <CashInOutOperation>(), default))
                .Returns((CashInOutOperation cashInOutOperation, CancellationToken ct) =>
                {
                    cashInOutAssertMethod(cashInOutOperation);

                    assertCalls.Count++;

                    return(Task.FromResult(new Response()));
                });
            }
            if (cashTransferAssertMethod != null)
            {
                cashOperationsApiMock.Setup(x => x.CashTransferAsync(It.IsAny <CashTransferOperation>(), default))
                .Returns((CashTransferOperation cashTransferOperation, CancellationToken ct) =>
                {
                    cashTransferAssertMethod(cashTransferOperation);

                    assertCalls.Count++;

                    return(Task.FromResult(new Response()));
                });
            }
            matchingEngineClientMock.SetupGet(x => x.CashOperations).Returns(() => cashOperationsApiMock.Object);

            return(matchingEngineClientMock.Object);
        }