* Update gitignore * Move csproj * Update project references * Update solutions * Update build scripts * Tests used to share editorconfig with projects in src * Fix broken tests. * Stop copying around .editorconfig merged root one with linting * csharp_style_expression_bodied -> suggestion * Move StyleCop rulesets to matching directories and update shared build properties * Remove legacy build files, update NuGet.cofig and solution files * Restore myget source * Clean up .gitignore * Update .gitignore * Move new test classes to tests after merge * Gitignore + nuget config * Move new test Co-authored-by: Ronald Barendse <ronald@barend.se>
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System.Runtime.Serialization;
|
|
using Newtonsoft.Json;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Web.Common.Formatters;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.Formatters
|
|
{
|
|
[TestFixture]
|
|
public class IgnoreRequiredAttributesResolverUnitTests
|
|
{
|
|
[Test]
|
|
public void Test()
|
|
{
|
|
const string emptyJsonObject = "{}";
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
// Ensure the deserialization throws if using default settings
|
|
Assert.Throws<JsonSerializationException>(() =>
|
|
JsonConvert.DeserializeObject<ObjectWithRequiredProperty>(emptyJsonObject));
|
|
|
|
ObjectWithRequiredProperty actual = JsonConvert.DeserializeObject<ObjectWithRequiredProperty>(
|
|
emptyJsonObject,
|
|
new JsonSerializerSettings
|
|
{
|
|
ContractResolver = new IgnoreRequiredAttributesResolver()
|
|
});
|
|
|
|
Assert.IsNotNull(actual);
|
|
Assert.IsNull(actual.Property);
|
|
});
|
|
}
|
|
|
|
[DataContract(Name = "objectWithRequiredProperty", Namespace = "")]
|
|
private class ObjectWithRequiredProperty
|
|
{
|
|
[DataMember(Name = "property", IsRequired = true)]
|
|
public string Property { get; set; }
|
|
}
|
|
}
|
|
}
|