Пример #1
0
        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 ApiPipelineStepRequestModel();

            createModel.SetProperties("B", 1, 1);
            CreateResponse <ApiPipelineStepResponseModel> createResult = await client.PipelineStepCreateAsync(createModel);

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

            ApiPipelineStepResponseModel getResponse = await client.PipelineStepGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.PipelineStepDeleteAsync(2);

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

            ApiPipelineStepResponseModel verifyResponse = await client.PipelineStepGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Пример #2
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IPipelineStepRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <PipelineStep>(null));
            var service = new PipelineStepService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.PipelineStepModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLPipelineStepMapperMock,
                                                  mock.DALMapperMockFactory.DALPipelineStepMapperMock,
                                                  mock.BOLMapperMockFactory.BOLHandlerPipelineStepMapperMock,
                                                  mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock,
                                                  mock.BOLMapperMockFactory.BOLOtherTransportMapperMock,
                                                  mock.DALMapperMockFactory.DALOtherTransportMapperMock,
                                                  mock.BOLMapperMockFactory.BOLPipelineStepDestinationMapperMock,
                                                  mock.DALMapperMockFactory.DALPipelineStepDestinationMapperMock,
                                                  mock.BOLMapperMockFactory.BOLPipelineStepNoteMapperMock,
                                                  mock.DALMapperMockFactory.DALPipelineStepNoteMapperMock,
                                                  mock.BOLMapperMockFactory.BOLPipelineStepStepRequirementMapperMock,
                                                  mock.DALMapperMockFactory.DALPipelineStepStepRequirementMapperMock);

            ApiPipelineStepResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public virtual ApiPipelineStepResponseModel MapBOToModel(
            BOPipelineStep boPipelineStep)
        {
            var model = new ApiPipelineStepResponseModel();

            model.SetProperties(boPipelineStep.Id, boPipelineStep.Name, boPipelineStep.PipelineStepStatusId, boPipelineStep.ShipperId);

            return(model);
        }
Пример #4
0
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiPipelineStepResponseModel response = await client.PipelineStepGetAsync(1);

            response.Should().NotBeNull();
        }
Пример #5
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiPipelineStepModelMapper();
            var model  = new ApiPipelineStepResponseModel();

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

            response.Name.Should().Be("A");
            response.PipelineStepStatusId.Should().Be(1);
            response.ShipperId.Should().Be(1);
        }
Пример #6
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiPipelineStepResponseModel response = await this.PipelineStepService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Пример #7
0
        public void MapBOToModel()
        {
            var            mapper = new BOLPipelineStepMapper();
            BOPipelineStep bo     = new BOPipelineStep();

            bo.SetProperties(1, "A", 1, 1);
            ApiPipelineStepResponseModel response = mapper.MapBOToModel(bo);

            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
            response.PipelineStepStatusId.Should().Be(1);
            response.ShipperId.Should().Be(1);
        }
Пример #8
0
        public async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

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

            ApiPipelineStepResponseModel model = await client.PipelineStepGetAsync(1);

            ApiPipelineStepModelMapper mapper = new ApiPipelineStepModelMapper();

            UpdateResponse <ApiPipelineStepResponseModel> updateResponse = await client.PipelineStepUpdateAsync(model.Id, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
        public async void Create_Errors()
        {
            PipelineStepControllerMockFacade mock = new PipelineStepControllerMockFacade();

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPipelineStepRequestModel>()));
        }
        public async void All_Exists()
        {
            PipelineStepControllerMockFacade mock = new PipelineStepControllerMockFacade();
            var record  = new ApiPipelineStepResponseModel();
            var records = new List <ApiPipelineStepResponseModel>();

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Пример #11
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiPipelineStepRequestModel> patch)
        {
            ApiPipelineStepResponseModel record = await this.PipelineStepService.Get(id);

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

                UpdateResponse <ApiPipelineStepResponseModel> result = await this.PipelineStepService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Пример #12
0
        public async void TestGet()
        {
            ApiPipelineStepResponseModel response = await this.Client.PipelineStepGetAsync(1);

            response.Should().NotBeNull();
        }