Esempio n. 1
0
        public static List <Strategy> LoadStrategies(IEventAggregator eventAggregator, ISubscriberHandler handler)
        {
            return(new List <Strategy>
            {
                new Strategy(s => s.Equals("i"), s => handler.AddSubscriber <int>()),
                new Strategy(s => s.Equals("s"), s => handler.AddSubscriber <string>()),
                new Strategy(s => s.Equals("a"), s => handler.DisplaySubscribers()),
                new Strategy(s => s.StartsWith("us "), s => handler.Unsubscribe(s.Remove(0, s.IndexOf(' ') + 1))),
                new Strategy(s => s.StartsWith("ss "), s => handler.Subscribe(s.Remove(0, s.IndexOf(' ') + 1))),
                new Strategy(s => s.StartsWith("d "), s => handler.DeleteSubscriber(s.Remove(0, s.IndexOf(' ') + 1))),
                new Strategy(s => s.StartsWith("p "), s =>
                {
                    var input = s.Remove(0, s.IndexOf(' ') + 1);
                    var output = 0;

                    if (int.TryParse(input, out output))
                    {
                        eventAggregator.Publish(output);
                    }
                    else
                    {
                        eventAggregator.Publish(input);
                    }
                })
            });
        }
Esempio n. 2
0
        public void DeleteSubscriber()
        {
            // arrange
            var firstSub  = _handler.AddSubscriber <int>();
            var secondSub = _handler.AddSubscriber <int>();

            // act
            _handler.DeleteSubscriber(secondSub.Name);

            // assert
            Assert.IsFalse(_handler.Subscribers
                           .Any(s => s.Name == secondSub.Name));
        }