public async Task<IHttpActionResult> Put(PutBalanceRequest putBalanceRequest)
        {
            var claimsIdentity = User.Identity as ClaimsIdentity;

            if (claimsIdentity == null)
                return InternalServerError();

            var fullName = claimsIdentity.GetFullNameFromClaims();
            var originator = new SimpleUser { Id = User.Identity.GetUserId(), UserName = User.Identity.GetUserName(), FullName = fullName };
            var result = await _balanceControllerService.UpdateBalance(putBalanceRequest.UserId, putBalanceRequest.Amount, originator);

            // todo location uri
            return Created("", result);
        }
        public async Task Put()
        {
            var originator = new SimpleUser { Id = TestConstants.User4.Id, UserName = TestConstants.User4.UserName };
            var amount = 4.4M;
            MockedApiInstaller.MockedBalanceControllerService.Setup(
               x => x.UpdateBalance(TestConstants.User1.Id, amount, originator))
               .ReturnsAsync(new decimal());

            var token = await AuthorizeUser(TestConstants.User4.UserName, TestConstants.User4.Password);
            Assert.IsNotNullOrEmpty(token.Token);

            var response = await PutAuthorizeAsync(new PutBalanceRequest { UserId = TestConstants.User1.Id, Amount = amount }, string.Format($"{_routePrefix}"));

            MockedApiInstaller.MockedBalanceControllerService.Verify(x => x.UpdateBalance(TestConstants.User1.Id, amount, It.Is<SimpleUser>(y => y.Id == originator.Id && y.UserName == originator.UserName)), Times.Once);

            AssertAndLogInvalidModelState(response, System.Net.HttpStatusCode.Created);
        }
Beispiel #3
0
        public async Task <decimal> UpdateBalance(string userId, decimal amount, SimpleUser originatorDto)
        {
            var docDbOriginator  = _mapper.Map <SimpleUser, Domain.Entities.DocumentDb.SimpleUser>(originatorDto);
            var userBalanceAudit = new UserBalanceAudit
            {
                Id     = Guid.NewGuid().ToString(),
                UserId = userId,
                Audits =
                    new List <UserBalanceAuditItem>
                {
                    new UserBalanceAuditItem {
                        Amount = amount, Date = DateTime.UtcNow, Originator = docDbOriginator
                    }
                }
            };
            var updatedAmount = await _documentStore.ExecuteStoredProcedure <decimal>(DocumentDbSp.UpdateUserBalance, userBalanceAudit);

            return(updatedAmount);
        }
        public async Task UpdateBalance()
        {
            var originator = new SimpleUser
            {
                Id = TestConstants.User4.Id,
                UserName = TestConstants.User4.UserName
            };

            var amount = 100.01M;
            var userId = TestConstants.User3.Id;
            var updatedBalance = await DatabaseRepository.UpdateBalance(userId, amount, originator);
            Assert.AreEqual(TestConstants.User3.Balance + amount, updatedBalance);
        }
 public async Task<decimal> UpdateBalance(string userId, decimal amount, SimpleUser originator)
 {
     var updatedAmount = await _databaseRepository.UpdateBalance(userId, amount, originator);
     return updatedAmount;
 }