Пример #1
0
        public async Task CommissionOperation_SetPersonalCommissions_CheckCommissions(float?tCom, float?dCom,
                                                                                      float?wCom, bool?isAbsoluteType)
        {
            var fakeUser        = new UserRecord();
            var fakeCommission  = new CommissionRecord();
            var userServiceMock = new Mock <IUserService>();

            userServiceMock
            .Setup(x => x.FindUserByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(fakeUser);
            userServiceMock
            .Setup(x => x.FindUserCommissionAsync(It.IsAny <int>()))
            .ReturnsAsync(fakeCommission);
            var adminController = new AdminController(userServiceMock.Object, _adminServiceMock.Object, _dbMock.Object);

            //act
            var result = await adminController.CommissionOperation(tCom, dCom, wCom, isAbsoluteType, null, It.IsAny <int>());

            //assert
            Assert.Equal(tCom, fakeCommission.TransferCommission);
            Assert.Equal(wCom, fakeCommission.WithdrawCommission);
            Assert.Equal(dCom, fakeCommission.DepositCommission);
            Assert.Equal(isAbsoluteType, fakeCommission.IsAbsoluteType);
            Assert.IsType <OkObjectResult>(result);
            _dbMock.Verify(x => x.SaveChangesAsync(It.IsAny <CancellationToken>()));
        }
Пример #2
0
 public static CommissionRecord CreateSameCommission(this CommissionRecord commission, OperationType type,
                                                     int id) =>
 new CommissionRecord
 {
     Id       = id, Rate = commission.Rate, Type = commission.Type, OperationType = type,
     Value    = commission.Value, CurrencyId = commission.CurrencyId, MaxCommission = commission.MaxCommission,
     MaxValue = commission.MaxValue, MinCommission = commission.MinCommission, UserId = commission.UserId
 };
Пример #3
0
 private static CommissionRecord GetCommission(CommissionRecord commission,
                                               OperationType operationType, double maxValue, int id)
 {
     commission.Id            = id;
     commission.OperationType = operationType;
     commission.MaxValue      = maxValue;
     return(commission);
 }
Пример #4
0
 private static void CreateCurrencyEqualCommissions(this ModelBuilder builder,
                                                    CommissionRecord commissionPattern, CurrencyRecord currency, int mul)
 {
     commissionPattern.CurrencyId = currency.Id;
     builder.Entity <CommissionRecord>().HasData(
         commissionPattern.CreateSameCommission(OperationType.Deposit, mul * commissionPattern.Id + 1),
         commissionPattern.CreateSameCommission(OperationType.Withdrawal, mul * commissionPattern.Id + 2),
         commissionPattern.CreateSameCommission(OperationType.Transfer, mul * commissionPattern.Id + 3));
 }
Пример #5
0
        private static void CreateUserCommission(this ModelBuilder builder, UserRecord user,
                                                 CommissionRecord commissionPattern, CurrencyRecord currency, OperationType type, int mul)
        {
            var commission = commissionPattern.CreateSameCommission(type, mul * commissionPattern.Id + 1);

            commission.CurrencyId = currency.Id;
            commission.UserId     = user.Id;
            builder.Entity <CommissionRecord>().HasData(commission);
        }
        public async Task Operation_WithdrawMoneyWithCommission_VerifyResult()
        {
            //arrange
            var fakeUser     = TestUser();
            var fakeAmount   = 1000.0f;
            var fakeCurrency = new CurrencyRecord {
                Id = 1, Name = "FAKE"
            };
            var fakeAccount = TestUserAccount();
            var fakeWallet  = new WalletRecord {
                CashValue = 1010
            };
            var fakeCommission = new CommissionRecord {
                CurrencyId = 1, WithdrawCommission = 10, IsAbsoluteType = true
            };
            var userServiceMock = new Mock <IUserService>();

            userServiceMock
            .Setup(x => x.FindCurrencyAsync(It.IsAny <string>()))
            .ReturnsAsync(fakeCurrency);
            userServiceMock
            .Setup(x => x.FindUserWalletAsync(It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(fakeWallet);
            userServiceMock
            .Setup(x => x.FindUserAccountAsync(It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(fakeAccount);
            userServiceMock
            .Setup(x => x.FindUserByNameAsync(It.IsAny <string>()))
            .ReturnsAsync(fakeUser);
            userServiceMock
            .Setup(x => x.FindCurrencyCommissionAsync(It.IsAny <int>()))
            .ReturnsAsync(fakeCommission);
            userServiceMock
            .Setup(x => x.FindUserCommissionAsync(It.IsAny <int>()))
            .ReturnsAsync(null as CommissionRecord);

            var accountController = new AccountController(userServiceMock.Object, _dbMock.Object)
            {
                ControllerContext = _controllerContext
            };

            //act
            await accountController.Operation(fakeAccount.Id, OperationType.Withdraw, fakeAmount, fakeCurrency.Name, null);

            //assert
            Assert.Equal(0, fakeWallet.CashValue);
        }
Пример #7
0
        public static CommissionRecord CreateCommission(int currencyId, CommissionDto commissionDto,
                                                        OperationType type, string userId = null)
        {
            var commission = new CommissionRecord
            {
                CurrencyId = currencyId, Type = commissionDto.Type, OperationType = type,
                MaxValue   = commissionDto.MaxOperationValue, UserId = userId
            };

            if (commissionDto.Type == CommissionType.Absolute)
            {
                commission.Value = commissionDto.Value;
            }
            else
            {
                commission.Rate          = commissionDto.Rate;
                commission.MinCommission = commissionDto.MinimalCommission;
                commission.MaxCommission = commissionDto.MaximalCommission;
            }

            return(commission);
        }
Пример #8
0
 public static double CalculateCommissionAsync(CommissionRecord record, double value) => record.Type switch
 {