Skip to content

Commit 24c674f

Browse files
authored
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.)
1 parent 9fbdab3 commit 24c674f

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed

Jint.Tests/Runtime/InteropTests.Dynamic.cs renamed to Jint.Tests.PublicInterface/InteropTests.Dynamic.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using System.Dynamic;
22
using Jint.Native;
33
using Jint.Native.Symbol;
4-
using Jint.Tests.Runtime.Domain;
54

6-
namespace Jint.Tests.Runtime
5+
namespace Jint.Tests.PublicInterface
76
{
87
public partial class InteropTests
98
{
@@ -143,5 +142,11 @@ public bool ContainsKey(string key)
143142
return _properties.ContainsKey(key);
144143
}
145144
}
145+
146+
private class Person
147+
{
148+
public string Name { get; set; }
149+
public int Age { get; set; }
150+
}
146151
}
147152
}

Jint.Tests/Runtime/InteropTests.Json.cs renamed to Jint.Tests.PublicInterface/InteropTests.Json.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Dynamic;
22
using Jint.Runtime.Interop;
33

4-
namespace Jint.Tests.Runtime;
4+
namespace Jint.Tests.PublicInterface;
55

66
public partial class InteropTests
77
{

Jint.Tests/Runtime/InteropTests.NewtonsoftJson.cs renamed to Jint.Tests.PublicInterface/InteropTests.NewtonsoftJson.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Jint.Runtime;
33
using Newtonsoft.Json.Linq;
44

5-
namespace Jint.Tests.Runtime
5+
namespace Jint.Tests.PublicInterface
66
{
77
public partial class InteropTests
88
{

Jint.Tests/Runtime/InteropTests.SystemTextJson.cs renamed to Jint.Tests.PublicInterface/InteropTests.SystemTextJson.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Text.Json.Nodes;
33
using Jint.Runtime.Interop;
44

5-
namespace Jint.Tests.Runtime;
5+
namespace Jint.Tests.PublicInterface;
66

77
public partial class InteropTests
88
{
@@ -37,7 +37,7 @@ public void AccessingJsonNodeShouldWork()
3737
var wrapped = new ObjectWrapper(e, target);
3838
if (target is JsonArray)
3939
{
40-
wrapped.SetPrototypeOf(e.Realm.Intrinsics.Array.PrototypeObject);
40+
wrapped.Prototype = e.Intrinsics.Array.PrototypeObject;
4141
}
4242
return wrapped;
4343
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Reflection;
2+
3+
namespace Jint.Tests.PublicInterface
4+
{
5+
public partial class InteropTests : IDisposable
6+
{
7+
private readonly Engine _engine;
8+
9+
public InteropTests()
10+
{
11+
_engine = new Engine(cfg => cfg.AllowClr(
12+
typeof(Console).GetTypeInfo().Assembly,
13+
typeof(File).GetTypeInfo().Assembly))
14+
.SetValue("log", new Action<object>(Console.WriteLine))
15+
.SetValue("assert", new Action<bool>(Assert.True))
16+
.SetValue("equal", new Action<object, object>(Assert.Equal))
17+
;
18+
}
19+
20+
void IDisposable.Dispose()
21+
{
22+
}
23+
}
24+
}

Jint.Tests.PublicInterface/Jint.Tests.PublicInterface.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<PackageReference Include="Newtonsoft.Json" />
2929
<PackageReference Include="NodaTime" />
3030
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" />
31+
<PackageReference Include="System.Text.Json" />
3132
<PackageReference Include="xunit" />
3233
<PackageReference Include="xunit.runner.visualstudio" />
3334
</ItemGroup>

0 commit comments

Comments
 (0)