コード例 #1
0
        public async Task RunStatement(int index, bool result)
        {
            var testData           = PandaStatementCreateContractTestData.pandaStatementCreateContracts(now)[index];
            var runStatementResult = await accountLogic.RunStatement(testData);

            Assert.Equal(runStatementResult.IsError(), result);
        }
コード例 #2
0
        public AccountLogicTest()
        {
            var mock = new MockRepository(MockBehavior.Default);

            _accountRepository = new Mock <IAccountRepository>();

            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new MappingProfile());
            });

            _mapper = mappingConfig.CreateMapper();


            #region CanActiveAccount

            _accountRepository
            .Setup(s => s.GetAccountStatus(AccountIdSuccess))
            .Returns(Task.FromResult(true));

            _accountRepository
            .Setup(s => s.GetAccountStatus(AccountIdFail))
            .Returns(Task.FromResult(false));

            _accountRepository
            .Setup(s => s.IsPaticipant(AccountIdSuccess, UserIdSuccess))
            .Returns(Task.FromResult(true));

            _accountRepository
            .Setup(s => s.IsPaticipant(AccountIdSuccess, userIdFail))
            .Returns(Task.FromResult(false));

            _accountRepository
            .Setup(s => s.IsPaticipant(AccountIdFail, UserIdSuccess))
            .Returns(Task.FromResult(false));
            _accountRepository
            .Setup(s => s.IsPaticipant(AccountIdFail, userIdFail))
            .Returns(Task.FromResult(false));

            #endregion

            #region CanUpdateBalance

            _accountRepository
            .Setup(s => s.GetAccountBalance(accountHundred))
            .Returns(Task.FromResult(balanceHundred));

            _accountRepository
            .Setup(s => s.GetAccountBalance(accountThousand))
            .Returns(Task.FromResult(balanceThousand));

            #endregion

            #region RunStatement

            var test0 = PandaStatementCreateContractTestData.pandaStatementCreateContracts(now)[0];
            var new0  = new PandaStatement();
            _mapper.Map(test0, new0);

            var test1 = PandaStatementCreateContractTestData.pandaStatementCreateContracts(now)[1];
            var new1  = new PandaStatement();
            _mapper.Map(test1, new1);

            _accountRepository
            .Setup(s => s.CreateStatement(It.Is <PandaStatement>(m =>
                                                                 m.Balances == new0.Balances
                                                                 &&
                                                                 m.CreatedAt == new0.CreatedAt
                                                                 &&
                                                                 m.Id == new0.Id
                                                                 &&
                                                                 m.Status == new0.Status
                                                                 )))
            .Returns(Task.FromResult(PandaResponse.CreateSuccessResponse(true)));

            _accountRepository
            .Setup(s => s.UpdateAccountBalance(new0.PandaAccountId, new0.Balances))
            .Returns(Task.FromResult(PandaResponse.CreateSuccessResponse(true)));

            _accountRepository
            .Setup(s => s.CreateStatement(new1))
            .Returns(Task.FromResult(PandaResponse.CreateErrorResponse <bool>("test error")));

            _accountRepository
            .Setup(s => s.UpdateAccountBalance(new1.PandaAccountId, new1.Balances))
            .Returns(Task.FromResult(PandaResponse.CreateErrorResponse <bool>("test error")));

            #endregion

            accountLogic = new AccountLogic(
                _accountRepository.Object,
                _mapper);
        }