コード例 #1
0
ファイル: EventNotifierTests.cs プロジェクト: suzuke/forge
        public void EventsAreNotRedispatched()
        {
            EventNotifier notifier = new EventNotifier();

            int callCount = 0;

            notifier.OnEvent <TestEvent>(evnt => ++ callCount);

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);

            notifier.Submit(TestEvent.Create());
            notifier.DispatchEvents();
            Assert.Equal(1, callCount);
            callCount = 0;

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);

            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());
            notifier.DispatchEvents();
            Assert.Equal(3, callCount);
            callCount = 0;

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);
        }
コード例 #2
0
 static EventData[] CreateEvent(long number, string stream)
 {
     return(new[]
     {
         new EventData(Guid.NewGuid(), typeof(TestEvent).AssemblyQualifiedName, true,
                       Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(TestEvent.Create(number, stream))), null)
     });
 }
コード例 #3
0
ファイル: MQPublisherTests.cs プロジェクト: wangyuzhu/Ray2
        public void should_Publish_Attribute()
        {
            var e = TestEvent.Create(1);

            this.Given(f => f.GivenInitEventPublisher())
            .When(f => f.WhenPublish(e))
            .Then(f => f.ThenSuccess())
            .BDDfy();
        }
コード例 #4
0
ファイル: EventPublisherTests.cs プロジェクト: lulzzz/Ray2
        private void WhenPublishList()
        {
            List <EventModel> models = new List <EventModel>();

            for (int i = 0; i < 10; i++)
            {
                EventModel model = new EventModel(TestEvent.Create(i));
                models.Add(model);
            }
            this.IsPublish = this.publisher.Publish(this.topic, models).GetAwaiter().GetResult();
        }
コード例 #5
0
ファイル: RabbitConsumerTests.cs プロジェクト: wangyuzhu/Ray2
        private void should_Process_RetryNotice()
        {
            this.exchange += "Process_RetryNotice";
            this.queue    += "Process_RetryNotice";
            EventModel model = new EventModel(TestEvent.Create(1));

            this.consumeOptions.NoticeRetriesCount = 3;
            this.Given(f => f.GivenInitProcessorFailure())
            .When(f => f.WhenSubscribe())
            .When(f => f.WhenProcess(model))
            .Then(f => f.ThenSuccess())
            .BDDfy();
        }
コード例 #6
0
ファイル: RabbitConsumerTests.cs プロジェクト: wangyuzhu/Ray2
        public void should_Subscribe_Normal()
        {
            this.exchange += "Subscribe_Normal";
            this.queue    += "Subscribe_Normal";
            EventModel     model = new EventModel(TestEvent.Create(1));
            PublishMessage msg   = new PublishMessage(model, this.serializer);

            this.Given(f => f.GivenInitProcessor())
            .When(f => f.WhenSubscribe())
            .When(f => f.WhenPublish(msg, 1))
            .Then(f => f.ThenProcess(model))
            .BDDfy();
        }
コード例 #7
0
        public void should_Expand_Normal()
        {
            this.topic    += "Expand";
            this.exchange += "Expand";
            EventModel     model = new EventModel(TestEvent.Create(1));
            PublishMessage msg   = new PublishMessage(model, this.serializer);

            this.Given(f => f.GivenInitProcessor())
            .When(f => f.WhenSubcribe())
            .When(f => f.WhenPublish(msg, 5000))
            .When(f => f.WhenMonitorConsumer())
            .BDDfy();
        }
コード例 #8
0
ファイル: MQPublisherTests.cs プロジェクト: wangyuzhu/Ray2
        public void should_GetAttributeOptions()
        {
            var e       = TestEvent.Create(1);
            var options = MQPublisherExtensions.GetAttributeOptions(e.GetType());

            Assert.NotNull(options);
            Assert.Equal(options.MQProvider, this.providerName);
            Assert.Equal(topic, options.Topic);

            var e1 = TestEvent1.Create(1);

            options = MQPublisherExtensions.GetAttributeOptions(e1.GetType());
            Assert.Null(options);
        }
コード例 #9
0
ファイル: RabbitConsumerTests.cs プロジェクト: wangyuzhu/Ray2
        private void should_IsExpand_True()
        {
            this.exchange += "expand";
            this.queue    += "expand";
            this.consumer  = new RabbitConsumer(serviceProvider, FakeConfig.ProviderName, serializer);
            EventModel     model = new EventModel(TestEvent.Create(1));
            PublishMessage msg   = new PublishMessage(model, this.serializer);

            this.Given(f => f.GivenInitProcessor())
            .When(f => f.WhenSubscribe())
            .When(f => f.WhenPublish(msg, 500))
            .When(f => f.WhenIsExpand())
            .Then(f => f.ThenSuccess())
            .BDDfy();
        }
コード例 #10
0
ファイル: EventNotifierTests.cs プロジェクト: suzuke/forge
        public void EventsAreNotRedispatchedWithConcurrentDispatch()
        {
            EventNotifier notifier = new EventNotifier();

            int callCount = 0;

            notifier.OnEvent <TestEvent>(evnt => {
                notifier.Submit(TestEvent.Create());
                ++callCount;
            });

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);

            notifier.Submit(TestEvent.Create());
            notifier.DispatchEvents();
            Assert.Equal(1, callCount);

            for (int i = 0; i < 20; ++i)
            {
                callCount = 0;
                notifier.DispatchEvents();
                Assert.Equal(1, callCount);
            }

            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());

            for (int i = 0; i < 20; ++i)
            {
                callCount = 0;
                notifier.DispatchEvents();
                Assert.Equal(4, callCount);
            }
        }
コード例 #11
0
        private void WhenPublishSingle()
        {
            EventModel model = new EventModel(TestEvent.Create(100));

            this.IsPublish = this.publisher.Publish(this.topic, model).GetAwaiter().GetResult();
        }