public virtual ApiProjectGroupResponseModel MapBOToModel(
            BOProjectGroup boProjectGroup)
        {
            var model = new ApiProjectGroupResponseModel();

            model.SetProperties(boProjectGroup.Id, boProjectGroup.DataVersion, boProjectGroup.JSON, boProjectGroup.Name);

            return(model);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiProjectGroupModelMapper();
            var model  = new ApiProjectGroupResponseModel();

            model.SetProperties("A", BitConverter.GetBytes(1), "A", "A");
            ApiProjectGroupRequestModel response = mapper.MapResponseToRequest(model);

            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
        public async virtual Task <IActionResult> Get(string id)
        {
            ApiProjectGroupResponseModel response = await this.ProjectGroupService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Beispiel #4
0
        public void MapBOToModel()
        {
            var            mapper = new BOLProjectGroupMapper();
            BOProjectGroup bo     = new BOProjectGroup();

            bo.SetProperties("A", BitConverter.GetBytes(1), "A", "A");
            ApiProjectGroupResponseModel response = mapper.MapBOToModel(bo);

            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.Id.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IProjectGroupRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <ProjectGroup>(null));
            var service = new ProjectGroupService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.ProjectGroupModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLProjectGroupMapperMock,
                                                  mock.DALMapperMockFactory.DALProjectGroupMapperMock);

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

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

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

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

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

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

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

            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 <ApiProjectGroupRequestModel> patch)
        {
            ApiProjectGroupResponseModel record = await this.ProjectGroupService.Get(id);

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

                UpdateResponse <ApiProjectGroupResponseModel> result = await this.ProjectGroupService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public async void TestGet()
        {
            ApiProjectGroupResponseModel response = await this.Client.ProjectGroupGetAsync("A");

            response.Should().NotBeNull();
        }