public void Acts_As_True_When_Successful()
        {
            // Given
            var result = new JsonPatchResult {
                Succeeded = true
            };

            // Then
            Assert.True(result);
        }
        public void Acts_As_False_When_Unsuccessful()
        {
            // Given
            var result = new JsonPatchResult {
                Succeeded = false
            };

            // Then
            Assert.False(result);
        }
Пример #3
0
        public void PatchingWithEscaping()
        {
            using (var store = GetDocumentStore())
            {
                string documentId = null;
                IDictionary <string, object> originalCompany = new ExpandoObject();

                originalCompany["~"]        = "~";
                originalCompany["/"]        = "/";
                originalCompany["foo/bar~"] = "foo/bar~";

                var list = new List <ExpandoObject>();
                IDictionary <string, object> prop1 = new ExpandoObject();
                prop1["~"] = "Nested~";
                list.Add((ExpandoObject)prop1);
                IDictionary <string, object> prop2 = new ExpandoObject();
                prop2["/"] = "Nested/";
                list.Add((ExpandoObject)prop2);
                IDictionary <string, object> prop3 = new ExpandoObject();
                prop3["foo/bar~"] = "NestedFoo/Bar~";
                list.Add((ExpandoObject)prop3);

                originalCompany["biscuits"] = list;

                dynamic originalCompany2 = originalCompany;
                using (var session = store.OpenSession())
                {
                    session.Store(originalCompany2);
                    documentId = originalCompany2.Id;
                    session.SaveChanges();
                }

                var jpd = new JsonPatchDocument();
                jpd.Add("/~0", "Hibernating Rhinos1");
                jpd.Replace("/~1", "Hibernating Rhinos2");
                jpd.Add("/foo~1bar~0", "Hibernating Rhinos3");
                jpd.Add("/biscuits/0/~0", "Hibernating Rhinos1");
                jpd.Add("/biscuits/1/~1", "Hibernating Rhinos2");
                jpd.Replace("/biscuits/1/~1", "Hibernating Rhinos replaced");
                jpd.Add("/biscuits/2/foo~1bar~0", "Hibernating Rhinos3");
                JsonPatchResult op = store.Operations.Send(new JsonPatchOperation(documentId, jpd));
                Assert.Equal(PatchStatus.Patched, op.Status);

                using (var session = store.OpenSession())
                {
                    IDictionary <string, object> dbCompany = session.Load <ExpandoObject>(documentId);
                    jpd.ApplyTo(originalCompany2);
                    AssertExpandosEqual(originalCompany2, (dynamic)dbCompany);
                }
            }
        }
Пример #4
0
        public void Run(string fileName, JsonValue testJson)
        {
            var isOptional = testJson.Object.TryGetBoolean("disabled") ?? false;

            JsonPatchResult result = null;

            using (new TestExecutionContext.IsolatedContext())
            {
                try
                {
                    var schemaValidation = JsonPatchTest.Schema.Validate(testJson);
                    if (!schemaValidation.IsValid)
                    {
                        foreach (var error in schemaValidation.NestedResults)
                        {
                            Console.WriteLine(error);
                        }

                        return;
                    }

                    var test = _serializer.Deserialize <JsonPatchTest>(testJson);

                    result = test.Patch.TryApply(test.Doc);

                    Assert.AreNotEqual(test.ExpectsError, result.Success);

                    if (test.HasExpectedValue)
                    {
                        Assert.AreEqual(test.ExpectedValue, result.Patched);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(fileName);
                    Console.WriteLine(testJson.GetIndentedString());
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    if (result != null)
                    {
                        Console.WriteLine(result.Error);
                    }
                    if (isOptional)
                    {
                        Assert.Inconclusive("This is an acceptable failure.  Test case failed, but was marked as 'disabled'.");
                    }
                    throw;
                }
            }
        }
Пример #5
0
        public void Run(string fileName, JsonValue testJson)
        {
            JsonPatchResult result = null;

            try
            {
                var schemaValidation = JsonPatchTest.Schema.Validate(testJson);
                if (!schemaValidation.Valid)
                {
                    foreach (var error in schemaValidation.Errors)
                    {
                        Console.WriteLine(error);
                    }
                    return;
                }
                var test = _serializer.Deserialize <JsonPatchTest>(testJson);

                result = test.Patch.TryApply(test.Doc);

                Assert.AreNotEqual(test.ExpectsError, result.Success);
                if (test.HasExpectedValue)
                {
                    Assert.AreEqual(test.ExpectedValue, result.Patched);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(fileName);
                Console.WriteLine(testJson.GetIndentedString());
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                if (result != null)
                {
                    Console.WriteLine(result.Error);
                }
                if (testJson.Object.TryGetBoolean("disabled") ?? false)
                {
                    Assert.Inconclusive();
                }
                throw;
            }
        }