예제 #1
0
        public void CanBuildAdd()
        {
            // Arrange
              JsonPatchDocument patch = new JsonPatchDocument();

              // Act
              patch.Add("/RelatedParties", new BugReport.Party { Name = "Liza" });

              // Assert
              dynamic operations = patch.Operations;
              Assert.IsNotNull(operations);
              Assert.AreEqual(1, operations.Count);
              Assert.AreEqual("add", operations[0].op);
              Assert.AreEqual("/RelatedParties", operations[0].path);

              // Not the best way to test, but some how we need to know that it Builds good JSON
              Assert.AreEqual(@"[{""value"":{""Name"":""Liza"",""Id"":0},""op"":""add"",""path"":""/RelatedParties""}]", patch.ToString());
        }
예제 #2
0
        public void CanBuildMove()
        {
            // Arrange
              JsonPatchDocument patch = new JsonPatchDocument();

              // Act
              patch.Move("/Title", "/AnotherTitle");

              // Assert
              dynamic operations = patch.Operations;
              Assert.IsNotNull(operations);
              Assert.AreEqual(1, operations.Count);
              Assert.AreEqual("move", operations[0].op);
              Assert.AreEqual("/Title", operations[0].from);
              Assert.AreEqual("/AnotherTitle", operations[0].path);

              // Not the best way to test, but some how we need to know that it Builds good JSON
              Assert.AreEqual(@"[{""from"":""/Title"",""op"":""move"",""path"":""/AnotherTitle""}]", patch.ToString());
        }
예제 #3
0
        public void CanBuildReplace()
        {
            // Arrange
              JsonPatchDocument patch = new JsonPatchDocument();

              // Act
              patch.Replace("/Title", "Bummer");

              // Assert
              dynamic operations = patch.Operations;
              Assert.IsNotNull(operations);
              Assert.AreEqual(1, operations.Count);
              Assert.AreEqual("replace", operations[0].op);
              Assert.AreEqual("/Title", operations[0].path);
              Assert.AreEqual("Bummer", operations[0].value);

              // Not the best way to test, but some how we need to know that it Builds good JSON
              Assert.AreEqual(@"[{""value"":""Bummer"",""op"":""replace"",""path"":""/Title""}]", patch.ToString());
        }
예제 #4
0
        public void CanBuildTypedTest()
        {
            // Arrange
              JsonPatchDocument<BugReport> patch = new JsonPatchDocument<BugReport>();

              // Act
              patch.Test(r => r.Title, "TestValue");

              // Assert
              dynamic operations = patch.Operations;
              Assert.IsNotNull(operations);
              Assert.AreEqual(1, operations.Count);
              Assert.AreEqual("test", operations[0].op);
              Assert.AreEqual("/Title", operations[0].path);
              Assert.AreEqual("TestValue", operations[0].value);

              // Not the best way to test, but some how we need to know that it Builds good JSON
              Assert.AreEqual(@"[{""value"":""TestValue"",""op"":""test"",""path"":""/Title""}]", patch.ToString());
        }
예제 #5
0
        public void CanBuildTypedReplaceWithObjectValue()
        {
            // Arrange
              BugReport.Party party = new BugReport.Party { Name = "John" };
              JsonPatchDocument<BugReport> patch = new JsonPatchDocument<BugReport>();

              // Act
              patch.Replace(r => r.Responsible, party);

              // Assert
              dynamic operations = patch.Operations;
              Assert.IsNotNull(operations);
              Assert.AreEqual(1, operations.Count);
              Assert.AreEqual("replace", operations[0].op);
              Assert.AreEqual("/Responsible", operations[0].path);
              Assert.AreEqual(party, operations[0].value);

              // Not the best way to test, but some how we need to know that it Builds good JSON
              Assert.AreEqual(@"[{""value"":{""Name"":""John"",""Id"":0},""op"":""replace"",""path"":""/Responsible""}]", patch.ToString());
        }
예제 #6
0
        public void CanBuildTypedRemove()
        {
            // Arrange
              JsonPatchDocument<BugReport> patch = new JsonPatchDocument<BugReport>();

              // Act
              patch.Remove(r => r.Responsible.Name);

              // Assert
              dynamic operations = patch.Operations;
              Assert.IsNotNull(operations);
              Assert.AreEqual(1, operations.Count);
              Assert.AreEqual("remove", operations[0].op);
              Assert.AreEqual("/Responsible/Name", operations[0].path);

              // Not the best way to test, but some how we need to know that it Builds good JSON
              Assert.AreEqual(@"[{""op"":""remove"",""path"":""/Responsible/Name""}]", patch.ToString());
        }
예제 #7
0
 public object Patch(JsonPatchDocument patch)
 {
   return patch.ToString();
 }