public virtual async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); var mapper = new ApiCallAssignmentServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; ICallAssignmentService service = testServer.Host.Services.GetService(typeof(ICallAssignmentService)) as ICallAssignmentService; ApiCallAssignmentServerResponseModel model = await service.Get(1); ApiCallAssignmentClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(1, 1); UpdateResponse <ApiCallAssignmentClientResponseModel> updateResponse = await client.CallAssignmentUpdateAsync(model.Id, request); context.Entry(context.Set <CallAssignment>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <CallAssignment>().ToList()[0].CallId.Should().Be(1); context.Set <CallAssignment>().ToList()[0].UnitId.Should().Be(1); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.CallId.Should().Be(1); updateResponse.Record.UnitId.Should().Be(1); }
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; ICallAssignmentService service = testServer.Host.Services.GetService(typeof(ICallAssignmentService)) as ICallAssignmentService; var model = new ApiCallAssignmentServerRequestModel(); model.SetProperties(1, 1); CreateResponse <ApiCallAssignmentServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.CallAssignmentDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiCallAssignmentServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public void MapServerResponseToRequest() { var mapper = new ApiCallAssignmentServerModelMapper(); var model = new ApiCallAssignmentServerResponseModel(); model.SetProperties(1, 1, 1); ApiCallAssignmentServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.CallId.Should().Be(1); response.UnitId.Should().Be(1); }
public async virtual Task <IActionResult> Get(int id) { ApiCallAssignmentServerResponseModel response = await this.CallAssignmentService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_ShouldReturnNullBecauseRecordNotFound() { var mock = new ServiceMockFacade <ICallAssignmentService, ICallAssignmentRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <CallAssignment>(null)); var service = new CallAssignmentService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CallAssignmentModelValidatorMock.Object, mock.DALMapperMockFactory.DALCallAssignmentMapperMock); ApiCallAssignmentServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { CallAssignmentControllerMockFacade mock = new CallAssignmentControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiCallAssignmentServerResponseModel> >(null as ApiCallAssignmentServerResponseModel); var mockRecord = new ApiCallAssignmentServerResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCallAssignmentServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCallAssignmentServerResponseModel> >(mockResponse.Object)); CallAssignmentController controller = new CallAssignmentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiCallAssignmentServerRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCallAssignmentServerRequestModel>())); }
public async void All_Exists() { CallAssignmentControllerMockFacade mock = new CallAssignmentControllerMockFacade(); var record = new ApiCallAssignmentServerResponseModel(); var records = new List <ApiCallAssignmentServerResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records)); CallAssignmentController controller = new CallAssignmentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0, string.Empty); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiCallAssignmentServerResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiCallAssignmentServerRequestModel> patch) { ApiCallAssignmentServerResponseModel record = await this.CallAssignmentService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiCallAssignmentServerRequestModel model = await this.PatchModel(id, patch) as ApiCallAssignmentServerRequestModel; UpdateResponse <ApiCallAssignmentServerResponseModel> result = await this.CallAssignmentService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }