Example #1
0
        public async Task PatchTerms_ShouldReturnOk()
        {
            // Arrange
            var buyerAccountUuid = Guid.NewGuid();
            var account          = new BuyerAccount {
                BuyerAccountUuid = buyerAccountUuid, CompanyName = "Brandscreen"
            };
            var model = new AccountTermsPatchViewModel {
                CreditLimit = 1000
            };

            Mock.Mock <IAccountService>().Setup(x => x.GetAccount(buyerAccountUuid))
            .ReturnsAsync(account);

            // Act
            var retVal = await Controller.PatchTerms(buyerAccountUuid, model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkResult>());
            Mock.Mock <IAccountService>().Verify(x => x.UpdateAccount(It.Is <BuyerAccount>(buyerAccount => buyerAccount.CreditLimit == model.CreditLimit)), Times.Once);
        }
        public async Task <IHttpActionResult> PatchTerms(Guid id, AccountTermsPatchViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var buyerAccount = await _accountService.GetAccount(id).ConfigureAwait(false);

            if (buyerAccount == null)
            {
                return(NotFound());
            }

            _mapping.Map(model, buyerAccount);
            await _accountService.UpdateAccount(buyerAccount).ConfigureAwait(false);

            return(Ok());
        }