diff --git a/Source/Demo.App.Tests/ActorFixture.cs b/Source/Demo.App.Tests/ActorFixture.cs index 7c5f4097..e4947b23 100644 --- a/Source/Demo.App.Tests/ActorFixture.cs +++ b/Source/Demo.App.Tests/ActorFixture.cs @@ -9,9 +9,6 @@ using Orleankka.TestKit; -using Orleans.Runtime.Configuration; -using Orleans.Serialization; - namespace Demo { public abstract class ActorFixture @@ -21,8 +18,7 @@ public abstract class ActorFixture [SetUp] public virtual void SetUp() { - var config = new ClusterConfiguration(); - Runtime = new ActorRuntimeMock(new SerializationManager(null, config.Globals, config.Defaults)); + Runtime = new ActorRuntimeMock(new SerializationOptions(roundtrip: true)); } protected ActorSystemMock System => Runtime.System; diff --git a/Source/Orleankka.TestKit/ActorRefMock.cs b/Source/Orleankka.TestKit/ActorRefMock.cs index b982d9cc..2f662a73 100644 --- a/Source/Orleankka.TestKit/ActorRefMock.cs +++ b/Source/Orleankka.TestKit/ActorRefMock.cs @@ -4,21 +4,20 @@ using System.Linq.Expressions; using System.Threading.Tasks; -using Orleans.Serialization; namespace Orleankka.TestKit { [Serializable] public class ActorRefMock : ActorRef { - [NonSerialized] readonly SerializationManager serialization; + [NonSerialized] readonly SerializationOptions serialization; [NonSerialized] readonly List expectations = new List(); [NonSerialized] readonly List messages = new List(); - internal ActorRefMock(ActorPath path, SerializationManager serialization = null) + internal ActorRefMock(ActorPath path, SerializationOptions serialization = null) : base(path) { - this.serialization = serialization; + this.serialization = serialization ?? SerializationOptions.Default; } public TellExpectation ExpectTell(Expression> match = null) diff --git a/Source/Orleankka.TestKit/ActorRuntimeMock.cs b/Source/Orleankka.TestKit/ActorRuntimeMock.cs index 32e8188d..3f8af734 100644 --- a/Source/Orleankka.TestKit/ActorRuntimeMock.cs +++ b/Source/Orleankka.TestKit/ActorRuntimeMock.cs @@ -1,12 +1,10 @@ using Orleankka.Services; -using Orleans.Serialization; - namespace Orleankka.TestKit { public class ActorRuntimeMock : IActorRuntime { - public ActorRuntimeMock(SerializationManager serialization = null) + public ActorRuntimeMock(SerializationOptions serialization = null) { System = new ActorSystemMock(serialization); Timers = new TimerServiceMock(); diff --git a/Source/Orleankka.TestKit/ActorSystemMock.cs b/Source/Orleankka.TestKit/ActorSystemMock.cs index 8410f617..8eca2e99 100644 --- a/Source/Orleankka.TestKit/ActorSystemMock.cs +++ b/Source/Orleankka.TestKit/ActorSystemMock.cs @@ -2,15 +2,13 @@ using System.Collections.Generic; using System.Threading.Tasks; -using Orleans.Serialization; - namespace Orleankka.TestKit { using Client; public class ActorSystemMock : IClientActorSystem { - readonly SerializationManager serialization; + readonly SerializationOptions serialization; readonly Dictionary actors = new Dictionary(); @@ -21,9 +19,9 @@ public class ActorSystemMock : IClientActorSystem readonly Queue observables = new Queue(); - public ActorSystemMock(SerializationManager serialization = null) + public ActorSystemMock(SerializationOptions serialization = null) { - this.serialization = serialization; + this.serialization = serialization ?? SerializationOptions.Default; } public ActorRefMock MockActorOf(string id) diff --git a/Source/Orleankka.TestKit/Orleankka.TestKit.csproj b/Source/Orleankka.TestKit/Orleankka.TestKit.csproj index 51b5ab3c..9545d31f 100644 --- a/Source/Orleankka.TestKit/Orleankka.TestKit.csproj +++ b/Source/Orleankka.TestKit/Orleankka.TestKit.csproj @@ -53,7 +53,7 @@ Properties\Product.cs - + diff --git a/Source/Orleankka.TestKit/SerializationOptions.cs b/Source/Orleankka.TestKit/SerializationOptions.cs new file mode 100644 index 00000000..7a4f1eba --- /dev/null +++ b/Source/Orleankka.TestKit/SerializationOptions.cs @@ -0,0 +1,52 @@ +using System; +using System.Linq; +using System.Net; +using System.Reflection; + +using Microsoft.Extensions.DependencyInjection; + +using Orleans; +using Orleans.Runtime.Configuration; +using Orleans.Serialization; +using Orleans.Runtime; + +namespace Orleankka.TestKit +{ + using Utility; + + public class SerializationOptions + { + internal static readonly SerializationOptions Default = new SerializationOptions(false); + + readonly SerializationManager manager; + + public SerializationOptions(bool roundtrip, params Type[] serializers) + { + Requires.NotNull(serializers, nameof(serializers)); + + if (!roundtrip) + return; + + var configuration = new ClientConfiguration + { + GatewayProvider = ClientConfiguration.GatewayProviderType.Config, + Gateways = { new IPEndPoint(0, 0) }, + TraceToConsole = false, + DefaultTraceLevel = Severity.Off + }; + + if (serializers.Length > 0) + configuration.SerializationProviders.AddRange(serializers.Select(x => x.GetTypeInfo())); + + var client = new ClientBuilder() + .UseConfiguration(configuration) + .Build(); + + manager = client.ServiceProvider.GetRequiredService(); + } + + internal object Roundtrip(object obj) => manager != null + ? manager.RoundTripSerializationForTesting(obj) + : obj; + } +} \ No newline at end of file diff --git a/Source/Orleankka.TestKit/StreamRefMock.cs b/Source/Orleankka.TestKit/StreamRefMock.cs index be342a56..f5ff93e6 100644 --- a/Source/Orleankka.TestKit/StreamRefMock.cs +++ b/Source/Orleankka.TestKit/StreamRefMock.cs @@ -4,14 +4,13 @@ using System.Linq.Expressions; using System.Threading.Tasks; -using Orleans.Serialization; namespace Orleankka.TestKit { [Serializable] public class StreamRefMock : StreamRef { - [NonSerialized] readonly SerializationManager serialization; + [NonSerialized] readonly SerializationOptions serialization; [NonSerialized] readonly List expectations = new List(); [NonSerialized] readonly List items = new List(); @@ -24,10 +23,10 @@ public class StreamRefMock : StreamRef public Actor Subscribed { get; private set; } public Actor Resumed { get; private set; } - internal StreamRefMock(StreamPath path, SerializationManager serialization = null) + internal StreamRefMock(StreamPath path, SerializationOptions serialization = null) : base(path, null) { - this.serialization = serialization; + this.serialization = serialization ?? SerializationOptions.Default; } public PushExpectation Expect(Expression> match = null)