public HubInvokerContext(IHub hub, TrackingDictionary state, MethodDescriptor methodDescriptor, object[] args) { Hub = hub; MethodDescriptor = methodDescriptor; Args = args; State = state; }
public void CanDeserializeClientState() { var clientState = new TrackingDictionary(); string clientId = "1"; var user = new ChatUser { Id = "1234", Name = "John", Identity = "foo" }; var cookies = new NameValueCollection(); cookies["jabbr.state"] = JsonConvert.SerializeObject(new ClientState { UserId = user.Id }); TestableChat chat = GetTestableChat(clientId, clientState, user, cookies); bool result = chat.Join(); Assert.Equal("1234", clientState["id"]); Assert.Equal("John", clientState["name"]); Assert.True(result); }
public static TestableChat GetTestableChat(string connectionId, TrackingDictionary clientState, ChatUser user, NameValueCollection cookies) { // setup things needed for chat var repository = new InMemoryRepository(); var resourceProcessor = new Mock <IResourceProcessor>(); var chatService = new Mock <IChatService>(); var connection = new Mock <IConnection>(); var settings = new Mock <IApplicationSettings>(); var mockPipeline = new Mock <IHubPipelineInvoker>(); settings.Setup(m => m.AuthApiKey).Returns("key"); // add user to repository repository.Add(user); // create testable chat var chat = new TestableChat(settings, resourceProcessor, chatService, repository, connection); var mockedConnectionObject = chat.MockedConnection.Object; chat.Clients = new HubConnectionContext(mockPipeline.Object, mockedConnectionObject, "Chat", connectionId, clientState); var prinicipal = new Mock <IPrincipal>(); var request = new Mock <IRequest>(); request.Setup(m => m.Cookies).Returns(new Cookies(cookies)); request.Setup(m => m.User).Returns(prinicipal.Object); // setup context chat.Context = new HubCallerContext(request.Object, connectionId); return(chat); }
public void CanJoinChatIfIdentitySet() { var clientState = new TrackingDictionary(); string clientId = "1"; var user = new ChatUser { Id = "1234", Name = "John", Identity = "foo" }; TestableChat chat = GetTestableChat(clientId, clientState, user); chat.Caller.id = "1234"; bool result = chat.Join(); Assert.Equal("1234", clientState["id"]); Assert.Equal("John", clientState["name"]); Assert.True(result); // TODO: find out why these don't work //Assert.Equal(1, user.ConnectedClients.Count); //Assert.Equal("1", user.ConnectedClients.First().Id); chat.MockedConnection.Verify(m => m.Broadcast("Chat." + clientId, It.IsAny <object>()), Times.Once()); }
public void CanDeserializeClientState() { var clientState = new TrackingDictionary(); string clientId = "1"; var user = new ChatUser { Id = "1234", Name = "John" }; var cookies = new NameValueCollection(); cookies["jabbr.state"] = JsonConvert.SerializeObject(new ClientState { UserId = user.Id }); TestableChat chat = GetTestableChat(clientId, clientState, user, cookies); bool result = chat.Join(); Assert.Equal("1234", clientState["id"]); Assert.Equal("John", clientState["name"]); Assert.True(result); chat.MockedConnection.Verify(m => m.Broadcast("Chat." + clientId, It.IsAny <object>()), Times.Once()); chat.MockedChatService.Verify(c => c.UpdateActivity(user, clientId), Times.Once()); }
public static TestableChat GetTestableChat(string clientId, TrackingDictionary clientState, ChatUser user, NameValueCollection cookies) { // setup things needed for chat var repository = new InMemoryRepository(); var resourceProcessor = new Mock <IResourceProcessor>(); var chatService = new Mock <IChatService>(); var connection = new Mock <IConnection>(); // add user to repository repository.Add(user); // create testable chat var chat = new TestableChat(resourceProcessor, chatService, repository, connection); var mockedConnectionObject = chat.MockedConnection.Object; // setup client agent chat.Agent = new ClientAgent(mockedConnectionObject, "Chat"); var request = new Mock <IRequest>(); request.Setup(m => m.Cookies).Returns(cookies); // setup signal agent var prinicipal = new Mock <IPrincipal>(); chat.Caller = new SignalAgent(mockedConnectionObject, clientId, "Chat", clientState); // setup context chat.Context = new HubContext(new HostContext(request.Object, null, prinicipal.Object), clientId); return(chat); }
public void CanJoinChat() { var clientState = new TrackingDictionary(); string clientId = "1"; var user = new ChatUser { Id = "1234", Name = "John" }; var cookies = new HttpCookieCollection { new HttpCookie("userid", "1234") }; TestableChat chat = GetTestableChat(clientId, clientState, user, cookies); bool result = chat.Join(); Assert.Equal("1234", clientState["id"]); Assert.Equal("John", clientState["name"]); Assert.True(result); // TODO: find out why these don't work //Assert.Equal(1, user.ConnectedClients.Count); //Assert.Equal("1", user.ConnectedClients.First().Id); chat.MockedConnection.Verify(m => m.Broadcast("Chat." + clientId, It.IsAny <object>()), Times.Once()); chat.MockedChatService.Verify(c => c.AddClient(user, clientId), Times.Once()); chat.MockedChatService.Verify(c => c.UpdateActivity(user), Times.Once()); }
public void MissingUsernameReturnsFalse() { var clientState = new TrackingDictionary(); string clientId = "1"; var user = new ChatUser(); TestableChat chat = GetTestableChat(clientId, clientState, user); bool result = chat.Join(); Assert.False(result); }
public EntitySystem(IServiceRegistry registry) : base(registry) { Services.AddService(typeof(EntitySystem), this); Enabled = true; Visible = true; entities = new TrackingDictionary <Entity, List <EntityProcessor> >(); enabledEntities = new TrackingHashSet <Entity>(); processors = new TrackingHashSet <EntityProcessor>(); processors.CollectionChanged += new EventHandler <TrackingCollectionChangedEventArgs>(systems_CollectionChanged); }
/// <summary> /// Initializes a new instance of the <see cref="EntityManager"/> class. /// </summary> /// <param name="registry">The registry.</param> /// <exception cref="System.ArgumentNullException">registry</exception> protected EntityManager(IServiceRegistry registry) { if (registry == null) { throw new ArgumentNullException("registry"); } Services = registry; entities = new TrackingDictionary <Entity, List <EntityProcessor> >(); enabledEntities = new TrackingHashSet <Entity>(); processors = new FastCollection <EntityProcessor>(); newProcessors = new List <EntityProcessor>(); componentTypes = new HashSet <Type>(); processorTypes = new HashSet <Type>(); }
public void CannotJoinChat() { var clientState = new TrackingDictionary(); string clientId = "1"; var user = new ChatUser { Id = "1234", Name = "John" }; TestableChat chat = GetTestableChat(clientId, clientState, user); chat.Clients.Caller.id = "1234"; bool result = chat.Join(); Assert.False(result); }
public TestableDebugHub(Mock <IContext> mockDbContext) : base(mockDbContext.Object) { const string connectionId = "1234"; const string hubName = "debug"; var mockConn = new Mock <IConnection>(); var mockUser = new Mock <IPrincipal>(); var mockCookies = new Mock <IRequestCookieCollection>(); var mockRequest = new Mock <IRequest>(); mockRequest.Setup(r => r.User).Returns(mockUser.Object); mockRequest.Setup(r => r.Cookies).Returns(mockCookies.Object); Clients = new ClientProxy(mockConn.Object, hubName); Groups = new GroupManager(mockConn.Object, hubName); Context = new HubCallerContext(mockRequest.Object, connectionId); var trackingDict = new TrackingDictionary(); Caller = new StatefulSignalProxy(mockConn.Object, connectionId, hubName, trackingDict); }
public static TestableChat GetTestableChat(string clientId, TrackingDictionary clientState, ChatUser user) { return(GetTestableChat(clientId, clientState, user, new NameValueCollection())); }
public TrackingInfo() { activeUsers = new TrackingDictionary(); inactiveUsers = new TrackingDictionary(); }
private void CleanupTrackingDictionary(TrackingDictionary dict, double minutes) { dict.RemoveOldItems (DateTime.Now.AddMinutes (-1.0 * minutes)); }