public void One_Level_Nesting_Unescaped() { var guids = Enumerable.Range(0, 6).Select(x => Guid.NewGuid()).ToList(); var guidCounter = 0; Guid GuidFactory() => guids[guidCounter++]; // nested blocks without property value escaping used in the conversion var innerJson = GetBlockListJson(null, SubContentGuid1, SubContentGuid2, SubSettingsGuid1); // get the json with the subFeatures as unescaped var json = GetBlockListJson(innerJson); var expected = ReplaceGuids( GetBlockListJson(innerJson), guids, ContentGuid1, ContentGuid2, SettingsGuid1, SubContentGuid1, SubContentGuid2, SubSettingsGuid1); var component = new BlockEditorPropertyHandler(s_logger); var result = component.ReplaceBlockListUdis(json, GuidFactory); var expectedJson = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(expected, _serializerSettings), _serializerSettings); var resultJson = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(result, _serializerSettings), _serializerSettings); Console.WriteLine(expectedJson); Console.WriteLine(resultJson); Assert.AreEqual(expectedJson, resultJson); }
public void Cannot_Have_Null_Udi() { var component = new BlockEditorPropertyHandler(s_logger); var json = GetBlockListJson(null, string.Empty); Assert.Throws <FormatException>(() => component.ReplaceBlockListUdis(json)); }
public void Nested_In_Complex_Editor_Escaped() { var guids = Enumerable.Range(0, 6).Select(x => Guid.NewGuid()).ToList(); var guidCounter = 0; Guid GuidFactory() { return(guids[guidCounter++]); } var innerJson = GetBlockListJson(null, SubContentGuid1, SubContentGuid2, SubSettingsGuid1); // we need to ensure the escaped json is consistent with how it will be re-escaped after parsing // and this is how to do that, the result will also include quotes around it. var innerJsonEscaped = JsonConvert.ToString(innerJson); // Complex editor such as the grid var complexEditorJsonEscaped = GetGridJson(innerJsonEscaped); var json = GetBlockListJson(complexEditorJsonEscaped); var component = new BlockEditorPropertyHandler(s_logger); var result = component.ReplaceBlockListUdis(json, GuidFactory); // the expected result is that the subFeatures data is no longer escaped var expected = ReplaceGuids( GetBlockListJson(GetGridJson(innerJson)), guids, ContentGuid1, ContentGuid2, SettingsGuid1, SubContentGuid1, SubContentGuid2, SubSettingsGuid1); var expectedJson = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(expected, _serializerSettings), _serializerSettings); var resultJson = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(result, _serializerSettings), _serializerSettings); Console.WriteLine(expectedJson); Console.WriteLine(resultJson); Assert.AreEqual(expectedJson, resultJson); }
public void No_Nesting() { var guids = Enumerable.Range(0, 3).Select(x => Guid.NewGuid()).ToList(); var guidCounter = 0; Guid GuidFactory() => guids[guidCounter++]; var json = GetBlockListJson(null); var expected = ReplaceGuids(json, guids, ContentGuid1, ContentGuid2, SettingsGuid1); var component = new BlockEditorPropertyHandler(s_logger); var result = component.ReplaceBlockListUdis(json, GuidFactory); var expectedJson = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(expected, _serializerSettings), _serializerSettings); var resultJson = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(result, _serializerSettings), _serializerSettings); Console.WriteLine(expectedJson); Console.WriteLine(resultJson); Assert.AreEqual(expectedJson, resultJson); }