Esempio n. 1
0
        public void Test_03()
        {
            bool usersonlineSent = false;
            bool nameFound       = false;

            string userName = "******";

            var fakeStorage = new FakeStorage();
            var hub         = new ChappHub(fakeStorage);

            var mockClients = new Mock <IHubCallerConnectionContext <dynamic> >();
            // var all = new Mock<HubCallerContext>();

            var mockContext = new Mock <HubCallerContext>();

            mockContext.Setup(m => m.ConnectionId).Returns("3");

            hub.Context = mockContext.Object;
            hub.Clients = mockClients.Object;

            dynamic others = new ExpandoObject();

            others.usersOnline = new Action <string[]>((names) =>
            {
                usersonlineSent = true;
                nameFound       = !names.Contains(userName);
            });

            mockClients.Setup(m => m.Others).Returns((ExpandoObject)others);

            hub.Logout(userName);

            // Make sure that users online was sent to other users
            Assert.IsTrue(usersonlineSent, "Users online was never called!");
            // Make sure that the user name of logged out user is not in online users list
            Assert.IsTrue(nameFound, "Username was not found from the usersonline list");

            // Check that the logout username was sent to store
            Assert.AreEqual(userName, fakeStorage.LogoutName, "Storage: username did not match");
        }