public void Regex_based_matching(string source, string target, string streamId, string actorId) { var system = new ActorSystemMock(); var attribute = new StreamSubscriptionAttribute { Source = source, Target = target }; var type = typeof(TestActor); var dispatcher = new Dispatcher(type); var specification = StreamSubscriptionSpecification.From(type, attribute, dispatcher); specification.Type = ActorTypeName.Of(typeof(TestActor)); var match = specification.Match(system, streamId); if (match == StreamSubscriptionMatch.None) { Assert.That(actorId, Is.Null); return; } var message = new object(); match.Receiver(message); Assert.That(system.RequestedRef, Is.Not.Null); Assert.That(system.RequestedRef.Path, Is.EqualTo(typeof(TestActor).ToActorPath(actorId))); Assert.That(system.RequestedRef.MessagePassedToTell, Is.SameAs(message)); }
static void RegisterStreamSubscriptions(IServiceCollection services, Type[] actors) { var subscriptions = new StreamSubscriptionSpecificationRegistry(); foreach (var actor in actors) { var dispatcher = new Dispatcher(actor); subscriptions.Register(StreamSubscriptionSpecification.From(actor, dispatcher)); } services.AddSingleton(subscriptions); }
public void Regex_based_matching(string source, string target, string streamId, string actorId) { var attribute = new StreamSubscriptionAttribute { Source = source, Target = target }; var specification = StreamSubscriptionSpecification.From(typeof(Actor), attribute); var match = specification.Match(streamId); Assert.That(match.ActorId, Is.EqualTo(actorId)); }
public void Matching_and_generating_actor_ids(string streamId, string source, string target, string actorId) { var attribute = new StreamSubscriptionAttribute { Source = $"sms:{source}", Target = target }; var specification = StreamSubscriptionSpecification.From(typeof(Actor), attribute); var match = specification.Match(streamId); Assert.That(match.Id, Is.EqualTo(actorId)); }
public void Dynamic_target_matching() { var system = new ActorSystemMock(); var type = ActorType.From(typeof(DynamicTargetSelectorActor)); var specification = StreamSubscriptionSpecification.From(type).ElementAt(0); var match = specification.Match(system, "foo"); var message = new object(); match.Receiver(message); Assert.That(system.RequestedRef, Is.Not.Null); Assert.That(system.RequestedRef.Path, Is.EqualTo(ActorPath.From(typeof(DynamicTargetSelectorActor), "bar"))); Assert.That(system.RequestedRef.MessagePassedToTell, Is.SameAs(message)); }