Пример #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 ApiVehicleOfficerServerModelMapper();
            ApplicationDbContext   context             = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IVehicleOfficerService service             = testServer.Host.Services.GetService(typeof(IVehicleOfficerService)) as IVehicleOfficerService;
            ApiVehicleOfficerServerResponseModel model = await service.Get(1);

            ApiVehicleOfficerClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(1, 1);

            UpdateResponse <ApiVehicleOfficerClientResponseModel> updateResponse = await client.VehicleOfficerUpdateAsync(model.Id, request);

            context.Entry(context.Set <VehicleOfficer>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <VehicleOfficer>().ToList()[0].OfficerId.Should().Be(1);
            context.Set <VehicleOfficer>().ToList()[0].VehicleId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.OfficerId.Should().Be(1);
            updateResponse.Record.VehicleId.Should().Be(1);
        }
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiVehicleOfficerServerModelMapper();
            var model  = new ApiVehicleOfficerServerResponseModel();

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

            response.Should().NotBeNull();
            response.OfficerId.Should().Be(1);
            response.VehicleId.Should().Be(1);
        }
        public void CreatePatch()
        {
            var mapper = new ApiVehicleOfficerServerModelMapper();
            var model  = new ApiVehicleOfficerServerRequestModel();

            model.SetProperties(1, 1);

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

            patch.ApplyTo(response);
            response.OfficerId.Should().Be(1);
            response.VehicleId.Should().Be(1);
        }