Beispiel #1
0
        public void BroadcastMessageToChannel()
        {
            string  testChannel = "testChannel";
            string  testMessage = "test message";
            string  testUser    = "******";
            dynamic broadCast   = new ExpandoObject();

            broadCast.sendChannelMessage = new Action <string, string>((user, message) =>
            {
                this.isSent = true;
                Assert.AreEqual(testUser, user, "the user was not supplied correctly");
                Assert.AreEqual(testMessage, message, "the message was not supplied correctly");
            });

            IRequest request     = base.BuildTestRequest().Object;
            var      mockClients = new Mock <IHubCallerConnectionContext <dynamic> >();

            mockClients.Setup(m => m.Group(testChannel)).Returns((ExpandoObject)broadCast);

            var mockHubCallerContext = new Mock <HubCallerContext>(request, "1");

            ChatHub hub = new ChatHub()
            {
                Context = mockHubCallerContext.Object,
                Clients = mockClients.Object,
                Groups  = mockGroupManager.Object
            };

            hub.ChannelBroadCast(testChannel, testUser, testMessage);
        }