private async Task <ApiSaleTicketsResponseModel> CreateRecord()
        {
            var model = new ApiSaleTicketsRequestModel();

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

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Beispiel #2
0
        public void MapModelToBO()
        {
            var mapper = new BOLSaleTicketsMapper();
            ApiSaleTicketsRequestModel model = new ApiSaleTicketsRequestModel();

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

            response.SaleId.Should().Be(1);
            response.TicketId.Should().Be(1);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiSaleTicketsModelMapper();
            var model  = new ApiSaleTicketsResponseModel();

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

            response.SaleId.Should().Be(1);
            response.TicketId.Should().Be(1);
        }
Beispiel #4
0
        public virtual async Task <IActionResult> Create([FromBody] ApiSaleTicketsRequestModel model)
        {
            CreateResponse <ApiSaleTicketsResponseModel> result = await this.SaleTicketsService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/SaleTickets/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public virtual BOSaleTickets MapModelToBO(
            int id,
            ApiSaleTicketsRequestModel model
            )
        {
            BOSaleTickets boSaleTickets = new BOSaleTickets();

            boSaleTickets.SetProperties(
                id,
                model.SaleId,
                model.TicketId);
            return(boSaleTickets);
        }
        public void CreatePatch()
        {
            var mapper = new ApiSaleTicketsModelMapper();
            var model  = new ApiSaleTicketsRequestModel();

            model.SetProperties(1, 1);

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

            patch.ApplyTo(response);
            response.SaleId.Should().Be(1);
            response.TicketId.Should().Be(1);
        }
Beispiel #7
0
        private async Task <ApiSaleTicketsRequestModel> PatchModel(int id, JsonPatchDocument <ApiSaleTicketsRequestModel> patch)
        {
            var record = await this.SaleTicketsService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiSaleTicketsRequestModel request = this.SaleTicketsModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Beispiel #8
0
        public virtual async Task <CreateResponse <ApiSaleTicketsResponseModel> > Create(
            ApiSaleTicketsRequestModel model)
        {
            CreateResponse <ApiSaleTicketsResponseModel> response = new CreateResponse <ApiSaleTicketsResponseModel>(await this.saleTicketsModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolSaleTicketsMapper.MapModelToBO(default(int), model);
                var record = await this.saleTicketsRepository.Create(this.dalSaleTicketsMapper.MapBOToEF(bo));

                response.SetRecord(this.bolSaleTicketsMapper.MapBOToModel(this.dalSaleTicketsMapper.MapEFToBO(record)));
            }

            return(response);
        }
Beispiel #9
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ISaleTicketsRepository>();
            var model = new ApiSaleTicketsRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <SaleTickets>())).Returns(Task.FromResult(new SaleTickets()));
            var service = new SaleTicketsService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLSaleTicketsMapperMock,
                                                 mock.DALMapperMockFactory.DALSaleTicketsMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSaleTicketsRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <SaleTickets>()));
        }
Beispiel #10
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ISaleTicketsRepository>();
            var model = new ApiSaleTicketsRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new SaleTicketsService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLSaleTicketsMapperMock,
                                                 mock.DALMapperMockFactory.DALSaleTicketsMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Beispiel #11
0
        public virtual async Task <UpdateResponse <ApiSaleTicketsResponseModel> > Update(
            int id,
            ApiSaleTicketsRequestModel model)
        {
            var validationResult = await this.saleTicketsModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolSaleTicketsMapper.MapModelToBO(id, model);
                await this.saleTicketsRepository.Update(this.dalSaleTicketsMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiSaleTicketsResponseModel>(this.bolSaleTicketsMapper.MapBOToModel(this.dalSaleTicketsMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiSaleTicketsResponseModel>(validationResult));
            }
        }
Beispiel #12
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiSaleTicketsRequestModel model)
        {
            ApiSaleTicketsRequestModel request = await this.PatchModel(id, this.SaleTicketsModelMapper.CreatePatch(model));

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

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

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

                UpdateResponse <ApiSaleTicketsResponseModel> result = await this.SaleTicketsService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #14
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSaleTicketsRequestModel model)
 {
     this.SaleIdRules();
     this.TicketIdRules();
     return(await this.ValidateAsync(model, id));
 }
Beispiel #15
0
        public virtual async Task <UpdateResponse <ApiSaleTicketsResponseModel> > SaleTicketsUpdateAsync(int id, ApiSaleTicketsRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/SaleTickets/{id}", item).ConfigureAwait(false);

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