Example #1
0
        public virtual ApiMachinePolicyResponseModel MapBOToModel(
            BOMachinePolicy boMachinePolicy)
        {
            var model = new ApiMachinePolicyResponseModel();

            model.SetProperties(boMachinePolicy.Id, boMachinePolicy.IsDefault, boMachinePolicy.JSON, boMachinePolicy.Name);

            return(model);
        }
Example #2
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiMachinePolicyModelMapper();
            var model  = new ApiMachinePolicyResponseModel();

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

            response.IsDefault.Should().Be(true);
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
Example #3
0
        public void MapBOToModel()
        {
            var             mapper = new BOLMachinePolicyMapper();
            BOMachinePolicy bo     = new BOMachinePolicy();

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

            response.Id.Should().Be("A");
            response.IsDefault.Should().Be(true);
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
Example #4
0
        public async virtual Task <IActionResult> Get(string id)
        {
            ApiMachinePolicyResponseModel response = await this.MachinePolicyService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Example #5
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IMachinePolicyRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <MachinePolicy>(null));
            var service = new MachinePolicyService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.MachinePolicyModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLMachinePolicyMapperMock,
                                                   mock.DALMapperMockFactory.DALMachinePolicyMapperMock);

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

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

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiMachinePolicyRequestModel>()));
        }
Example #7
0
        public async void All_Exists()
        {
            MachinePolicyControllerMockFacade mock = new MachinePolicyControllerMockFacade();
            var record  = new ApiMachinePolicyResponseModel();
            var records = new List <ApiMachinePolicyResponseModel>();

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

            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 <ApiMachinePolicyRequestModel> patch)
        {
            ApiMachinePolicyResponseModel record = await this.MachinePolicyService.Get(id);

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

                UpdateResponse <ApiMachinePolicyResponseModel> result = await this.MachinePolicyService.Update(id, model);

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

            response.Should().NotBeNull();
        }