Пример #1
0
        public static IEnumerable <TestCaseData> TestCases()
        {
            foreach (Type nestedType in typeof(TestHelpers.PubSub).GetNestedTypes())
            {
                var publications =
                    GetCalls(nestedType, Channel.PublisherToBroker, new[] { WampMessageType.v2Publish });

                var publicationAcks =
                    GetCalls(nestedType, Channel.BrokerToPublisher, new[] { WampMessageType.v2Published })
                    .ToArray();

                var publicationErrors =
                    GetCalls(nestedType, Channel.BrokerToPublisher, new[] { WampMessageType.v2Error });

                var subscriptions =
                    GetCalls(nestedType, Channel.SubscriberToBroker, new[] { WampMessageType.v2Subscribe });

                var subscriptionAcks =
                    GetCalls(nestedType, Channel.BrokerToSubscriber, new[] { WampMessageType.v2Subscribed })
                    .ToArray();

                var events =
                    GetCalls(nestedType, Channel.BrokerToSubscriber, new[] { WampMessageType.v2Event })
                    .ToArray();

                BrokerScenario scenario = new BrokerScenario();

                scenario.Publications      = publications;
                scenario.PublicationAcks   = publicationAcks;
                scenario.PublicationErrors = publicationErrors;
                scenario.Subscriptions     = subscriptions;
                scenario.Events            = events;

                MockClient <IWampClientProxy <MockRaw> > subscriber = GetSubscriber(nestedType, scenario.ClientBuilder, scenario.Handler, events.Concat(subscriptionAcks));
                MockClient <IWampClientProxy <MockRaw> > publisher  = GetPublisher(nestedType, scenario.ClientBuilder, publicationAcks);

                scenario.Subscriber = subscriber;
                scenario.Publisher  = publisher;

                TestCaseData testCase = new TestCaseData(scenario);
                testCase.SetName(string.Format("PubSubIntegrationTest.{0}",
                                               nestedType.Name));

                yield return(testCase);
            }
        }
Пример #2
0
        public void BrokerTest(BrokerScenario scenario)
        {
            foreach (var subscription in scenario.Subscriptions)
            {
                scenario.Handler.HandleMessage(scenario.Subscriber.Client, subscription);
            }

            foreach (var publication in scenario.Publications)
            {
                scenario.Handler.HandleMessage(scenario.Publisher.Client, publication);
            }

            foreach (WampMessage <MockRaw> response in scenario.Events)
            {
                IEnumerable <WampMessage <MockRaw> > recordedMessages =
                    scenario.Subscriber.Recorder.RecordedMessages;

                WampMessage <MockRaw> mapped =
                    mMapper.MapRequest(response, recordedMessages, true);

                if (mapped == null)
                {
                    Assert.Fail("An expected response of the form {0} was not found", response);
                }
            }

            foreach (WampMessage <MockRaw> response in scenario.PublicationAcks
                     .Concat(scenario.PublicationErrors))
            {
                IEnumerable <WampMessage <MockRaw> > recordedMessages =
                    scenario.Publisher.Recorder.RecordedMessages;

                WampMessage <MockRaw> mapped =
                    mMapper.MapRequest(response, recordedMessages, false);

                if (mapped == null)
                {
                    Assert.Fail("An expected response of the form {0} was not found", response);
                }
            }
        }