Esempio n. 1
0
        public void disposes_on_asp_shutdown_event()
        {
            var topic1 = new FakeTopic
            {
                Name = "Tom"
            };

            var topic2 = new FakeTopic
            {
                Name = "Todd"
            };

            var channel1 = ClassUnderTest.ChannelFor(topic1);
            var channel2 = ClassUnderTest.ChannelFor(topic2);

            channel1.ShouldNotBeNull();
            channel2.ShouldNotBeNull();

            _shutdownDetector.Stop(true);

            channel1.Channel.IsConnected().ShouldBeFalse();
            channel2.Channel.IsConnected().ShouldBeFalse();

            Exception <ObjectDisposedException> .ShouldBeThrownBy(() => ClassUnderTest.ChannelFor(topic1));

            Exception <ObjectDisposedException> .ShouldBeThrownBy(() => ClassUnderTest.ChannelFor(topic2));
        }
Esempio n. 2
0
        public void SetUp()
        {
            theInitializer = new DefaultChannelInitializer <FakeTopic>();
            theWriter      = new RecordingServerEventWriter();

            theCache = MockRepository.GenerateMock <ITopicChannelCache>();
            ITopicChannel <FakeTopic> channel = new TopicChannel <FakeTopic>(new EventQueue <FakeTopic>());

            theChannel = channel.Channel;
            theTopic   = new FakeTopic();

            theCache.Stub(x => x.TryGetChannelFor(theTopic, out channel)).Return(true).OutRef(channel);

            theChannelWriter = new ChannelWriter <FakeTopic>(theWriter, theWriter, theCache, theInitializer);

            e1 = new ServerEvent("1", "data-1");
            e2 = new ServerEvent("2", "data-2");
            e3 = new ServerEvent("3", "data-3");
            e4 = new ServerEvent("4", "data-4");
            e5 = new ServerEvent("5", "data-5");

            ie1 = new ServerEvent("random1", "initialization data-1");
            ie2 = new ServerEvent("random2", "initialization data-2");
            ie3 = new ServerEvent("3", "initialization data-3");
        }
Esempio n. 3
0
 public bool Equals(FakeTopic other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.Name, Name));
 }
Esempio n. 4
0
        public void publish_a_server_event()
        {
            var @event = new ServerEvent("1", "some text");
            var topic  = new FakeTopic {
                Name = "something"
            };

            var theChannel = MockFor <ITopicChannel <FakeTopic> >();

            MockFor <ITopicChannelCache>().Stub(x => x.ChannelFor(topic)).Return(theChannel);

            ClassUnderTest.WriteTo(topic, @event);

            theChannel.AssertWasCalled(x => x.WriteEvents(topic, @event));
        }
Esempio n. 5
0
        public void spin_up_pre_builds()
        {
            var factory = MockRepository.GenerateMock <IEventQueueFactory <FakeTopic> >();
            var queue   = new EventQueue <FakeTopic>();
            var topic   = new FakeTopic {
                Name = "Top"
            };

            factory.Stub(x => x.BuildFor(topic)).Return(queue);

            var family = new TopicFamily <FakeTopic>(factory);

            family.SpinUpChannel(topic);

            factory.AssertWasCalled(x => x.BuildFor(topic));
        }
Esempio n. 6
0
        public void failure_to_acquire_channel_terminates_without_errors()
        {
            theWriter = new RecordingServerEventWriter();

            var cache = MockRepository.GenerateMock <ITopicChannelCache>();
            ITopicChannel <FakeTopic> channel = new TopicChannel <FakeTopic>(new EventQueue <FakeTopic>());

            theChannel = channel.Channel;
            theTopic   = new FakeTopic();

            cache.Stub(x => x.TryGetChannelFor(theTopic, out channel)).Return(false);

            theChannelWriter = new ChannelWriter <FakeTopic>(theWriter, theWriter, cache, theInitializer);
            var task = theChannelWriter.Write(theTopic);

            task.Wait(150).ShouldBeTrue();
        }
Esempio n. 7
0
        public void publish_against_a_different_interface()
        {
            var oddQueue = MockFor <IOddQueue>();
            var @event   = new ServerEvent("1", "some text");
            var topic    = new FakeTopic
            {
                Name = "something"
            };

            var theChannel = new TopicChannel <FakeTopic>(oddQueue);

            MockFor <ITopicChannelCache>().Stub(x => x.ChannelFor(topic)).Return(theChannel);

            ClassUnderTest.WriteTo <FakeTopic, IOddQueue>(topic, x =>
            {
                x.WriteOddly(@event);
            });

            oddQueue.AssertWasCalled(x => x.WriteOddly(@event));
        }
