2
0
Эх сурвалжийг харах

Move some interop tests to the public interface test project (#1767)

most of those interop tests illustrate how to interact with objects from
popular libraries such as Newtonsoft.Json, System.Text.Json and dynamic
objects such as ExpandoObject.

because this can be a valuable reference for Jint users, they should not
depend on any internals (which would be off limits for callers.)
BhaaL 1 жил өмнө
parent
commit
24c674f9b8

+ 7 - 2
Jint.Tests/Runtime/InteropTests.Dynamic.cs → Jint.Tests.PublicInterface/InteropTests.Dynamic.cs

@@ -1,9 +1,8 @@
 using System.Dynamic;
 using Jint.Native;
 using Jint.Native.Symbol;
-using Jint.Tests.Runtime.Domain;
 
-namespace Jint.Tests.Runtime
+namespace Jint.Tests.PublicInterface
 {
     public partial class InteropTests
     {
@@ -143,5 +142,11 @@ namespace Jint.Tests.Runtime
                 return _properties.ContainsKey(key);
             }
         }
+
+        private class Person
+        {
+            public string Name { get; set; }
+            public int Age { get; set; }
+        }
     }
 }

+ 1 - 1
Jint.Tests/Runtime/InteropTests.Json.cs → Jint.Tests.PublicInterface/InteropTests.Json.cs

@@ -1,7 +1,7 @@
 using System.Dynamic;
 using Jint.Runtime.Interop;
 
-namespace Jint.Tests.Runtime;
+namespace Jint.Tests.PublicInterface;
 
 public partial class InteropTests
 {

+ 1 - 1
Jint.Tests/Runtime/InteropTests.NewtonsoftJson.cs → Jint.Tests.PublicInterface/InteropTests.NewtonsoftJson.cs

@@ -2,7 +2,7 @@ using Jint.Native;
 using Jint.Runtime;
 using Newtonsoft.Json.Linq;
 
-namespace Jint.Tests.Runtime
+namespace Jint.Tests.PublicInterface
 {
     public partial class InteropTests
     {

+ 2 - 2
Jint.Tests/Runtime/InteropTests.SystemTextJson.cs → Jint.Tests.PublicInterface/InteropTests.SystemTextJson.cs

@@ -2,7 +2,7 @@ using System.Reflection;
 using System.Text.Json.Nodes;
 using Jint.Runtime.Interop;
 
-namespace Jint.Tests.Runtime;
+namespace Jint.Tests.PublicInterface;
 
 public partial class InteropTests
 {
@@ -37,7 +37,7 @@ public partial class InteropTests
                 var wrapped = new ObjectWrapper(e, target);
                 if (target is JsonArray)
                 {
-                    wrapped.SetPrototypeOf(e.Realm.Intrinsics.Array.PrototypeObject);
+                    wrapped.Prototype = e.Intrinsics.Array.PrototypeObject;
                 }
                 return wrapped;
             };

+ 24 - 0
Jint.Tests.PublicInterface/InteropTests.cs

@@ -0,0 +1,24 @@
+using System.Reflection;
+
+namespace Jint.Tests.PublicInterface
+{
+    public partial class InteropTests : IDisposable
+    {
+        private readonly Engine _engine;
+
+        public InteropTests()
+        {
+            _engine = new Engine(cfg => cfg.AllowClr(
+                        typeof(Console).GetTypeInfo().Assembly,
+                        typeof(File).GetTypeInfo().Assembly))
+                    .SetValue("log", new Action<object>(Console.WriteLine))
+                    .SetValue("assert", new Action<bool>(Assert.True))
+                    .SetValue("equal", new Action<object, object>(Assert.Equal))
+                ;
+        }
+
+        void IDisposable.Dispose()
+        {
+        }
+    }
+}

+ 1 - 0
Jint.Tests.PublicInterface/Jint.Tests.PublicInterface.csproj

@@ -28,6 +28,7 @@
     <PackageReference Include="Newtonsoft.Json" />
     <PackageReference Include="NodaTime" />
     <PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" />
+    <PackageReference Include="System.Text.Json" />
     <PackageReference Include="xunit" />
     <PackageReference Include="xunit.runner.visualstudio" />
   </ItemGroup>