Exemplo n.º 1
0
 public void AccountMustExistSome() =>
 Assert.True(
     TryOptionAsync(() => Task.FromResult(
                        AccountState.New(Guid.NewGuid())))
     .AccountMustExist()
     .IsSuccess
     );
 public async Task ToActionResultOk() =>
 Assert.NotNull(
     await Success <ErrorMsg, TryOptionAsync <AccountViewModel> >(
         TryOptionAsync(AccountViewModel.New(
                            AccountState.New(Guid.NewGuid()))))
     .ToActionResult()
     as OkObjectResult
     );
Exemplo n.º 3
0
        public async Task GetAccountState()
        {
            _stateDb
            .Setup(m => m.FindAsync(
                       It.IsAny <Expression <Func <AccountState, bool> > >(),
                       null))
            .ReturnsAsync(AccountState.New(Guid.NewGuid()));

            var result = await _repo.GetAccountState(Guid.NewGuid()).Try();

            Assert.True(result.IsSome);
        }
Exemplo n.º 4
0
        public async Task HandleGetAccountById()
        {
            _repo
            .Setup(m => m.GetAccountState(It.IsAny <Guid>()))
            .Returns(TryOptionAsync(Task.FromResult(
                                        AccountState.New(Guid.NewGuid())))
                     );

            var result = await _handler.Handle(
                new GetAccountById("669dceb5-107d-4701-ae9c-802d6963d081"),
                default);

            Assert.True(result.IsSuccess);
        }
Exemplo n.º 5
0
        public async Task UpsertAccountState()
        {
            _stateDb
            .Setup(m => m.FindOneAndUpdateAsync(
                       It.IsAny <Expression <Func <AccountState, bool> > >(),
                       It.IsAny <UpdateDefinition <AccountState> >(),
                       It.IsAny <FindOneAndUpdateOptions <AccountState, AccountState> >(),
                       default))
            .ReturnsAsync(AccountState.New(Guid.NewGuid()));

            var result = await _repo
                         .UpsertAccountState(AccountState.New(Guid.NewGuid()))
                         .Try();

            Assert.True(result.IsSome);
        }
Exemplo n.º 6
0
        public async Task Post()
        {
            _mediator
            .Setup(m => m.Send(
                       It.IsAny <IRequest <AccountResponse> >(),
                       default))
            .ReturnsAsync(
                Success <ErrorMsg, TryOptionAsync <AccountViewModel> >(
                    TryOptionAsync(AccountViewModel.New(
                                       AccountState.New(Guid.NewGuid())))
                    ));

            var result = await _controller.Post(new AccountTransaction());

            Assert.IsType <OkObjectResult>(result);
        }
        public async Task HandleCreatedAccount()
        {
            _repo
            .Setup(m => m.GetAccountState(It.IsAny <Guid>()))
            .Returns(TryOptionAsync <AccountState>(None));
            _repo
            .Setup(m => m.UpsertAccountState(It.IsAny <AccountState>()))
            .Returns(TryOptionAsync(Task.FromResult(
                                        AccountState.New(Guid.NewGuid())))
                     );

            var result = await _handler.Handle(new AccountTransaction
            {
                Event     = TransactionEvent.CreatedAccount,
                AccountId = "669dceb5-107d-4701-ae9c-802d6963d081",
                Currency  = CurrencyCode.USD
            }, default);

            Assert.True(result.IsSuccess);
        }
        public async Task HandleDepositedCash()
        {
            _repo
            .Setup(m => m.GetAccountState(It.IsAny <Guid>()))
            .Returns(TryOptionAsync(Task.FromResult(
                                        AccountState.New(Guid.NewGuid())))
                     );
            _repo
            .Setup(m => m.UpsertAccountState(It.IsAny <AccountState>()))
            .Returns(TryOptionAsync(Task.FromResult(
                                        AccountState.New(Guid.NewGuid())))
                     );

            var result = await _handler.Handle(new AccountTransaction
            {
                Event     = TransactionEvent.DepositedCash,
                AccountId = "669dceb5-107d-4701-ae9c-802d6963d081",
                Amount    = 10
            }, default);

            Assert.True(result.IsSuccess);
        }