示例#1
0
        public void Disconnect_Remove()
        {
            var guid1 = Guid.NewGuid();

            ChatHub.ConnectedUsers.Add(new UserModel()
            {
                Id = guid1,
                Language = "English",
                UserName = "******",
                IsChatting = true,
                ConnectionIds = new Dictionary<string, List<string>>() { { "Lobby", new List<string>() { "C4" } } }
            });

            Guid? disUser = null;

            var hub = new ChatHub(new MockTranslator());
            var mockClients = new Mock<IHubCallerConnectionContext<dynamic>>();
            hub.Clients = mockClients.Object;
            dynamic all = new ExpandoObject();
            all.userDisconnected = new Action<Guid>((name) =>
            {
                disUser = name;
            });

            AttachIdentity(hub, "Tester4", "C4");

            mockClients.Setup(m => m.All).Returns((ExpandoObject)all);
            mockClients.Setup(m => m.Caller).Returns((ExpandoObject)all);
            mockClients.Setup(m => m.Others).Returns((ExpandoObject)all);
            mockClients.Setup(m => m.OthersInGroup(It.IsAny<string>())).Returns((ExpandoObject)all);

            hub.OnDisconnected(true);

            Assert.AreEqual(0, ChatHub.ConnectedUsers.Count);
            Assert.AreEqual(guid1, disUser);
        }