public void AccountHandler_ConfirmTransaction_Succesfull()
        {
            var accountService = new Moq.Mock <IAccountService>();
            var accountHandler = new AccountHandler(accountService.Object);
            var transactionId  = Guid.NewGuid();

            var ammount       = new Models.Money();
            var listOperation = new List <Operation>()
            {
                new Operation()
                {
                    Id            = Guid.NewGuid(),
                    TransactionId = transactionId,
                    Ammount       = ammount,
                    OperationType = OperationType.Out,
                    Status        = OperationStatus.Waiting
                },
                new Operation()
                {
                    Id            = Guid.NewGuid(),
                    TransactionId = transactionId,
                    Ammount       = ammount,
                    OperationType = OperationType.In,
                    Status        = OperationStatus.Waiting
                }
            };

            accountService
            .Setup(a => a.FindOperations(transactionId))
            .Returns(listOperation);

            accountService
            .Setup(a => a.ConfirmOperation(Moq.It.IsAny <Guid>()))
            .Returns <Guid>((operationId) =>
            {
                var operation    = listOperation.FirstOrDefault(o => (Guid)o.Id == operationId);
                operation.Status = OperationStatus.Confirmed;
                return(operation);
            });

            accountHandler.ConfirmTransaction(transactionId);

            accountService.Verify(a => a.FindOperations(transactionId), Moq.Times.Once);
            accountService.Verify(a => a.ConfirmOperation((Guid)listOperation[0].Id), Moq.Times.Once);
            accountService.Verify(a => a.ConfirmOperation((Guid)listOperation[1].Id), Moq.Times.Once);
        }
        public void AccountHandler_CommitTransaction_InvalidNumberOfOperationsException()
        {
            var accountService = new Moq.Mock <IAccountService>();
            var accountHandler = new AccountHandler(accountService.Object);
            var transactionId  = Guid.NewGuid();

            var ammount       = new Models.Money();
            var listOperation = new List <Operation>()
            {
                new Operation()
                {
                    Id            = Guid.NewGuid(),
                    TransactionId = transactionId,
                    Ammount       = ammount,
                    OperationType = OperationType.Out,
                    Status        = OperationStatus.Waiting
                },
                new Operation()
                {
                    Id            = Guid.NewGuid(),
                    TransactionId = transactionId,
                    Ammount       = ammount,
                    OperationType = OperationType.In,
                    Status        = OperationStatus.Waiting
                },
                new Operation()
                {
                    Id            = Guid.NewGuid(),
                    TransactionId = transactionId,
                    Ammount       = ammount,
                    OperationType = OperationType.In,
                    Status        = OperationStatus.Waiting
                }
            };

            accountService
            .Setup(a => a.FindOperations(transactionId))
            .Returns(listOperation);

            Assert.Throws <InvalidNumberOfOperationsException>(() => accountHandler.ConfirmTransaction(transactionId));

            accountService.Verify(a => a.FindOperations(transactionId), Moq.Times.Once);
            accountService.Verify(a => a.ConfirmOperation(listOperation[0].Id), Moq.Times.Never);
            accountService.Verify(a => a.ConfirmOperation(listOperation[1].Id), Moq.Times.Never);
            //OperationsNotMatchException
        }