Пример #1
0
        public async Task Patch_ShouldReturnOk()
        {
            // Arrange
            var buyerAccountUuid = Guid.NewGuid();
            var account          = new BuyerAccount {
                BuyerAccountUuid = buyerAccountUuid, CompanyName = "Brandscreen"
            };
            var model = new AccountPatchViewModel {
                CompanyName = "WJsHome"
            };

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

            // Act
            var retVal = await Controller.Patch(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.CompanyName == model.CompanyName)), Times.Once);
        }
Пример #2
0
        public async Task <IHttpActionResult> Patch(Guid id, AccountPatchViewModel 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());
        }