public async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            var createModel = new ApiHandlerRequestModel();

            createModel.SetProperties(2, "B", "B", "B", "B");
            CreateResponse <ApiHandlerResponseModel> createResult = await client.HandlerCreateAsync(createModel);

            createResult.Success.Should().BeTrue();

            ApiHandlerResponseModel getResponse = await client.HandlerGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.HandlerDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();

            ApiHandlerResponseModel verifyResponse = await client.HandlerGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Beispiel #2
0
        public async void Update()
        {
            var mock  = new ServiceMockFacade <IHandlerRepository>();
            var model = new ApiHandlerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Handler>())).Returns(Task.FromResult(new Handler()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Handler()));
            var service = new HandlerService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLHandlerMapperMock,
                                             mock.DALMapperMockFactory.DALHandlerMapperMock,
                                             mock.BOLMapperMockFactory.BOLAirTransportMapperMock,
                                             mock.DALMapperMockFactory.DALAirTransportMapperMock,
                                             mock.BOLMapperMockFactory.BOLHandlerPipelineStepMapperMock,
                                             mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock,
                                             mock.BOLMapperMockFactory.BOLOtherTransportMapperMock,
                                             mock.DALMapperMockFactory.DALOtherTransportMapperMock);

            UpdateResponse <ApiHandlerResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiHandlerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Handler>()));
        }
Beispiel #3
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiHandlerRequestModel model)
 {
     this.CountryIdRules();
     this.EmailRules();
     this.FirstNameRules();
     this.LastNameRules();
     this.PhoneRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiHandlerResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiHandlerRequestModel();

            model.SetProperties(2, "B", "B", "B", "B");
            CreateResponse <ApiHandlerResponseModel> result = await client.HandlerCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Beispiel #5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiHandlerRequestModel model)
        {
            CreateResponse <ApiHandlerResponseModel> result = await this.HandlerService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Handlers/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public void MapModelToBO()
        {
            var mapper = new BOLHandlerMapper();
            ApiHandlerRequestModel model = new ApiHandlerRequestModel();

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

            response.CountryId.Should().Be(1);
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
        }
Beispiel #7
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiHandlerModelMapper();
            var model  = new ApiHandlerResponseModel();

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

            response.CountryId.Should().Be(1);
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
        }
Beispiel #8
0
        private async Task <ApiHandlerRequestModel> PatchModel(int id, JsonPatchDocument <ApiHandlerRequestModel> patch)
        {
            var record = await this.HandlerService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiHandlerRequestModel request = this.HandlerModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Beispiel #9
0
        public virtual async Task <CreateResponse <ApiHandlerResponseModel> > Create(
            ApiHandlerRequestModel model)
        {
            CreateResponse <ApiHandlerResponseModel> response = new CreateResponse <ApiHandlerResponseModel>(await this.handlerModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolHandlerMapper.MapModelToBO(default(int), model);
                var record = await this.handlerRepository.Create(this.dalHandlerMapper.MapBOToEF(bo));

                response.SetRecord(this.bolHandlerMapper.MapBOToModel(this.dalHandlerMapper.MapEFToBO(record)));
            }

            return(response);
        }
        public virtual BOHandler MapModelToBO(
            int id,
            ApiHandlerRequestModel model
            )
        {
            BOHandler boHandler = new BOHandler();

            boHandler.SetProperties(
                id,
                model.CountryId,
                model.Email,
                model.FirstName,
                model.LastName,
                model.Phone);
            return(boHandler);
        }
Beispiel #11
0
        public void CreatePatch()
        {
            var mapper = new ApiHandlerModelMapper();
            var model  = new ApiHandlerRequestModel();

            model.SetProperties(1, "A", "A", "A", "A");

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

            patch.ApplyTo(response);
            response.CountryId.Should().Be(1);
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
        }
Beispiel #12
0
        public virtual async Task <UpdateResponse <ApiHandlerResponseModel> > Update(
            int id,
            ApiHandlerRequestModel model)
        {
            var validationResult = await this.handlerModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolHandlerMapper.MapModelToBO(id, model);
                await this.handlerRepository.Update(this.dalHandlerMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiHandlerResponseModel>(this.bolHandlerMapper.MapBOToModel(this.dalHandlerMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiHandlerResponseModel>(validationResult));
            }
        }
Beispiel #13
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IHandlerRepository>();
            var model = new ApiHandlerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new HandlerService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLHandlerMapperMock,
                                             mock.DALMapperMockFactory.DALHandlerMapperMock,
                                             mock.BOLMapperMockFactory.BOLAirTransportMapperMock,
                                             mock.DALMapperMockFactory.DALAirTransportMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Beispiel #14
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiHandlerRequestModel model)
        {
            ApiHandlerRequestModel request = await this.PatchModel(id, this.HandlerModelMapper.CreatePatch(model));

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

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

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

                UpdateResponse <ApiHandlerResponseModel> result = await this.HandlerService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }