public async Task Handle_CreateTransaction_ShouldReturnTransactions()
        {
            var handler = new TransactionCreateHandler(Mapper, _mockRepo.Object);

            var request = new TransactionCreateRequest
            {
                Transactions = TransactionModels()
            };

            var now = DateTime.Now;

            _mockRepo
              .Setup(repo => repo.Operation.Create(It.IsAny<Operation>()))
              .Callback<Operation>(a => a.Id = 666)
              .Verifiable();

            _mockRepo
              .Setup(repo => repo.TransactionRepository.CreateMany(It.IsAny<IEnumerable<Transaction>>()))
              .Verifiable();


            var result = await handler.Handle(request, default);

            Assert.True(result.All(t => t.OperationId == 666));

            Assert.IsAssignableFrom<IEnumerable<TransactionModel>>(result);
        }
        public int Create(TransactionCreateRequest transactionCreateRequest)
        {
            int newId = 0;

            dataProvider.ExecuteNonQuery(
                "Transaction_Insert",
                (parameters) =>
            {
                parameters.AddWithValue("@UserId", transactionCreateRequest.UserId);
                parameters.AddWithValue("@PurchasePrice", transactionCreateRequest.PurchasePrice);
                parameters.AddWithValue("@TotalCommission", transactionCreateRequest.TotalCommission);
                parameters.AddWithValue("@Fees", transactionCreateRequest.Fees);
                parameters.AddWithValue("@AgentCommission", transactionCreateRequest.AgentCommission);
                parameters.AddWithValue("@BrokerCommission", transactionCreateRequest.BrokerCommission);
                parameters.AddWithValue("@SaleDate", transactionCreateRequest.SaleDate);
                parameters.AddWithValue("@CloseDate", transactionCreateRequest.CloseDate);
                parameters.AddWithValue("@Status", transactionCreateRequest.Status);
                parameters.AddWithValue("@StreetAddress", transactionCreateRequest.StreetAddress);
                parameters.AddWithValue("@City", transactionCreateRequest.City);
                parameters.AddWithValue("@State", transactionCreateRequest.State);
                parameters.AddWithValue("@ZipCode", transactionCreateRequest.ZipCode);
                parameters.AddWithValue("@Lead_Id", transactionCreateRequest.Lead_Id);
                parameters.Add("@Id", SqlDbType.Int).Direction = ParameterDirection.Output;
            },
                (parameters) =>
            {
                newId = (int)parameters["@Id"].Value;
            }
                );

            return(newId);
        }
Beispiel #3
0
        public HttpResponseMessage Create(TransactionCreateRequest transactionCreateRequest)
        {
            if (transactionCreateRequest == null)
            {
                ModelState.AddModelError(" ", "Missing body data");
            }
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            int newId = transactionService.Create(transactionCreateRequest);

            return(Request.CreateResponse(HttpStatusCode.Created, new ItemResponse <int> {
                Item = newId
            }));
        }
Beispiel #4
0
        public async Task <ActionResult <TransactionCreateResponse> > Create([FromBody] TransactionCreateRequest request)
        {
            request.EnsureValidation();
            TransactionCreateArgs transactionCreateArgs = new TransactionCreateArgs
            {
                TransactionName   = request.Name,
                DebitAccountId    = request.DebitAccountId,
                CreditAccountId   = request.CreditAccountId,
                TransactionAmount = request.Amount,
                IssuedTime        = request.IssuedTime
            };
            IMediator mediator = Factory.Resolve <IMediator>();
            TransactionCreateResult transactionCreateResult = await mediator.Send(new TransactionCreateCommand(transactionCreateArgs));

            transactionCreateResult.EnsureSuccess();
            TransactionCreateResponse response = new TransactionCreateResponse
            {
                IsSuccess = true
            };

            return(Ok(response));
        }