private async Task <ApiMachineRefTeamResponseModel> CreateRecord()
        {
            var model = new ApiMachineRefTeamRequestModel();

            model.SetProperties(1, 1);
            CreateResponse <ApiMachineRefTeamResponseModel> result = await this.Client.MachineRefTeamCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Example #2
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiMachineRefTeamModelMapper();
            var model  = new ApiMachineRefTeamResponseModel();

            model.SetProperties(1, 1, 1);
            ApiMachineRefTeamRequestModel response = mapper.MapResponseToRequest(model);

            response.MachineId.Should().Be(1);
            response.TeamId.Should().Be(1);
        }
        public void MapModelToBO()
        {
            var mapper = new BOLMachineRefTeamMapper();
            ApiMachineRefTeamRequestModel model = new ApiMachineRefTeamRequestModel();

            model.SetProperties(1, 1);
            BOMachineRefTeam response = mapper.MapModelToBO(1, model);

            response.MachineId.Should().Be(1);
            response.TeamId.Should().Be(1);
        }
Example #4
0
        public virtual BOMachineRefTeam MapModelToBO(
            int id,
            ApiMachineRefTeamRequestModel model
            )
        {
            BOMachineRefTeam boMachineRefTeam = new BOMachineRefTeam();

            boMachineRefTeam.SetProperties(
                id,
                model.MachineId,
                model.TeamId);
            return(boMachineRefTeam);
        }
Example #5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiMachineRefTeamRequestModel model)
        {
            CreateResponse <ApiMachineRefTeamResponseModel> result = await this.MachineRefTeamService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/MachineRefTeams/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Example #6
0
        public void CreatePatch()
        {
            var mapper = new ApiMachineRefTeamModelMapper();
            var model  = new ApiMachineRefTeamRequestModel();

            model.SetProperties(1, 1);

            JsonPatchDocument <ApiMachineRefTeamRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiMachineRefTeamRequestModel();

            patch.ApplyTo(response);
            response.MachineId.Should().Be(1);
            response.TeamId.Should().Be(1);
        }
        public virtual async Task <CreateResponse <ApiMachineRefTeamResponseModel> > Create(
            ApiMachineRefTeamRequestModel model)
        {
            CreateResponse <ApiMachineRefTeamResponseModel> response = new CreateResponse <ApiMachineRefTeamResponseModel>(await this.machineRefTeamModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolMachineRefTeamMapper.MapModelToBO(default(int), model);
                var record = await this.machineRefTeamRepository.Create(this.dalMachineRefTeamMapper.MapBOToEF(bo));

                response.SetRecord(this.bolMachineRefTeamMapper.MapBOToModel(this.dalMachineRefTeamMapper.MapEFToBO(record)));
            }

            return(response);
        }
Example #8
0
        private async Task <ApiMachineRefTeamRequestModel> PatchModel(int id, JsonPatchDocument <ApiMachineRefTeamRequestModel> patch)
        {
            var record = await this.MachineRefTeamService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiMachineRefTeamRequestModel request = this.MachineRefTeamModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IMachineRefTeamRepository>();
            var model = new ApiMachineRefTeamRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <MachineRefTeam>())).Returns(Task.FromResult(new MachineRefTeam()));
            var service = new MachineRefTeamService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.MachineRefTeamModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLMachineRefTeamMapperMock,
                                                    mock.DALMapperMockFactory.DALMachineRefTeamMapperMock);

            CreateResponse <ApiMachineRefTeamResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.MachineRefTeamModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiMachineRefTeamRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <MachineRefTeam>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IMachineRefTeamRepository>();
            var model = new ApiMachineRefTeamRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new MachineRefTeamService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.MachineRefTeamModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLMachineRefTeamMapperMock,
                                                    mock.DALMapperMockFactory.DALMachineRefTeamMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.MachineRefTeamModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
        public virtual async Task <UpdateResponse <ApiMachineRefTeamResponseModel> > Update(
            int id,
            ApiMachineRefTeamRequestModel model)
        {
            var validationResult = await this.machineRefTeamModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolMachineRefTeamMapper.MapModelToBO(id, model);
                await this.machineRefTeamRepository.Update(this.dalMachineRefTeamMapper.MapBOToEF(bo));

                var record = await this.machineRefTeamRepository.Get(id);

                return(new UpdateResponse <ApiMachineRefTeamResponseModel>(this.bolMachineRefTeamMapper.MapBOToModel(this.dalMachineRefTeamMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiMachineRefTeamResponseModel>(validationResult));
            }
        }
Example #12
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiMachineRefTeamRequestModel model)
        {
            ApiMachineRefTeamRequestModel request = await this.PatchModel(id, this.MachineRefTeamModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiMachineRefTeamResponseModel> result = await this.MachineRefTeamService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Example #13
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiMachineRefTeamRequestModel> patch)
        {
            ApiMachineRefTeamResponseModel record = await this.MachineRefTeamService.Get(id);

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

                UpdateResponse <ApiMachineRefTeamResponseModel> result = await this.MachineRefTeamService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Example #14
0
        public virtual async Task <UpdateResponse <ApiMachineRefTeamResponseModel> > MachineRefTeamUpdateAsync(int id, ApiMachineRefTeamRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/MachineRefTeams/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiMachineRefTeamResponseModel> >(httpResponse.Content.ContentToString()));
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiMachineRefTeamRequestModel model)
 {
     this.MachineIdRules();
     this.TeamIdRules();
     return(await this.ValidateAsync(model, id));
 }