Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server-side caching of viewmodels #704

Merged
merged 20 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/DotVVM.Framework.Tests.Common/ViewModel/JsonPatchTests.cs
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 + "}";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using DotVVM.Framework.Configuration;
using DotVVM.Framework.ViewModel;
using DotVVM.Framework.ViewModel.Serialization;
using DotVVM.Framework.ViewModel.Validation;
Expand All @@ -18,7 +19,8 @@ public void ViewModelSerializationMapper_Name_JsonPropertyVsBindAttribute()
{
var mapper = new ViewModelSerializationMapper(new ViewModelValidationRuleTranslator(),
new AttributeViewModelValidationMetadataProvider(),
new DefaultPropertySerialization());
new DefaultPropertySerialization(),
DotvvmConfiguration.CreateDefault());
var map = mapper.GetMap(typeof(JsonPropertyVsBindAttribute));

Assert.AreEqual("NoAttribute", map.Property("NoAttribute").Name);
Expand Down
Loading