Example #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       = 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));
        }
        internal static StreamSubscriptionSpecification From(Type actor, StreamSubscriptionAttribute attribute)
        {
            if (string.IsNullOrWhiteSpace(attribute.Source))
            {
                throw InvalidSpecification(actor, "has null or whitespace only value of Source");
            }

            if (string.IsNullOrWhiteSpace(attribute.Target))
            {
                throw InvalidSpecification(actor, "has null or whitespace only value of Target");
            }

            var parts = attribute.Source.Split(new[] { ":" }, 2, StringSplitOptions.None);

            if (parts.Length != 2)
            {
                throw InvalidSpecification(actor, $"has invalid Source specification: {attribute.Source}");
            }

            var provider = parts[0];
            var source   = parts[1];
            var target   = attribute.Target;

            return(new StreamSubscriptionSpecification(provider, source, target, actor));
        }
        internal static StreamSubscriptionSpecification From(ActorType type, StreamSubscriptionAttribute attribute)
        {
            if (string.IsNullOrWhiteSpace(attribute.Source))
                throw InvalidSpecification(type, "has null or whitespace only value of Source");

            if (string.IsNullOrWhiteSpace(attribute.Target))
                throw InvalidSpecification(type, "has null or whitespace only value of Target");

            if (attribute.Filter != null && string.IsNullOrWhiteSpace(attribute.Filter))
                throw InvalidSpecification(type, "has whitespace only value of Filter");

            var parts = attribute.Source.Split(new[] {":"}, 2, StringSplitOptions.None);
            if (parts.Length != 2)
                throw InvalidSpecification(type, $"has invalid Source specification: {attribute.Source}");

            var provider = parts[0];
            var source   = parts[1];
            var target   = attribute.Target;
            var filter   = attribute.Filter;

            var isRegex  = source.StartsWith("/") && 
                           source.EndsWith("/");
            if (!isRegex)
                return new MatchExact(provider, source, target, type, filter);

            var pattern = source.Substring(1, source.Length - 2);
            return new MatchPattern(provider, pattern, target, type, filter);
        }
        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));
        }
        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));
        }
Example #6
0
        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));
        }
        internal static StreamSubscriptionSpecification From(Type actor, StreamSubscriptionAttribute attribute)
        {
            if (string.IsNullOrWhiteSpace(attribute.Source))
                throw InvalidSpecification(actor, "has null or whitespace only value of Source");

            if (string.IsNullOrWhiteSpace(attribute.Target))
                throw InvalidSpecification(actor, "has null or whitespace only value of Target");

            var parts = attribute.Source.Split(new[] {":"}, 2, StringSplitOptions.None);
            if (parts.Length != 2)
                throw InvalidSpecification(actor, $"has invalid Source specification: {attribute.Source}");

            var provider = parts[0];
            var source   = parts[1];
            var target   = attribute.Target;
            
            return new StreamSubscriptionSpecification(provider, source, target, actor);
        }
Example #8
0
        internal static StreamSubscriptionSpecification From(Type actor, StreamSubscriptionAttribute attribute, Dispatcher dispatcher)
        {
            if (string.IsNullOrWhiteSpace(attribute.Source))
            {
                throw InvalidSpecification(actor, "has null or whitespace only value of Source");
            }

            if (string.IsNullOrWhiteSpace(attribute.Target))
            {
                throw InvalidSpecification(actor, "has null or whitespace only value of Target");
            }

            if (attribute.Filter != null && string.IsNullOrWhiteSpace(attribute.Filter))
            {
                throw InvalidSpecification(actor, "has whitespace only value of Filter");
            }

            var parts = attribute.Source.Split(new[] { ":" }, 2, StringSplitOptions.None);

            if (parts.Length != 2)
            {
                throw InvalidSpecification(actor, $"has invalid Source specification: {attribute.Source}");
            }

            var filter   = BuildFilter(attribute.Filter, actor, dispatcher);
            var selector = BuildTargetSelector(attribute.Target, actor);

            var provider = parts[0];
            var source   = parts[1];

            var isRegex = source.StartsWith("/") &&
                          source.EndsWith("/");

            if (!isRegex)
            {
                return(MatchExact(actor, provider, source, attribute.Target, selector, filter));
            }

            var pattern = source.Substring(1, source.Length - 2);

            return(MatchPattern(actor, provider, pattern, attribute.Target, selector, filter));
        }
        internal static StreamSubscriptionSpecification From(ActorType type, StreamSubscriptionAttribute attribute)
        {
            if (string.IsNullOrWhiteSpace(attribute.Source))
            {
                throw InvalidSpecification(type, "has null or whitespace only value of Source");
            }

            if (string.IsNullOrWhiteSpace(attribute.Target))
            {
                throw InvalidSpecification(type, "has null or whitespace only value of Target");
            }

            if (attribute.Filter != null && string.IsNullOrWhiteSpace(attribute.Filter))
            {
                throw InvalidSpecification(type, "has whitespace only value of Filter");
            }

            var parts = attribute.Source.Split(new[] { ":" }, 2, StringSplitOptions.None);

            if (parts.Length != 2)
            {
                throw InvalidSpecification(type, $"has invalid Source specification: {attribute.Source}");
            }

            var provider = parts[0];
            var source   = parts[1];
            var target   = attribute.Target;
            var filter   = attribute.Filter;

            var isRegex = source.StartsWith("/") &&
                          source.EndsWith("/");

            if (!isRegex)
            {
                return(new MatchExact(provider, source, target, type, filter));
            }

            var pattern = source.Substring(1, source.Length - 2);

            return(new MatchPattern(provider, pattern, target, type, filter));
        }
Example #10
0
 internal static StreamSubscriptionSpecification From(ActorType actor, StreamSubscriptionAttribute attribute)
 {
     return(From(actor, ActorPrototype.Of(actor), attribute));
 }
 internal static StreamSubscriptionSpecification From(ActorType actor, StreamSubscriptionAttribute attribute)
 {
     return From(actor, ActorPrototype.Of(actor), attribute);
 }