public async void Update_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <ICallTypeService, ICallTypeRepository>(); var model = new ApiCallTypeServerRequestModel(); var validatorMock = new Mock <IApiCallTypeServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiCallTypeServerRequestModel>())).Returns(Task.FromResult(new ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new CallType())); var service = new CallTypeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALCallTypeMapperMock, mock.DALMapperMockFactory.DALCallMapperMock); UpdateResponse <ApiCallTypeServerResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiCallTypeServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <CallTypeUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public virtual async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; ICallTypeService service = testServer.Host.Services.GetService(typeof(ICallTypeService)) as ICallTypeService; var model = new ApiCallTypeServerRequestModel(); model.SetProperties("B"); CreateResponse <ApiCallTypeServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.CallTypeDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiCallTypeServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public void MapServerResponseToRequest() { var mapper = new ApiCallTypeServerModelMapper(); var model = new ApiCallTypeServerResponseModel(); model.SetProperties(1, "A"); ApiCallTypeServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.Name.Should().Be("A"); }
public void CreatePatch() { var mapper = new ApiCallTypeServerModelMapper(); var model = new ApiCallTypeServerRequestModel(); model.SetProperties("A"); JsonPatchDocument <ApiCallTypeServerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiCallTypeServerRequestModel(); patch.ApplyTo(response); response.Name.Should().Be("A"); }
public virtual async Task <IActionResult> Create([FromBody] ApiCallTypeServerRequestModel model) { CreateResponse <ApiCallTypeServerResponseModel> result = await this.CallTypeService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/CallTypes/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
private async Task <ApiCallTypeServerRequestModel> PatchModel(int id, JsonPatchDocument <ApiCallTypeServerRequestModel> patch) { var record = await this.CallTypeService.Get(id); if (record == null) { return(null); } else { ApiCallTypeServerRequestModel request = this.CallTypeModelMapper.MapServerResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <ICallTypeService, ICallTypeRepository>(); var model = new ApiCallTypeServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new CallTypeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CallTypeModelValidatorMock.Object, mock.DALMapperMockFactory.DALCallTypeMapperMock, mock.DALMapperMockFactory.DALCallMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.CallTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <CallTypeDeletedNotification>(), It.IsAny <CancellationToken>())); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiCallTypeServerRequestModel model) { ApiCallTypeServerRequestModel request = await this.PatchModel(id, this.CallTypeModelMapper.CreatePatch(model)) as ApiCallTypeServerRequestModel; if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiCallTypeServerResponseModel> result = await this.CallTypeService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiCallTypeServerRequestModel> patch) { ApiCallTypeServerResponseModel record = await this.CallTypeService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiCallTypeServerRequestModel model = await this.PatchModel(id, patch) as ApiCallTypeServerRequestModel; UpdateResponse <ApiCallTypeServerResponseModel> result = await this.CallTypeService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }