Example #1
0
        public virtual ApiPostHistoryTypesResponseModel MapBOToModel(
            BOPostHistoryTypes boPostHistoryTypes)
        {
            var model = new ApiPostHistoryTypesResponseModel();

            model.SetProperties(boPostHistoryTypes.Id, boPostHistoryTypes.Type);

            return(model);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiPostHistoryTypesModelMapper();
            var model  = new ApiPostHistoryTypesResponseModel();

            model.SetProperties(1, "A");
            ApiPostHistoryTypesRequestModel response = mapper.MapResponseToRequest(model);

            response.Type.Should().Be("A");
        }
        public void MapBOToModel()
        {
            var mapper            = new BOLPostHistoryTypesMapper();
            BOPostHistoryTypes bo = new BOPostHistoryTypes();

            bo.SetProperties(1, "A");
            ApiPostHistoryTypesResponseModel response = mapper.MapBOToModel(bo);

            response.Id.Should().Be(1);
            response.Type.Should().Be("A");
        }
Example #4
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiPostHistoryTypesResponseModel response = await this.PostHistoryTypesService.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 <IPostHistoryTypesRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <PostHistoryTypes>(null));
            var service = new PostHistoryTypesService(mock.LoggerMock.Object,
                                                      mock.RepositoryMock.Object,
                                                      mock.ModelValidatorMockFactory.PostHistoryTypesModelValidatorMock.Object,
                                                      mock.BOLMapperMockFactory.BOLPostHistoryTypesMapperMock,
                                                      mock.DALMapperMockFactory.DALPostHistoryTypesMapperMock);

            ApiPostHistoryTypesResponseModel response = await service.Get(default(int));

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

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

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

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

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

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

            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(int id, [FromBody] JsonPatchDocument <ApiPostHistoryTypesRequestModel> patch)
        {
            ApiPostHistoryTypesResponseModel record = await this.PostHistoryTypesService.Get(id);

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

                UpdateResponse <ApiPostHistoryTypesResponseModel> result = await this.PostHistoryTypesService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public async void TestGet()
        {
            ApiPostHistoryTypesResponseModel response = await this.Client.PostHistoryTypesGetAsync(1);

            response.Should().NotBeNull();
        }