public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <ICallService, ICallRepository>(); var model = new ApiCallServerRequestModel(); var validatorMock = new Mock <IApiCallServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new CallService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALCallMapperMock, mock.DALMapperMockFactory.DALCallAssignmentMapperMock, mock.DALMapperMockFactory.DALNoteMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <CallDeletedNotification>(), 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; ICallService service = testServer.Host.Services.GetService(typeof(ICallService)) as ICallService; var model = new ApiCallServerRequestModel(); model.SetProperties(1, 1, 1, "B", 1, DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), 2); CreateResponse <ApiCallServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.CallDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiCallServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public virtual async Task <IActionResult> Create([FromBody] ApiCallServerRequestModel model) { CreateResponse <ApiCallServerResponseModel> result = await this.CallService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Calls/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
private async Task <ApiCallServerRequestModel> PatchModel(int id, JsonPatchDocument <ApiCallServerRequestModel> patch) { var record = await this.CallService.Get(id); if (record == null) { return(null); } else { ApiCallServerRequestModel request = this.CallModelMapper.MapServerResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void MapServerResponseToRequest() { var mapper = new ApiCallServerModelMapper(); var model = new ApiCallServerResponseModel(); model.SetProperties(1, 1, 1, 1, "A", 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1); ApiCallServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.AddressId.Should().Be(1); response.CallDispositionId.Should().Be(1); response.CallStatusId.Should().Be(1); response.CallString.Should().Be("A"); response.CallTypeId.Should().Be(1); response.DateCleared.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.DateDispatched.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.QuickCallNumber.Should().Be(1); }
public void CreatePatch() { var mapper = new ApiCallServerModelMapper(); var model = new ApiCallServerRequestModel(); model.SetProperties(1, 1, 1, "A", 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1); JsonPatchDocument <ApiCallServerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiCallServerRequestModel(); patch.ApplyTo(response); response.AddressId.Should().Be(1); response.CallDispositionId.Should().Be(1); response.CallStatusId.Should().Be(1); response.CallString.Should().Be("A"); response.CallTypeId.Should().Be(1); response.DateCleared.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.DateDispatched.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.QuickCallNumber.Should().Be(1); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiCallServerRequestModel model) { ApiCallServerRequestModel request = await this.PatchModel(id, this.CallModelMapper.CreatePatch(model)) as ApiCallServerRequestModel; if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiCallServerResponseModel> result = await this.CallService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <ICallService, ICallRepository>(); var model = new ApiCallServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new CallService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CallModelValidatorMock.Object, mock.DALMapperMockFactory.DALCallMapperMock, mock.DALMapperMockFactory.DALCallAssignmentMapperMock, mock.DALMapperMockFactory.DALNoteMapperMock); 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.CallModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <CallDeletedNotification>(), It.IsAny <CancellationToken>())); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiCallServerRequestModel> patch) { ApiCallServerResponseModel record = await this.CallService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiCallServerRequestModel model = await this.PatchModel(id, patch) as ApiCallServerRequestModel; UpdateResponse <ApiCallServerResponseModel> result = await this.CallService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }