public virtual ApiWorkerResponseModel MapBOToModel( BOWorker boWorker) { var model = new ApiWorkerResponseModel(); model.SetProperties(boWorker.Id, boWorker.CommunicationStyle, boWorker.Fingerprint, boWorker.IsDisabled, boWorker.JSON, boWorker.MachinePolicyId, boWorker.Name, boWorker.RelatedDocumentIds, boWorker.Thumbprint, boWorker.WorkerPoolIds); return(model); }
public async virtual Task <IActionResult> Get(string id) { ApiWorkerResponseModel response = await this.WorkerService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_null_record() { var mock = new ServiceMockFacade <IWorkerRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <Worker>(null)); var service = new WorkerService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.WorkerModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLWorkerMapperMock, mock.DALMapperMockFactory.DALWorkerMapperMock); ApiWorkerResponseModel response = await service.Get(default(string)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>())); }
public void MapResponseToRequest() { var mapper = new ApiWorkerModelMapper(); var model = new ApiWorkerResponseModel(); model.SetProperties("A", "A", "A", true, "A", "A", "A", "A", "A", "A"); ApiWorkerRequestModel response = mapper.MapResponseToRequest(model); response.CommunicationStyle.Should().Be("A"); response.Fingerprint.Should().Be("A"); response.IsDisabled.Should().Be(true); response.JSON.Should().Be("A"); response.MachinePolicyId.Should().Be("A"); response.Name.Should().Be("A"); response.RelatedDocumentIds.Should().Be("A"); response.Thumbprint.Should().Be("A"); response.WorkerPoolIds.Should().Be("A"); }
public void MapBOToModel() { var mapper = new BOLWorkerMapper(); BOWorker bo = new BOWorker(); bo.SetProperties("A", "A", "A", true, "A", "A", "A", "A", "A", "A"); ApiWorkerResponseModel response = mapper.MapBOToModel(bo); response.CommunicationStyle.Should().Be("A"); response.Fingerprint.Should().Be("A"); response.Id.Should().Be("A"); response.IsDisabled.Should().Be(true); response.JSON.Should().Be("A"); response.MachinePolicyId.Should().Be("A"); response.Name.Should().Be("A"); response.RelatedDocumentIds.Should().Be("A"); response.Thumbprint.Should().Be("A"); response.WorkerPoolIds.Should().Be("A"); }
public async void Create_Errors() { WorkerControllerMockFacade mock = new WorkerControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiWorkerResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiWorkerResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiWorkerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiWorkerResponseModel> >(mockResponse.Object)); WorkerController controller = new WorkerController(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 ApiWorkerRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiWorkerRequestModel>())); }
public async void All_Exists() { WorkerControllerMockFacade mock = new WorkerControllerMockFacade(); var record = new ApiWorkerResponseModel(); var records = new List <ApiWorkerResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); WorkerController controller = new WorkerController(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); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiWorkerResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiWorkerRequestModel> patch) { ApiWorkerResponseModel record = await this.WorkerService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiWorkerRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiWorkerResponseModel> result = await this.WorkerService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiWorkerResponseModel response = await this.Client.WorkerGetAsync("A"); response.Should().NotBeNull(); }