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;

            IAirTransportService service = testServer.Host.Services.GetService(typeof(IAirTransportService)) as IAirTransportService;
            var model = new ApiAirTransportServerRequestModel();

            model.SetProperties(2, "B", 1, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, DateTime.Parse("1/1/1988 12:00:00 AM"));
            CreateResponse <ApiAirTransportServerResponseModel> createdResponse = await service.Create(model);

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

            ActionResponse deleteResult = await client.AirTransportDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
Пример #2
0
        public virtual async Task <IActionResult> Create([FromBody] ApiAirTransportServerRequestModel model)
        {
            CreateResponse <ApiAirTransportServerResponseModel> result = await this.AirTransportService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/AirTransports/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Пример #3
0
        private async Task <ApiAirTransportServerRequestModel> PatchModel(int id, JsonPatchDocument <ApiAirTransportServerRequestModel> patch)
        {
            var record = await this.AirTransportService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiAirTransportServerRequestModel request = this.AirTransportModelMapper.MapServerResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiAirTransportServerModelMapper();
            var model  = new ApiAirTransportServerResponseModel();

            model.SetProperties(1, 1, "A", 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, DateTime.Parse("1/1/1987 12:00:00 AM"));
            ApiAirTransportServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.AirlineId.Should().Be(1);
            response.FlightNumber.Should().Be("A");
            response.HandlerId.Should().Be(1);
            response.LandDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PipelineStepId.Should().Be(1);
            response.TakeoffDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
        }
        public void CreatePatch()
        {
            var mapper = new ApiAirTransportServerModelMapper();
            var model  = new ApiAirTransportServerRequestModel();

            model.SetProperties(1, "A", 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, DateTime.Parse("1/1/1987 12:00:00 AM"));

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

            patch.ApplyTo(response);
            response.AirlineId.Should().Be(1);
            response.FlightNumber.Should().Be("A");
            response.HandlerId.Should().Be(1);
            response.LandDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PipelineStepId.Should().Be(1);
            response.TakeoffDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
        }
Пример #6
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IAirTransportService, IAirTransportRepository>();
            var model = new ApiAirTransportServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new AirTransportService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.AirTransportModelValidatorMock.Object,
                                                  mock.DALMapperMockFactory.DALAirTransportMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.AirTransportModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <AirTransportDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
Пример #7
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiAirTransportServerRequestModel model)
        {
            ApiAirTransportServerRequestModel request = await this.PatchModel(id, this.AirTransportModelMapper.CreatePatch(model)) as ApiAirTransportServerRequestModel;

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Пример #8
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IAirTransportService, IAirTransportRepository>();
            var model         = new ApiAirTransportServerRequestModel();
            var validatorMock = new Mock <IApiAirTransportServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new AirTransportService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  validatorMock.Object,
                                                  mock.DALMapperMockFactory.DALAirTransportMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <AirTransportDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Пример #9
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiAirTransportServerRequestModel> patch)
        {
            ApiAirTransportServerResponseModel record = await this.AirTransportService.Get(id);

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

                UpdateResponse <ApiAirTransportServerResponseModel> result = await this.AirTransportService.Update(id, model);

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