public void MapModelToBO()
        {
            var mapper = new BOLTicketStatusMapper();
            ApiTicketStatusRequestModel model = new ApiTicketStatusRequestModel();

            model.SetProperties("A");
            BOTicketStatus response = mapper.MapModelToBO(1, model);

            response.Name.Should().Be("A");
        }
Example #2
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiTicketStatusModelMapper();
            var model  = new ApiTicketStatusResponseModel();

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

            response.Name.Should().Be("A");
        }
Example #3
0
        private async Task <ApiTicketStatusResponseModel> CreateRecord()
        {
            var model = new ApiTicketStatusRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiTicketStatusResponseModel> result = await this.Client.TicketStatusCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public virtual BOTicketStatus MapModelToBO(
            int id,
            ApiTicketStatusRequestModel model
            )
        {
            BOTicketStatus boTicketStatus = new BOTicketStatus();

            boTicketStatus.SetProperties(
                id,
                model.Name);
            return(boTicketStatus);
        }
Example #5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiTicketStatusRequestModel model)
        {
            CreateResponse <ApiTicketStatusResponseModel> result = await this.TicketStatusService.Create(model);

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

            model.SetProperties("A");

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

            patch.ApplyTo(response);
            response.Name.Should().Be("A");
        }
Example #7
0
        private async Task <ApiTicketStatusRequestModel> PatchModel(int id, JsonPatchDocument <ApiTicketStatusRequestModel> patch)
        {
            var record = await this.TicketStatusService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiTicketStatusRequestModel request = this.TicketStatusModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual async Task <CreateResponse <ApiTicketStatusResponseModel> > Create(
            ApiTicketStatusRequestModel model)
        {
            CreateResponse <ApiTicketStatusResponseModel> response = new CreateResponse <ApiTicketStatusResponseModel>(await this.ticketStatusModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolTicketStatusMapper.MapModelToBO(default(int), model);
                var record = await this.ticketStatusRepository.Create(this.dalTicketStatusMapper.MapBOToEF(bo));

                response.SetRecord(this.bolTicketStatusMapper.MapBOToModel(this.dalTicketStatusMapper.MapEFToBO(record)));
            }

            return(response);
        }
Example #9
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ITicketStatusRepository>();
            var model = new ApiTicketStatusRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TicketStatus>())).Returns(Task.FromResult(new TicketStatus()));
            var service = new TicketStatusService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.TicketStatusModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLTicketStatusMapperMock,
                                                  mock.DALMapperMockFactory.DALTicketStatusMapperMock,
                                                  mock.BOLMapperMockFactory.BOLTicketMapperMock,
                                                  mock.DALMapperMockFactory.DALTicketMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.TicketStatusModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTicketStatusRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TicketStatus>()));
        }
Example #10
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ITicketStatusRepository>();
            var model = new ApiTicketStatusRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new TicketStatusService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.TicketStatusModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLTicketStatusMapperMock,
                                                  mock.DALMapperMockFactory.DALTicketStatusMapperMock,
                                                  mock.BOLMapperMockFactory.BOLTicketMapperMock,
                                                  mock.DALMapperMockFactory.DALTicketMapperMock);

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

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

            if (validationResult.IsValid)
            {
                var bo = this.bolTicketStatusMapper.MapModelToBO(id, model);
                await this.ticketStatusRepository.Update(this.dalTicketStatusMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiTicketStatusResponseModel>(this.bolTicketStatusMapper.MapBOToModel(this.dalTicketStatusMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiTicketStatusResponseModel>(validationResult));
            }
        }
Example #12
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTicketStatusRequestModel model)
        {
            ApiTicketStatusRequestModel request = await this.PatchModel(id, this.TicketStatusModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiTicketStatusResponseModel> result = await this.TicketStatusService.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 <ApiTicketStatusRequestModel> patch)
        {
            ApiTicketStatusResponseModel record = await this.TicketStatusService.Get(id);

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

                UpdateResponse <ApiTicketStatusResponseModel> result = await this.TicketStatusService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Example #14
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTicketStatusRequestModel model)
 {
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }
Example #15
0
        public virtual async Task <UpdateResponse <ApiTicketStatusResponseModel> > TicketStatusUpdateAsync(int id, ApiTicketStatusRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/TicketStatus/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiTicketStatusResponseModel> >(httpResponse.Content.ContentToString()));
        }