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

            ApiPersonClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B");

            UpdateResponse <ApiPersonClientResponseModel> updateResponse = await client.PersonUpdateAsync(model.PersonId, request);

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

            updateResponse.Record.PersonId.Should().Be(1);
            updateResponse.Record.PersonName.Should().Be("B");
        }
예제 #2
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiPersonServerModelMapper();
            var model  = new ApiPersonServerResponseModel();

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

            response.Should().NotBeNull();
            response.PersonName.Should().Be("A");
        }
예제 #3
0
        public void CreatePatch()
        {
            var mapper = new ApiPersonServerModelMapper();
            var model  = new ApiPersonServerRequestModel();

            model.SetProperties("A");

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

            patch.ApplyTo(response);
            response.PersonName.Should().Be("A");
        }
예제 #4
0
        public void MapServerRequestToResponse()
        {
            var mapper = new ApiPersonServerModelMapper();
            var model  = new ApiPersonServerRequestModel();

            model.SetProperties("A", "A", "A", "A");
            ApiPersonServerResponseModel response = mapper.MapServerRequestToResponse(1, model);

            response.Should().NotBeNull();
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
            response.Ssn.Should().Be("A");
        }