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(); }
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); }
public void GetPeekConnectionEmptyTest() { var pusherRegistry = new PusherRegistry(new DateTimeProvider()); var nothing = pusherRegistry.GetPeekConnection(); Assert.IsNull(nothing); }