Beispiel #1
0
        public void WorkItemRemovals()
        {
            var before = GetBaselineWorkItem();
            var after  = GetBaselineWorkItem();

            after.Relations.Remove(after.Relations.First(item => item.Index == 19));
            after.Relations.Remove(after.Relations.First(item => item.Index == 12));
            after.Relations.Remove(after.Relations.First(item => item.Index == 0));

            var patch = JsonPatchBuilder.GenerateDeltaPatch <ADOWorkItem>(before, after);

            Assert.AreEqual(3, patch.PatchCount);

            AssertJsonContains(patch, JArray.FromObject(new dynamic[]
            {
                new
                {
                    op   = "remove",
                    path = "/relations/0"
                },
                new
                {
                    op   = "remove",
                    path = "/relations/12"
                },
                new
                {
                    op   = "remove",
                    path = "/relations/19"
                }
            }));
        }
Beispiel #2
0
        public void WorkItemAdditions()
        {
            ADOWorkItem from = GetBaselineWorkItem();
            ADOWorkItem to   = GetBaselineWorkItem();

            var patchFromEmpty = JsonPatchBuilder.GenerateDeltaPatch(new ADOWorkItem(), to);

            AssertJsonContains(patchFromEmpty, JObject.FromObject(new
            {
                op    = "add",
                path  = "/id",
                value = to.Id
            }));
            AssertJsonContains(patchFromEmpty, JObject.FromObject(new
            {
                op    = "add",
                path  = "/fields/System.Title",
                value = to.Title
            }));

            var patch = JsonPatchBuilder.GenerateDeltaPatch(from, to);

            Assert.AreEqual(0, patch.PatchCount);

            to.AssignedTo = new ADOPerson()
            {
                DisplayName = "John Doe", Email = "*****@*****.**"
            };
            to.Relations.Add(new ADOWorkItemRelationInfo()
            {
                Name = "Test Name", Type = "Test Type"
            });
            patch = JsonPatchBuilder.GenerateDeltaPatch(from, to);
            Assert.AreEqual(2, patch.PatchCount);
            AssertJsonContains(patch, JObject.FromObject(new
            {
                op    = "add",
                path  = "/fields/System.AssignedTo",
                value = new
                {
                    uniqueName = to.AssignedTo.Email
                }
            }));
            AssertJsonContains(patch, JObject.FromObject(new
            {
                op    = "add",
                path  = "/relations/-",
                value = new
                {
                    rel        = "ArtifactLink",
                    url        = (string)null,
                    attributes = new
                    {
                        name = "Test Name"
                    }
                }
            }));
        }
Beispiel #3
0
        public void WorkItemMixedOperations()
        {
            var before = GetBaselineWorkItem();
            var after  = GetBaselineWorkItem();

            after.Title = "Modified title";
            after.State = null;
            after.Relations.Remove(after.Relations.First(item => item.Index == 12));
            after.Relations.Add(new ADOWorkItemRelationInfo()
            {
                Name = "New relation name",
                Url  = "New relation url"
            });

            var patch = JsonPatchBuilder.GenerateDeltaPatch(before, after);

            Assert.AreEqual(4, patch.PatchCount);
            AssertJsonContains(patch, JObject.FromObject(new
            {
                op    = "replace",
                path  = "/fields/System.Title",
                value = "Modified title"
            }));
            AssertJsonContains(patch, JObject.FromObject(new
            {
                op   = "remove",
                path = "/fields/System.State"
            }));
            AssertJsonContains(patch, JObject.FromObject(new
            {
                op   = "remove",
                path = "/relations/12"
            }));
            AssertJsonContains(patch, JObject.FromObject(new
            {
                op    = "add",
                path  = "/relations/-",
                value = new
                {
                    rel        = "ArtifactLink",
                    url        = "New relation url",
                    attributes = new
                    {
                        name = "New relation name"
                    },
                }
            }));
        }