Beispiel #1
0
        public void GetPeekConnectionRequeueFromCommitToPeekTest()
        {
            var dateTimeProvider = Substitute.For <IDateTimeProvider>();

            dateTimeProvider.UtcNow.Returns(DateTime.UtcNow);

            var pusherRegistry     = new PusherRegistry(dateTimeProvider);
            var connectionRegistry = new ConnectionRegistry(pusherRegistry, null);

            var persistentConnection = Substitute.For <IPersistentConnection>();

            persistentConnection.ConnectionId.Returns(Guid.NewGuid());

            connectionRegistry.RegisterInitiatedConnection(persistentConnection);
            connectionRegistry.PromoteToLoggedInConnection(persistentConnection, Identity.Next(), 1);

            connectionRegistry.PromoteToSubscribedConnection(persistentConnection.DeviceId, SubscriptionType.PeekAndCommit);

            persistentConnection.LastHeartbeat.Returns(DateTime.UtcNow.AddSeconds(-20.0));
            persistentConnection.NextPeekTime.Returns(DateTime.UtcNow.AddSeconds(-0.1));

            var conn = pusherRegistry.GetPeekConnection();

            pusherRegistry.SetAsCommitNeededConnections(new[] { conn });

            persistentConnection.LastCommitTime = DateTime.UtcNow.AddSeconds(-20);

            dateTimeProvider.UtcNow.Returns(DateTime.UtcNow.AddMilliseconds(200));
            pusherRegistry.GetPeekConnection();
        }
Beispiel #2
0
        public void GetPeekConnectionHeartbeatTooEarlyTest()
        {
            var dateTimeProvider = Substitute.For <IDateTimeProvider>();

            dateTimeProvider.UtcNow.Returns(DateTime.UtcNow);

            var pusherRegistry     = new PusherRegistry(dateTimeProvider);
            var connectionRegistry = new ConnectionRegistry(pusherRegistry, null);

            var persistentConnection = Substitute.For <IPersistentConnection>();

            persistentConnection.ConnectionId.Returns(Guid.NewGuid());

            connectionRegistry.RegisterInitiatedConnection(persistentConnection);
            connectionRegistry.PromoteToLoggedInConnection(persistentConnection, Identity.Next(), 1);

            connectionRegistry.PromoteToSubscribedConnection(persistentConnection.DeviceId, SubscriptionType.PeekAndCommit);

            persistentConnection.LastHeartbeat.Returns(DateTime.UtcNow.AddSeconds(-20.0));
            persistentConnection.NextPeekTime.Returns(DateTime.UtcNow.AddSeconds(0.1));

            var nothing = pusherRegistry.GetPeekConnection();

            Assert.IsNull(nothing);
        }
Beispiel #3
0
        public void GetPeekConnectionEmptyTest()
        {
            var pusherRegistry = new PusherRegistry(new DateTimeProvider());

            var nothing = pusherRegistry.GetPeekConnection();

            Assert.IsNull(nothing);
        }