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

            ApiUnitClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B");

            UpdateResponse <ApiUnitClientResponseModel> updateResponse = await client.UnitUpdateAsync(model.Id, request);

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

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.CallSign.Should().Be("B");
        }
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiUnitServerModelMapper();
            var model  = new ApiUnitServerResponseModel();

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

            response.Should().NotBeNull();
            response.CallSign.Should().Be("A");
        }
        public void CreatePatch()
        {
            var mapper = new ApiUnitServerModelMapper();
            var model  = new ApiUnitServerRequestModel();

            model.SetProperties("A");

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

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