Example #1
0
        public virtual ApiWorkerTaskLeaseResponseModel MapBOToModel(
            BOWorkerTaskLease boWorkerTaskLease)
        {
            var model = new ApiWorkerTaskLeaseResponseModel();

            model.SetProperties(boWorkerTaskLease.Id, boWorkerTaskLease.Exclusive, boWorkerTaskLease.JSON, boWorkerTaskLease.Name, boWorkerTaskLease.TaskId, boWorkerTaskLease.WorkerId);

            return(model);
        }
Example #2
0
        public async virtual Task <IActionResult> Get(string id)
        {
            ApiWorkerTaskLeaseResponseModel response = await this.WorkerTaskLeaseService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiWorkerTaskLeaseModelMapper();
            var model  = new ApiWorkerTaskLeaseResponseModel();

            model.SetProperties("A", true, "A", "A", "A", "A");
            ApiWorkerTaskLeaseRequestModel response = mapper.MapResponseToRequest(model);

            response.Exclusive.Should().Be(true);
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.TaskId.Should().Be("A");
            response.WorkerId.Should().Be("A");
        }
Example #4
0
        public void MapBOToModel()
        {
            var mapper           = new BOLWorkerTaskLeaseMapper();
            BOWorkerTaskLease bo = new BOWorkerTaskLease();

            bo.SetProperties("A", true, "A", "A", "A", "A");
            ApiWorkerTaskLeaseResponseModel response = mapper.MapBOToModel(bo);

            response.Exclusive.Should().Be(true);
            response.Id.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.TaskId.Should().Be("A");
            response.WorkerId.Should().Be("A");
        }
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IWorkerTaskLeaseRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <WorkerTaskLease>(null));
            var service = new WorkerTaskLeaseService(mock.LoggerMock.Object,
                                                     mock.RepositoryMock.Object,
                                                     mock.ModelValidatorMockFactory.WorkerTaskLeaseModelValidatorMock.Object,
                                                     mock.BOLMapperMockFactory.BOLWorkerTaskLeaseMapperMock,
                                                     mock.DALMapperMockFactory.DALWorkerTaskLeaseMapperMock);

            ApiWorkerTaskLeaseResponseModel response = await service.Get(default(string));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>()));
        }
        public async void Create_Errors()
        {
            WorkerTaskLeaseControllerMockFacade mock = new WorkerTaskLeaseControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiWorkerTaskLeaseResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiWorkerTaskLeaseResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiWorkerTaskLeaseRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiWorkerTaskLeaseResponseModel> >(mockResponse.Object));
            WorkerTaskLeaseController controller = new WorkerTaskLeaseController(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 ApiWorkerTaskLeaseRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiWorkerTaskLeaseRequestModel>()));
        }
        public async void All_Exists()
        {
            WorkerTaskLeaseControllerMockFacade mock = new WorkerTaskLeaseControllerMockFacade();
            var record  = new ApiWorkerTaskLeaseResponseModel();
            var records = new List <ApiWorkerTaskLeaseResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            WorkerTaskLeaseController controller = new WorkerTaskLeaseController(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 <ApiWorkerTaskLeaseResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Example #8
0
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiWorkerTaskLeaseRequestModel> patch)
        {
            ApiWorkerTaskLeaseResponseModel record = await this.WorkerTaskLeaseService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiWorkerTaskLeaseRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiWorkerTaskLeaseResponseModel> result = await this.WorkerTaskLeaseService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Example #9
0
        public async void TestGet()
        {
            ApiWorkerTaskLeaseResponseModel response = await this.Client.WorkerTaskLeaseGetAsync("A");

            response.Should().NotBeNull();
        }