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 ApiVehCapabilityServerModelMapper();
            ApplicationDbContext  context             = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IVehCapabilityService service             = testServer.Host.Services.GetService(typeof(IVehCapabilityService)) as IVehCapabilityService;
            ApiVehCapabilityServerResponseModel model = await service.Get(1);

            ApiVehCapabilityClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B");

            UpdateResponse <ApiVehCapabilityClientResponseModel> updateResponse = await client.VehCapabilityUpdateAsync(model.Id, request);

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

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Name.Should().Be("B");
        }
        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;

            IVehCapabilityService service = testServer.Host.Services.GetService(typeof(IVehCapabilityService)) as IVehCapabilityService;
            var model = new ApiVehCapabilityServerRequestModel();

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

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

            ActionResponse deleteResult = await client.VehCapabilityDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiVehCapabilityServerModelMapper();
            var model  = new ApiVehCapabilityServerResponseModel();

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

            response.Should().NotBeNull();
            response.Name.Should().Be("A");
        }
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiVehCapabilityServerResponseModel response = await this.VehCapabilityService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Esempio n. 5
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IVehCapabilityService, IVehCapabilityRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <VehCapability>(null));
            var service = new VehCapabilityService(mock.LoggerMock.Object,
                                                   mock.MediatorMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.VehCapabilityModelValidatorMock.Object,
                                                   mock.DALMapperMockFactory.DALVehCapabilityMapperMock,
                                                   mock.DALMapperMockFactory.DALVehicleCapabilitiesMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public async void Create_Errors()
        {
            VehCapabilityControllerMockFacade mock = new VehCapabilityControllerMockFacade();

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

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

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

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

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

            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 <ApiVehCapabilityServerRequestModel> patch)
        {
            ApiVehCapabilityServerResponseModel record = await this.VehCapabilityService.Get(id);

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

                UpdateResponse <ApiVehCapabilityServerResponseModel> result = await this.VehCapabilityService.Update(id, model);

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