Esempio n. 8
0
        public void caches_against_a_single_topic_family()
        {
            var topic1 = new FakeTopic
            {
                Name = "Tom"
            };

            var topic2 = new FakeTopic
            {
                Name = "Todd"
            };

            ClassUnderTest.ChannelFor(topic1).ShouldNotBeNull();
            ClassUnderTest.ChannelFor(topic1).ShouldBeTheSameAs(ClassUnderTest.ChannelFor(topic1));
            ClassUnderTest.ChannelFor(topic1).ShouldBeTheSameAs(ClassUnderTest.ChannelFor(topic1));
            ClassUnderTest.ChannelFor(topic1).ShouldBeTheSameAs(ClassUnderTest.ChannelFor(topic1));

            ClassUnderTest.ChannelFor(topic2).ShouldBeTheSameAs(ClassUnderTest.ChannelFor(topic2));

            ClassUnderTest.ChannelFor(topic1).ShouldNotBeTheSameAs(ClassUnderTest.ChannelFor(topic2));
        }
Esempio n. 9
0
        public void caches_against_a_multiple_topic_families()
        {
            // All relatives of mine from the same family.  In-law finally
            // rebelled and named a child "Parker"
            var topic1 = new FakeTopic
            {
                Name = "Tom"
            };

            var topic2 = new FakeTopic
            {
                Name = "Todd"
            };

            var topic3 = new DifferentTopic {
                Name = "Trevor"
            };

            var topic4 = new DifferentTopic
            {
                Name = "Trent"
            };

            ClassUnderTest.ChannelFor(topic1).ShouldNotBeNull();
            ClassUnderTest.ChannelFor(topic1).ShouldBeTheSameAs(ClassUnderTest.ChannelFor(topic1));
            ClassUnderTest.ChannelFor(topic1).ShouldBeTheSameAs(ClassUnderTest.ChannelFor(topic1));
            ClassUnderTest.ChannelFor(topic1).ShouldBeTheSameAs(ClassUnderTest.ChannelFor(topic1));

            ClassUnderTest.ChannelFor(topic2).ShouldBeTheSameAs(ClassUnderTest.ChannelFor(topic2));

            ClassUnderTest.ChannelFor(topic1).ShouldNotBeTheSameAs(ClassUnderTest.ChannelFor(topic2));

            ClassUnderTest.ChannelFor(topic3).ShouldBeTheSameAs(ClassUnderTest.ChannelFor(topic3));

            ClassUnderTest.ChannelFor(topic4).ShouldBeTheSameAs(ClassUnderTest.ChannelFor(topic4));

            ClassUnderTest.ChannelFor(topic3).ShouldNotBeTheSameAs(ClassUnderTest.ChannelFor(topic4));
        }
Esempio n. 10
0
        public void builds_and_caches_by_topic()
        {
            var factory = new DefaultEventQueueFactory <FakeTopic>();
            var family  = new TopicFamily <FakeTopic>(factory);

            var topic1 = new FakeTopic {
                Name = "Tom"
            };

            var topic2 = new FakeTopic
            {
                Name = "Todd"
            };

            family.ChannelFor(topic1).ShouldNotBeNull();
            family.ChannelFor(topic1).ShouldBeTheSameAs(family.ChannelFor(topic1));
            family.ChannelFor(topic1).ShouldBeTheSameAs(family.ChannelFor(topic1));
            family.ChannelFor(topic1).ShouldBeTheSameAs(family.ChannelFor(topic1));

            family.ChannelFor(topic2).ShouldBeTheSameAs(family.ChannelFor(topic2));


            family.ChannelFor(topic1).ShouldNotBeTheSameAs(family.ChannelFor(topic2));
        }
Esempio n. 11
0
 public bool Equals(FakeTopic other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Name, Name);
 }
Esempio n. 12
0
        public void spin_up_pre_builds()
        {
            var factory = MockRepository.GenerateMock<IEventQueueFactory<FakeTopic>>();
            var queue = new EventQueue<FakeTopic>();
            var topic = new FakeTopic{
                Name = "Top"
            };

            factory.Stub(x => x.BuildFor(topic)).Return(queue);

            var family = new TopicFamily<FakeTopic>(factory);
            family.SpinUpChannel(topic);

            factory.AssertWasCalled(x => x.BuildFor(topic));
        }
Esempio n. 13
0
        public void builds_and_caches_by_topic()
        {
            var factory = new DefaultEventQueueFactory<FakeTopic>();
            var family = new TopicFamily<FakeTopic>(factory);

            var topic1 = new FakeTopic{
                Name = "Tom"
            };

            var topic2 = new FakeTopic
            {
                Name = "Todd"
            };

            family.ChannelFor(topic1).ShouldNotBeNull();
            family.ChannelFor(topic1).ShouldBeTheSameAs(family.ChannelFor(topic1));
            family.ChannelFor(topic1).ShouldBeTheSameAs(family.ChannelFor(topic1));
            family.ChannelFor(topic1).ShouldBeTheSameAs(family.ChannelFor(topic1));

            family.ChannelFor(topic2).ShouldBeTheSameAs(family.ChannelFor(topic2));

            family.ChannelFor(topic1).ShouldNotBeTheSameAs(family.ChannelFor(topic2));
        }