예제 #1
0
        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 ApiOtherTransportServerModelMapper();
            ApplicationDbContext   context             = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IOtherTransportService service             = testServer.Host.Services.GetService(typeof(IOtherTransportService)) as IOtherTransportService;
            ApiOtherTransportServerResponseModel model = await service.Get(1);

            ApiOtherTransportClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(1, 1);

            UpdateResponse <ApiOtherTransportClientResponseModel> updateResponse = await client.OtherTransportUpdateAsync(model.Id, request);

            context.Entry(context.Set <OtherTransport>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <OtherTransport>().ToList()[0].HandlerId.Should().Be(1);
            context.Set <OtherTransport>().ToList()[0].PipelineStepId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.HandlerId.Should().Be(1);
            updateResponse.Record.PipelineStepId.Should().Be(1);
        }
예제 #2
0
        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;

            IOtherTransportService service = testServer.Host.Services.GetService(typeof(IOtherTransportService)) as IOtherTransportService;
            var model = new ApiOtherTransportServerRequestModel();

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

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

            ActionResponse deleteResult = await client.OtherTransportDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
예제 #3
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiOtherTransportServerModelMapper();
            var model  = new ApiOtherTransportServerResponseModel();

            model.SetProperties(1, 1, 1);
            ApiOtherTransportServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.HandlerId.Should().Be(1);
            response.PipelineStepId.Should().Be(1);
        }
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiOtherTransportServerResponseModel response = await this.OtherTransportService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IOtherTransportService, IOtherTransportRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <OtherTransport>(null));
            var service = new OtherTransportService(mock.LoggerMock.Object,
                                                    mock.MediatorMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.OtherTransportModelValidatorMock.Object,
                                                    mock.DALMapperMockFactory.DALOtherTransportMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
예제 #6
0
        public async void Create_Errors()
        {
            OtherTransportControllerMockFacade mock = new OtherTransportControllerMockFacade();

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiOtherTransportServerRequestModel>()));
        }
예제 #7
0
        public async void All_Exists()
        {
            OtherTransportControllerMockFacade mock = new OtherTransportControllerMockFacade();
            var record  = new ApiOtherTransportServerResponseModel();
            var records = new List <ApiOtherTransportServerResponseModel>();

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiOtherTransportServerRequestModel> patch)
        {
            ApiOtherTransportServerResponseModel record = await this.OtherTransportService.Get(id);

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

                UpdateResponse <ApiOtherTransportServerResponseModel> result = await this.OtherTransportService.Update(id, model);

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