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

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

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            var mapper = new ApiPipelineStepServerModelMapper();
            ApplicationDbContext context             = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IPipelineStepService service             = testServer.Host.Services.GetService(typeof(IPipelineStepService)) as IPipelineStepService;
            ApiPipelineStepServerResponseModel model = await service.Get(1);

            ApiPipelineStepClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B", 1, 1);

            UpdateResponse <ApiPipelineStepClientResponseModel> updateResponse = await client.PipelineStepUpdateAsync(model.Id, request);

            context.Entry(context.Set <PipelineStep>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <PipelineStep>().ToList()[0].Name.Should().Be("B");
            context.Set <PipelineStep>().ToList()[0].PipelineStepStatusId.Should().Be(1);
            context.Set <PipelineStep>().ToList()[0].ShipperId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Name.Should().Be("B");
            updateResponse.Record.PipelineStepStatusId.Should().Be(1);
            updateResponse.Record.ShipperId.Should().Be(1);
        }
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IPipelineStepService service = testServer.Host.Services.GetService(typeof(IPipelineStepService)) as IPipelineStepService;
            var model = new ApiPipelineStepServerRequestModel();

            model.SetProperties("B", 1, 1);
            CreateResponse <ApiPipelineStepServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.PipelineStepDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiPipelineStepServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Ejemplo n.º 3
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiPipelineStepServerResponseModel response = await this.PipelineStepService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Ejemplo n.º 4
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiPipelineStepServerModelMapper();
            var model  = new ApiPipelineStepServerResponseModel();

            model.SetProperties(1, "A", 1, 1);
            ApiPipelineStepServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.Name.Should().Be("A");
            response.PipelineStepStatusId.Should().Be(1);
            response.ShipperId.Should().Be(1);
        }
Ejemplo n.º 5
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IPipelineStepService, IPipelineStepRepository>();

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

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Ejemplo n.º 6
0
        public async void Create_Errors()
        {
            PipelineStepControllerMockFacade mock = new PipelineStepControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiPipelineStepServerResponseModel> >(null as ApiPipelineStepServerResponseModel);
            var mockRecord   = new ApiPipelineStepServerResponseModel();

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiPipelineStepServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiPipelineStepServerResponseModel> >(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 ApiPipelineStepServerRequestModel());

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

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).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, string.Empty);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiPipelineStepServerResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Ejemplo n.º 8
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiPipelineStepServerRequestModel> patch)
        {
            ApiPipelineStepServerResponseModel record = await this.PipelineStepService.Get(id);

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

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

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