当前位置: 首页>>代码示例>>C#>>正文


C# JsonServiceClient.Patch方法代码示例

本文整理汇总了C#中JsonServiceClient.Patch方法的典型用法代码示例。如果您正苦于以下问题:C# JsonServiceClient.Patch方法的具体用法?C# JsonServiceClient.Patch怎么用?C# JsonServiceClient.Patch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonServiceClient的用法示例。


在下文中一共展示了JsonServiceClient.Patch方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanPerform_PartialUpdate

        public void CanPerform_PartialUpdate()
        {
            var client = new JsonServiceClient("http://localhost:53990/api/");

            // back date for readability
            var created = DateTime.Now.AddHours(-2);

            // Create a record so we can patch it
            var league = new League() {Name = "BEFORE", Abbreviation = "BEFORE", DateUpdated = created, DateCreated = created};
            var newLeague = client.Post<League>(league);

            // Update Name and DateUpdated fields. Notice I don't want to update DateCreatedField.
            // I also added a fake field to show it does not cause any errors
            var updated = DateTime.Now;
            newLeague.Name = "AFTER";
            newLeague.Abbreviation = "AFTER"; // setting to after but it should not get updated
            newLeague.DateUpdated = updated;

            client.Patch<League>("http://localhost:53990/api/leagues/" + newLeague.Id + "?fields=Name,DateUpdated,thisFieldDoesNotExist", newLeague);

            var updatedLeague = client.Get<League>(newLeague);

            Assert.AreEqual(updatedLeague.Name, "AFTER");
            Assert.AreEqual(updatedLeague.Abbreviation, "BEFORE");
            Assert.AreEqual(updatedLeague.DateUpdated.ToString(), updated.ToString(), "update fields don't match");
            Assert.AreEqual(updatedLeague.DateCreated.ToString(), created.ToString(), "created fields don't match");

            // double check
            Assert.AreNotEqual(updatedLeague.DateCreated, updatedLeague.DateUpdated);
        }
开发者ID:jokecamp,项目名称:ServiceStackv4-Demo-TeamsApi,代码行数:30,代码来源:PartialUpdateTests.cs

示例2: Test_PATCH_PASS

        public void Test_PATCH_PASS()
        {
            var restClient = new JsonServiceClient(serviceUrl);

            // register callback to grab the Location: header when executed
            string lastResponseLocation = "";
            HttpStatusCode lastResponseStatusCode = 0;
            restClient.LocalHttpWebResponseFilter = httpRes =>
            {
                lastResponseLocation = httpRes.Headers[HttpHeaders.Location];
                lastResponseStatusCode = httpRes.StatusCode;
            };

            // dummy data
            var newemp1 = new Employee()
            {
                Id = 123,
                Name = "Kimo",
                StartDate = new DateTime(2015, 7, 2),
                CubicleNo = 4234,
                Email = "[email protected]",
            };
            restClient.Post<object>("/employees", newemp1);

            var emps = restClient.Get<List<Employee>>("/employees");

            var emp = emps.First();

            var empPatch = new Operations.EmployeePatch();
            empPatch.Add(new Operations.JsonPatchElement()
            {
                op = "replace",
                path = "/title",
                value = "Kahuna Laau Lapaau",
            });

            empPatch.Add(new Operations.JsonPatchElement()
            {
                op = "replace",
                path = "/cubicleno",
                value = "32",
            });

            restClient.Patch<object>(string.Format("/employees/{0}", emp.Id), empPatch);

            var empAfterPatch = restClient.Get<Employee>(string.Format("/employees/{0}", emp.Id));

            Assert.NotNull(empAfterPatch);
            // patched
            Assert.Equal("Kahuna Laau Lapaau", empAfterPatch.Title);
            Assert.Equal("32", empAfterPatch.CubicleNo.ToString());
            // unpatched
            Assert.Equal("[email protected]", empAfterPatch.Email);
        }
开发者ID:kshkrao3,项目名称:Enehana.CodeSamples,代码行数:54,代码来源:Tests_JSONPatchWithServiceStack.cs

示例3: Test_PATCH_unsupported_cast_PASS

        public void Test_PATCH_unsupported_cast_PASS()
        {
            var restClient = new JsonServiceClient(serviceUrl);

            // dummy data
            var newemp1 = new Employee()
            {
                Id = 123,
                Name = "Kimo",
                StartDate = new DateTime(2015, 7, 2),
                CubicleNo = 4234,
                Email = "[email protected]",
            };
            restClient.Post<object>("/employees", newemp1);

            var emps = restClient.Get<List<Employee>>("/employees");
            var emp = emps.First();

            var empPatch = new Operations.EmployeePatch();

            // float not currently supported by this example code
            empPatch.Add(new Operations.JsonPatchElement()
            {
                op = "replace",
                path = "/longitude",
                value = "2.123",
            });

            restClient.Patch<object>(string.Format("/employees/{0}", emp.Id), empPatch);
            
        }
开发者ID:kshkrao3,项目名称:Enehana.CodeSamples,代码行数:31,代码来源:Tests_JSONPatchWithServiceStack.cs

示例4: Test_PATCH_unsupported_cast_FAIL

        public void Test_PATCH_unsupported_cast_FAIL()
        {
            var restClient = new JsonServiceClient(serviceUrl);

            // dummy data
            var newemp1 = new Employee()
            {
                Id = 123,
                Name = "Kimo",
                StartDate = new DateTime(2015, 7, 2),
                CubicleNo = 4234,
                Email = "[email protected]",
            };
            restClient.Post<object>("/employees", newemp1);

            var emps = restClient.Get<List<Employee>>("/employees");
            var emp = emps.First();

            var empPatch = new Operations.EmployeePatch();

            // double not currently supported by this example code
            empPatch.Add(new Operations.JsonPatchElement()
            {
                op = "replace",
                path = "/othernumber",
                value = "3.1415927",
            });

            Assert.Throws<WebServiceException>(delegate
            {
                // InvalidCastException
                restClient.Patch<object>(string.Format("/employees/{0}", emp.Id), empPatch);
            });
        }
开发者ID:kshkrao3,项目名称:Enehana.CodeSamples,代码行数:34,代码来源:Tests_JSONPatchWithServiceStack.cs


注:本文中的JsonServiceClient.Patch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。