public async Task Update_ReturnSelf_With_InvalidModel_When_PassingInvalidModel() { var model = new UpdateIdSrvClientDto() { Id = Guid.NewGuid() }; this.ClientServiceMock.Setup(v => v.UpdateClientAsync(It.IsAny <UpdateIdSrvClientDto>())).ReturnsAsync(true); var controller = new ClientsController(this.ClientServiceMock.Object); controller.ModelState.AddModelError(string.Empty, string.Empty); ActionResult result = await controller.Update(model); Assert.IsInstanceOf <ViewResult>(result); var viewResult = result as ViewResult; Assert.NotNull(viewResult); Assert.IsEmpty(viewResult.ViewName); object modelFromController = controller.ViewData.Model; Assert.IsInstanceOf <UpdateIdSrvClientDto>(modelFromController); var actualModel = modelFromController as UpdateIdSrvClientDto; Assert.AreEqual(actualModel, model); Assert.IsFalse(controller.ModelState.IsValid); }
public async Task Update_CallServiceUpdateForClient_When_PassingModel() { var model = new UpdateIdSrvClientDto(); this.ClientServiceMock.Setup(v => v.UpdateClientAsync(model)).ReturnsAsync(true); var controller = new ClientsController(this.ClientServiceMock.Object); await controller.Update(model); this.ClientServiceMock.Verify(v => v.UpdateClientAsync(model), Times.Once); }
public void Update_ThrowsClientRepositoryException_When_RepositoryReturnUnexpetedResponse() { this.ClientRepository .Setup(v => v.UpdateAsync(It.IsAny <UpdateIdSrvClientDto>())) .ReturnsAsync(this.UnexpectedRepositoryResponse); var controller = new ClientController(this.ClientRepository.Object); var clientDto = new UpdateIdSrvClientDto { Name = "u", Secret = "p" }; Assert.ThrowsAsync <ClientRepositoryException>(() => controller.Update(clientDto)); }
public async Task Update_InvokeUpdateFromRepository_With_PassedDto_When_PassingNameAndSecretAndUriInDto() { this.ClientRepository .Setup(v => v.UpdateAsync(It.IsAny <UpdateIdSrvClientDto>())) .ReturnsAsync(RepositoryResponse.Success); var controller = new ClientController(this.ClientRepository.Object); var clientDto = new UpdateIdSrvClientDto { Name = "u", Secret = "p", Uri = "u" }; IHttpActionResult httpResult = await controller.Update(clientDto); this.ClientRepository.Verify(v => v.UpdateAsync(clientDto)); }
public async Task Update_ReturnNotFound_When_RepositoryReturnNotFound() { this.ClientRepository .Setup(v => v.UpdateAsync(It.IsAny <UpdateIdSrvClientDto>())) .ReturnsAsync(RepositoryResponse.NotFound); var controller = new ClientController(this.ClientRepository.Object); var clientDto = new UpdateIdSrvClientDto { Name = "u", Secret = "p" }; IHttpActionResult httpResult = await controller.Update(clientDto); Assert.NotNull(httpResult); Assert.IsInstanceOf <NotFoundResult>(httpResult); }
public async Task Update_ReturnOk_When_PassingDtoWithNameAndSecretAndUri_And_RepositoryReturnSuccess() { this.ClientRepository .Setup(v => v.UpdateAsync(It.IsAny <UpdateIdSrvClientDto>())) .ReturnsAsync(RepositoryResponse.Success); var controller = new ClientController(this.ClientRepository.Object); var clientDto = new UpdateIdSrvClientDto { Name = "u", Secret = "p", Uri = "u" }; IHttpActionResult httpResult = await controller.Update(clientDto); Assert.NotNull(httpResult); Assert.IsInstanceOf <OkResult>(httpResult); }
public async Task <IHttpActionResult> Update(UpdateIdSrvClientDto client) { if (client == null || client.Name == null || client.Secret == null) { return(this.BadRequest()); } RepositoryResponse response = await this.ClientRepository.UpdateAsync(client); return (response == RepositoryResponse.Success ? this.Ok() : response == RepositoryResponse.NotFound ? this.NotFound() : response == RepositoryResponse.Conflict ? this.Conflict() as IHttpActionResult : throw new ClientRepositoryException()); }
public async Task <ActionResult> Update(UpdateIdSrvClientDto client) { if (!this.ModelState.IsValid) { return(this.View(client)); } bool updated = await this.ClientService.UpdateClientAsync(client); if (!updated) { this.ModelState.AddModelError(string.Empty, "Не удалось обновить клиента"); } return(updated ? this.ViewSuccess("Клиент успешно обновлён") : this.View(client) as ActionResult); }
public async Task <ActionResult> Update(Guid id) { IdSrvClientDto client = await this.ClientService.GetClientByIdAsync(id); if (client == null) { return(this.ViewError("Такого клиента не существует") as ActionResult); } var updateClient = new UpdateIdSrvClientDto { Id = client.Id, Name = client.Name, Secret = client.Secret, Uri = client.Uri, }; return(this.View(updateClient)); }
/// <inheritdoc/> public async Task <RepositoryResponse> UpdateAsync(UpdateIdSrvClientDto client) { if (client == null || client.Name == null || client.Secret == null) { throw new ArgumentNullException(nameof(client)); } using (IDbConnection connection = await this.GetConnection()) { var compiler = new SqlServerCompiler(); var db = new QueryFactory(connection, compiler); try { int updated = await db.Query("Clients").Where(new { client.Id }).UpdateAsync(client); return(updated == 1 ? RepositoryResponse.Success : RepositoryResponse.NotFound); } catch (SqlCeException ex) when(ex.NativeError == 25016) { return(RepositoryResponse.Conflict); } } }
/// <inheritdoc/> /// <remarks> /// В случае ошибки подключения к WebApi возникнет системное исключение, /// внутри метода оно никак не перехватывается. Метод может вернуть false только /// в случае успешного подключения (когда ответ WebApi интепретируется как ошибка). /// </remarks> public async Task <bool> UpdateClientAsync(UpdateIdSrvClientDto client) { return(await RestApiHelpers.CallBoolApi(() => this.RestClient.UpdateAsync(client))); }