Exemplo n.º 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 ApiVehicleServerModelMapper();
            ApplicationDbContext          context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IVehicleService               service = testServer.Host.Services.GetService(typeof(IVehicleService)) as IVehicleService;
            ApiVehicleServerResponseModel model   = await service.Get(1);

            ApiVehicleClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B");

            UpdateResponse <ApiVehicleClientResponseModel> updateResponse = await client.VehicleUpdateAsync(model.Id, request);

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

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Name.Should().Be("B");
        }
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiVehicleServerModelMapper();
            var model  = new ApiVehicleServerResponseModel();

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

            response.Should().NotBeNull();
            response.Name.Should().Be("A");
        }
        public void CreatePatch()
        {
            var mapper = new ApiVehicleServerModelMapper();
            var model  = new ApiVehicleServerRequestModel();

            model.SetProperties("A");

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

            patch.ApplyTo(response);
            response.Name.Should().Be("A");
        }