Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ContentModelSerializationTests.cs
Nikolaj Geisle 7aeb400fce V10: fix build warnings in test projects (#12509)
* Run code cleanup

* Dotnet format benchmarks project

* Fix up Test.Common

* Run dotnet format + manual cleanup

* Run code cleanup for unit tests

* Run dotnet format

* Fix up errors

* Manual cleanup of Unit test project

* Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Fix according to review

* Fix after merge

* Fix errors

Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
Co-authored-by: Zeegaan <nge@umbraco.dk>
2022-06-21 08:09:38 +02:00

81 lines
3.2 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Extensions;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.AngularIntegration;
[TestFixture]
public class ContentModelSerializationTests
{
[Test]
public void Content_Display_To_Json()
{
// create 3 tabs with 3 properties each
var tabs = new List<Tab<ContentPropertyDisplay>>();
for (var tabIndex = 0; tabIndex < 3; tabIndex++)
{
var props = new List<ContentPropertyDisplay>();
for (var propertyIndex = 0; propertyIndex < 3; propertyIndex++)
{
props.Add(new ContentPropertyDisplay
{
Alias = "property" + propertyIndex,
Label = "Property " + propertyIndex,
Id = propertyIndex,
Value = "value" + propertyIndex,
Config = new Dictionary<string, object> { { propertyIndex.ToInvariantString(), "value" } },
Description = "Description " + propertyIndex,
View = "~/Views/View" + propertyIndex,
HideLabel = false,
});
}
tabs.Add(new Tab<ContentPropertyDisplay>
{
Alias = "Tab" + tabIndex,
Label = "Tab" + tabIndex,
Properties = props,
});
}
var displayModel = new ContentItemDisplay
{
Id = 1234,
Variants = new List<ContentVariantDisplay> { new() { Name = "Test", Tabs = tabs } },
};
var json = JsonConvert.SerializeObject(displayModel);
var jObject = JObject.Parse(json);
Assert.AreEqual("1234", jObject["id"].ToString());
Assert.AreEqual("Test", jObject["variants"][0]["name"].ToString());
var jsonTabs = jObject["variants"][0]["tabs"];
Assert.AreEqual(3, jsonTabs.Count());
for (var tab = 0; tab < jsonTabs.Count(); tab++)
{
Assert.AreEqual("Tab" + tab, jsonTabs[tab]["alias"].ToString());
Assert.AreEqual("Tab" + tab, jsonTabs[tab]["label"].ToString());
Assert.AreEqual(3, jsonTabs[tab]["properties"].Count());
for (var prop = 0; prop < jsonTabs[tab]["properties"].Count(); prop++)
{
Assert.AreEqual("property" + prop, jsonTabs[tab]["properties"][prop]["alias"].ToString());
Assert.AreEqual("Property " + prop, jsonTabs[tab]["properties"][prop]["label"].ToString());
Assert.AreEqual(prop, jsonTabs[tab]["properties"][prop]["id"].Value<int>());
Assert.AreEqual("value" + prop, jsonTabs[tab]["properties"][prop]["value"].ToString());
Assert.AreEqual("{\"" + prop + "\":\"value\"}", jsonTabs[tab]["properties"][prop]["config"].ToString(Formatting.None));
Assert.AreEqual("Description " + prop, jsonTabs[tab]["properties"][prop]["description"].ToString());
Assert.AreEqual(false, jsonTabs[tab]["properties"][prop]["hideLabel"].Value<bool>());
}
}
}
}