Exemple #1
0
 public ChannelWriter(IHttpRequest connectivity, IServerEventWriter writer, ITopicChannelCache cache, IChannelInitializer <T> channelInitializer)
 {
     _connectivity       = connectivity;
     _writer             = writer;
     _cache              = cache;
     _channelInitializer = channelInitializer;
 }
        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");
        }
        public void sends_initialization_events_then_events_following_last_initial_event_id()
        {
            theChannel.Write(q => q.Write(e1, e2, e3, e4, e5));
            theInitializer = new TestChannelInitializer(ie1, ie2, ie3);

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

            theWriter.ConnectedTest = () => !theWriter.Events.Contains(e5);

            var task = theChannelWriter.Write(theTopic);

            task.Wait(150).ShouldBeTrue();

            theWriter.Events.ShouldHaveTheSameElementsAs(ie1, ie2, ie3, e4, e5);
        }
        public void parent_task_is_faulted_when_channel_initializer_fails()
        {
            theInitializer   = new FailingTestChannelInitializer();
            theChannelWriter = new ChannelWriter <FakeTopic>(theWriter, theWriter, theCache, theInitializer);

            var testTask = new Task(() => theChannelWriter.Write(theTopic));

            testTask.RunSynchronously();
            testTask.IsFaulted.ShouldBeTrue();

            var exceptions = testTask.Exception.Flatten().InnerExceptions;

            exceptions.Count.ShouldBe(1);
            exceptions[0].Message.ShouldBe(FailingTestChannelInitializer.ExceptionMessage);
        }