示例#1
0
        public async Task CreateTransaction(Transaction transaction, Guid transactionId)
        {
            using var itemLock = new EntityLock(transaction.AccountId, typeof(DataAccess.Entities.Account));
            var transactionEntity = await accountDbContext.Transactions
                                    .AsNoTracking()
                                    .FirstOrDefaultAsync(x => x.Id == transactionId);

            if (transactionEntity != null)
            {
                return;
            }

            var account = await accountDbContext.Accounts
                          .FirstOrDefaultAsync(x => x.Id == transaction.AccountId);

            if (account == null)
            {
                throw new ValidationException();
            }

            account.Balance += transaction.Amount.Value;
            accountDbContext.Transactions.Add(new DataAccess.Entities.Transaction()
            {
                Id        = transactionId,
                AccountId = transaction.AccountId,
                Amount    = transaction.Amount.Value
            });

            await accountDbContext.SaveChangesAsync();
        }
示例#2
0
        public void DealLocksController_GetLocks_Returns_OKResponseCode(int dealNumber, bool isLocked)
        {
            #region Arrange

            Mock <IEntityLockRepository> dealLockRepository = new Mock <IEntityLockRepository>();
            SetupUserIdentity();
            SetupDealLockRepository(dealLockRepository, dealNumber, userIdentity.UserId, isLocked);

            string url = $"{AppSettings.BASEURL}{ RouteHelper.DealsRoutePrefix }/{dealNumber}/locks";
            //string url = $"{AppSettings.BASEURL}{RouteHelper.DealsRoutePrefix}{RouteHelper.DealLocksPrefix}";
            var httpRequest = new HttpRequestMessage(new HttpMethod(AppSettings.HTTPGET), url);

            DealLocksController dealLocksController = CreateDealLocksController(httpRequest, dealLockRepository.Object);

            #endregion

            #region Act

            var response      = dealLocksController.GetLocks(dealNumber);
            var contentResult = response as NegotiatedContentResult <ResponseItem <EntityLock> >;

            #endregion

            #region Assert

            #region Expected Data

            var expectedDealLock = new  EntityLock()
            {
                entityId            = dealNumber,
                entityTypeName      = EntityType.Deals.ToString(),
                lockedByDisplayName = "John Doe",
                lockedTimestamp     = DateTime.MinValue
            };

            string  expectedURL      = ($"/{ RouteHelper.DealsRoutePrefix }/{dealNumber }/locks");
            var     expectedMessages = new List <Message>();
            Message expectedMessage  = new Warning("entityID", $"{ expectedDealLock.lockedByDisplayName} has locked this deal for edit");
            expectedMessages.Add(expectedMessage);
            IList <Link> links = null;
            ResponseItem <EntityLock> expectedContent = new ResponseItem <EntityLock>(expectedURL, expectedDealLock, links, expectedMessages);

            #endregion

            Assertions.AssertOkResponse(contentResult);

            var actualDealLock = contentResult.Content.data;
            if (isLocked)
            {
                Assertions.AreEqualByJson(expectedContent, contentResult.Content);
            }
            else
            {
                Assert.IsNull(actualDealLock);
                Assert.IsNull(contentResult.Content.messages);
                Assert.IsNull(links);
            }



            #endregion
        }