Skip to content

Commit

Permalink
Remove Newtonsoft.Json.Linq usage from unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Apr 24, 2024
1 parent 6e485b2 commit 1dc58d7
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Writers;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using DotVVM.Framework.ResourceManagement;

namespace DotVVM.Framework.Binding.Expressions
{
internal class BindingDebugJsonConverter: JsonConverter<IBinding>
{
public override IBinding Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
throw new NotImplementedException("Deserializing dotvvm bindings from JSON is not supported.");
public override void Write(Utf8JsonWriter writer, IBinding obj, JsonSerializerOptions options)
internal class BindingDebugJsonConverter(bool detailed): GenericWriterJsonConverter<IBinding>((writer, obj, options) => {
if (detailed)
{
writer.WriteStartObject();
writer.WriteString("ToString"u8, obj.ToString());
var props = (obj as ICloneableBinding)?.GetAllComputedProperties() ?? Enumerable.Empty<IBinding>();
foreach (var p in props)
{
var name = p.GetType().Name;
writer.WritePropertyName(name);
JsonSerializer.Serialize(writer, p, options);
}
writer.WriteEndObject();
}
else
{
writer.WriteStringValue(obj?.ToString());

// w.WriteStartObject();
// w.WritePropertyName("ToString");
// w.WriteValue(obj.ToString());
// var props = (obj as ICloneableBinding)?.GetAllComputedProperties() ?? Enumerable.Empty<IBinding>();
// foreach (var p in props)
// {
// var name = p.GetType().Name;
// w.WritePropertyName(name);
// serializer.Serialize(w, p);
// }
// w.WriteEndObject();
}
})
{
public BindingDebugJsonConverter() : this(false) { }
}
}
1 change: 0 additions & 1 deletion src/Framework/Framework/Diagnostics/JsonSizeAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using DotVVM.Framework.Utils;
using DotVVM.Framework.ViewModel.Serialization;
using FastExpressionCompiler;
// using Newtonsoft.Json.Linq;

namespace DotVVM.Framework.Diagnostics
{
Expand Down
1 change: 0 additions & 1 deletion src/Samples/Api.Common/Model/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace DotVVM.Samples.BasicSamples.Api.Common.Model
{
Expand Down
3 changes: 1 addition & 2 deletions src/Samples/Api.Common/Model/OrderItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json;


namespace DotVVM.Samples.BasicSamples.Api.Common.Model
{
public class OrderItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using DotVVM.Framework.Compilation.ControlTree;
using DotVVM.Framework.Controls;
using DotVVM.Framework.ViewModel;
using Newtonsoft.Json;

namespace DotVVM.Samples.BasicSamples.ViewModels.ControlSamples.GridView
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Text;
using System.Threading.Tasks;
using DotVVM.Framework.Controls;
using Newtonsoft.Json;

namespace DotVVM.Samples.BasicSamples.ViewModels.ControlSamples.GridView
{
Expand Down
1 change: 0 additions & 1 deletion src/Tests/Binding/StaticCommandExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using DotVVM.Framework.ViewModel;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using static DotVVM.Framework.Testing.DotvvmTestHelper;

namespace DotVVM.Framework.Tests.Binding
Expand Down
1 change: 0 additions & 1 deletion src/Tests/ControlTests/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DotVVM.Framework.Testing;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Microsoft.Extensions.DependencyInjection;
using DotVVM.Framework.ViewModel;

Expand Down
18 changes: 10 additions & 8 deletions src/Tests/Runtime/ConfigurationSerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using DotVVM.Framework.ResourceManagement;
using DotVVM.Framework.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Encodings.Web;

namespace DotVVM.Framework.Tests.Runtime
{
Expand Down Expand Up @@ -43,19 +45,19 @@ void checkConfig(DotvvmConfiguration config, bool includeProperties = false, str

Console.WriteLine(serialized);

var jobject = JObject.Parse(serialized);
void removeTestStuff(JToken token)
var jobject = JsonNode.Parse(serialized).AsObject();
void removeTestStuff(JsonNode token)
{
if (token is JObject obj)
foreach (var testControl in obj.Properties().Where(p => p.Name.Contains(".Tests.")).ToArray())
testControl.Remove();
if (token is JsonObject obj)
foreach (var testControl in obj.Where(p => p.Key.Contains(".Tests.")).ToArray())
obj.Remove(testControl.Key);
}
removeTestStuff(jobject["properties"]);
removeTestStuff(jobject["propertyGroups"]);
removeTestStuff(jobject["capabilities"]);
removeTestStuff(jobject["controls"]);
jobject["assemblies"]?.Parent.Remove(); // there are user specific paths
check.CheckString(jobject.ToString(), checkName, fileExtension, memberName, sourceFilePath);
jobject.Remove("assemblies"); // there are user specific paths
check.CheckString(jobject.ToJsonString(new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, WriteIndented = true }), checkName, fileExtension, memberName, sourceFilePath);
}

[TestMethod]
Expand Down
1 change: 0 additions & 1 deletion src/Tests/Runtime/ControlTree/ServerSideStyleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using DotVVM.Framework.ResourceManagement;
using DotVVM.Framework.ViewModel;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Linq;

namespace DotVVM.Framework.Tests.Runtime.ControlTree
{
Expand Down
1 change: 0 additions & 1 deletion src/Tests/Runtime/RuntimeErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using DotVVM.Framework.Configuration;
using DotVVM.Framework.Hosting;
using DotVVM.Framework.ResourceManagement;
Expand Down

0 comments on commit 1dc58d7

Please sign in to comment.