Exemple #1
0
        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          = ActorType.From(typeof(TestActor));
            var specification = StreamSubscriptionSpecification.From(type, attribute);
            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(ActorPath.From(typeof(TestActor), actorId)));
            Assert.That(system.RequestedRef.MessagePassedToTell, Is.SameAs(message));
        }
Exemple #2
0
        public static ActorPath From(Type type, string id)
        {
            Requires.NotNull(type, nameof(type));

            var code = ActorType
                       .From(type)
                       .Code;

            return(From(code, id));
        }
Exemple #3
0
        public static bool Matches(string stream, string target)
        {
            var actor = ActorType.From(typeof(T));
            var proto = ActorPrototype.Define(actor);
            var specs = StreamSubscriptionSpecification.From(actor, proto);

            var matched = specs
                          .Select(s => s.Match(null, stream))
                          .Where(m => m != StreamSubscriptionMatch.None)
                          .ToArray();

            return(matched.Any(x => x.Target == target));
        }
Exemple #4
0
        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));
        }