Esempio n. 1
0
        public async Task Publish_WhileDisposed_Throws()
        {
            // arrange
            _subscriptionStore
            .Setup(m => m.GetSubscriptions(It.IsAny <string>()))
            .ReturnsAsync(GetSubs(10));

            var handler = new FakeHandler(HttpStatusCode.OK, "test");

            var hub = new Hub(
                _hubLocation,
                _subscriptionStore.Object,
                _challengeGenerator.Object,
                _queue.Object,
                handler);

            hub.Dispose();

            // act

            // assert
            await
            Assert.ThrowsAsync <ObjectDisposedException>(
                () => hub.PublishDirect(_testPublication));
        }
Esempio n. 2
0
        public async Task PublishDirect_FailedNotify_TriggersEvent()
        {
            // arrange
            _subscriptionStore
            .Setup(m => m.GetSubscriptions(It.IsAny <string>()))
            .ReturnsAsync(GetSubs(2));

            var handler = new FakeHandler(HttpStatusCode.NotFound, "test failure");

            var hub = new Hub(
                _hubLocation,
                _subscriptionStore.Object,
                _challengeGenerator.Object,
                _queue.Object,
                handler);

            var failCount = 0;

            hub.PublishNotificationFailed += (o, s) => failCount++;

            // act
            await hub.PublishDirect(_testPublication);

            await Task.Delay(500);

            // assert
            Assert.Equal(2, failCount);
        }
Esempio n. 3
0
        public async Task Subscribe_MissingChallengeResponse_ReturnsFalse()
        {
            // arrange
            var handler = new FakeHandler(HttpStatusCode.OK, null);
            var hub     = new Hub(_hubLocation, _subscriptionStore.Object, _challengeGenerator.Object, _queue.Object, handler);

            // act
            var result = await hub.Subscribe(_testSubscription, "baz");

            // assert
            Assert.False(result.SubscriptionSucceeded);
        }
Esempio n. 4
0
        public async Task Subscribe_ChallengeFailed_ReturnsFalse()
        {
            // arrange
            var subscriberChallengeReply = "bar"; // server sends "foo"
            var handler = new FakeHandler(HttpStatusCode.OK, subscriberChallengeReply);
            var hub     = new Hub(_hubLocation, _subscriptionStore.Object, _challengeGenerator.Object, _queue.Object, handler);

            // act
            var result = await hub.Subscribe(_testSubscription, "baz");

            // assert
            Assert.False(result.SubscriptionSucceeded);
        }
Esempio n. 5
0
        public async Task Subscribe_Failure_DoesNotCallStore()
        {
            // arrange
            var store = new Mock <ISubscriptionStore>();

            store.Setup(m => m.Subscribe(It.IsAny <Subscription>()));

            var handler = new FakeHandler(HttpStatusCode.OK, null);
            var hub     = new Hub(_hubLocation, store.Object, _challengeGenerator.Object, _queue.Object, handler);

            // act
            var result = await hub.Subscribe(_testSubscription, "baz");

            // assert
            store.Verify(m => m.Subscribe(It.IsAny <Subscription>()), Times.Never);
        }
Esempio n. 6
0
        public async Task Subscribe_SunnyDay_ReturnsTrue()
        {
            // arrange
            var handler = new FakeHandler(HttpStatusCode.OK, ChallengeValue);
            var hub     = new Hub(
                _hubLocation,
                _subscriptionStore.Object,
                _challengeGenerator.Object,
                _queue.Object,
                handler);

            // act
            var result = await hub.Subscribe(_testSubscription, "verifyToken");

            // assert
            Assert.True(result.SubscriptionSucceeded);
        }
Esempio n. 7
0
        public async Task Subscribe_Success_CallsSubscriptionStore()
        {
            // arrange
            var subStore = new Mock <ISubscriptionStore>();

            subStore
            .Setup(m => m.Subscribe(It.IsAny <Subscription>()))
            .Returns(Task.FromResult(It.IsAny <SubscriptionResult>()));

            var handler = new FakeHandler(HttpStatusCode.OK, ChallengeValue);
            var hub     = new Hub(_hubLocation, subStore.Object, _challengeGenerator.Object, _queue.Object, handler);

            // act
            var result = await hub.Subscribe(_testSubscription, "verifyToken");

            // assert
            subStore.Verify(m => m.Subscribe(It.IsAny <Subscription>()), Times.Once);
        }
Esempio n. 8
0
        public async Task PublishDirect_NoSubscribers_NoHttpCallsMade()
        {
            // arrange
            _subscriptionStore
            .Setup(m => m.GetSubscriptions(It.IsAny <string>()))
            .ReturnsAsync(GetSubs(0));

            var handler = new FakeHandler(HttpStatusCode.OK, "test");

            var hub = new Hub(
                _hubLocation,
                _subscriptionStore.Object,
                _challengeGenerator.Object,
                _queue.Object,
                handler);

            // act
            await hub.PublishDirect(_testPublication);

            await Task.Delay(500);

            // assert
            Assert.Equal(0, handler.Count);
        }