-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #704 from riganti/feature/viewmodel-server-cache
Server-side caching of viewmodels The failing UI tests already fixed in master.
- Loading branch information
Showing
39 changed files
with
1,675 additions
and
972 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/DotVVM.Framework.Tests.Common/ViewModel/JsonPatchTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Linq; | ||
using DotVVM.Framework.Utils; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace DotVVM.Framework.Tests.Common.ViewModel | ||
{ | ||
[TestClass] | ||
public class JsonPatchTests | ||
{ | ||
|
||
[DataTestMethod] | ||
[DataRow(null, "['a', 'b']")] | ||
[DataRow("['a', 'd']", "['a', 'd']")] | ||
[DataRow("['a', 'b', 'c']", "['a', 'b', 'c']")] | ||
[DataRow("['a']", "['a']")] | ||
public void JsonPatch_Arrays_Primitive(string modifiedJson, string resultJson) | ||
{ | ||
var original = JObject.Parse(WrapArray("['a', 'b']")); | ||
var modified = JObject.Parse(WrapArray(modifiedJson)); | ||
var result = JObject.Parse(WrapArray(resultJson)); | ||
JsonUtils.Patch(original, modified); | ||
Assert.IsTrue(JToken.DeepEquals(original, result)); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow("{ }", "{ 'a': 1, 'b': 'a' }")] | ||
[DataRow("{ 'a': 2 }", "{ 'a': 2, 'b': 'a' }")] | ||
[DataRow("{ 'a': 2, c: null }", "{ 'a': 2, 'b': 'a', 'c': null }")] | ||
[DataRow("{ 'a': 2 }", "{ 'a': 2, 'b': 'a' }")] | ||
public void JsonPatch_Objects(string modifiedJson, string resultJson) | ||
{ | ||
var original = JObject.Parse("{ 'a': 1, 'b': 'a' }"); | ||
var modified = JObject.Parse(modifiedJson); | ||
var result = JObject.Parse(resultJson); | ||
JsonUtils.Patch(original, modified); | ||
Assert.IsTrue(JToken.DeepEquals(original, result)); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow("{ }", "{ 'a': 1, 'bparent': { 'b': 'a', 'c': 1 } }")] | ||
[DataRow("{ 'a': 2, 'b': 'a' }", "{ 'a': 2, 'b': 'a', 'bparent': { 'b': 'a', 'c': 1 } }")] | ||
[DataRow("{ 'bparent': { 'c': 2 } }", "{ 'a': 1, 'bparent': { 'b': 'a', 'c': 2 } }")] | ||
[DataRow("{ 'bparent': { 'c': 2, 'd': 3 } }", "{ 'a': 1, 'bparent': { 'b': 'a', 'c': 2, 'd': 3 } }")] | ||
[DataRow("{ 'bparent': { 'b': 'b' } }", "{ 'a': 1, 'bparent': { 'b': 'b', 'c': 1 } }")] | ||
public void JsonPatch_Objects_Nested(string modifiedJson, string resultJson) | ||
{ | ||
var original = JObject.Parse("{ 'a': 1, 'bparent': { 'b': 'a', 'c': 1 } }"); | ||
var modified = JObject.Parse(modifiedJson); | ||
var result = JObject.Parse(resultJson); | ||
JsonUtils.Patch(original, modified); | ||
Assert.IsTrue(JToken.DeepEquals(original, result)); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow(null, "[{ 'a': 1 }, { 'a': 2 }]")] | ||
[DataRow("[{ 'a': 3 }, {}]", "[{ 'a': 3 }, { 'a': 2 }]")] | ||
[DataRow("[{}, {}, { 'a': 3 }]", "[{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }]")] | ||
[DataRow("[{ 'a': 2 }]", "[{ 'a': 2 }]")] | ||
[DataRow("[{}]", "[{ 'a': 1 }]")] | ||
public void JsonPatch_ObjectArray(string modifiedJson, string resultJson) | ||
{ | ||
var original = JObject.Parse(WrapArray("[{ 'a': 1 }, { 'a': 2 }]")); | ||
var modified = JObject.Parse(WrapArray(modifiedJson)); | ||
var result = JObject.Parse(WrapArray(resultJson)); | ||
JsonUtils.Patch(original, modified); | ||
Assert.IsTrue(JToken.DeepEquals(original, result)); | ||
} | ||
|
||
private string WrapArray(string a) | ||
{ | ||
if (a == null) | ||
{ | ||
return "{}"; | ||
} | ||
|
||
return "{'array': " + a + "}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.