Exemplo n.º 1
0
        public void AcceptChat_Initiated()
        {
            var guid1 = Guid.NewGuid();
            var guid2 = Guid.NewGuid();

            ChatHub.ConnectedUsers.Add(new UserModel()
            {
                Id = guid1,
                Language = "English",
                UserName = "******",
                IsChatting = false,
                Invites = new List<Guid>() { guid2 },
                ConnectionIds = new Dictionary<string, List<string>>() { { "Lobby", new List<string>() { "C7" } } }
            });
            ChatHub.ConnectedUsers.Add(new UserModel()
            {
                Id = guid2,
                Language = "French",
                UserName = "******",
                IsChatting = false,
                Invites = new List<Guid>(),
                ConnectionIds = new Dictionary<string, List<string>>() { { "Lobby", new List<string>() { "C8" } } }
            });

            ChatRoom chatRoom = new ChatRoom();

            var hub = new ChatHub(new MockTranslator());
            var mockClients = new Mock<IHubCallerConnectionContext<dynamic>>();
            hub.Clients = mockClients.Object;

            var mockGroupManager = new Mock<IGroupManager>();
            hub.Groups = mockGroupManager.Object;

            dynamic all = new ExpandoObject();
            all.joinRoom = new Action<ChatRoom>((room) =>
            {
                chatRoom = room;
            });

            AttachIdentity(hub, "Tester8", "C8");

            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);
            mockClients.Setup(m => m.User(It.IsAny<string>())).Returns((ExpandoObject)all);
            mockClients.Setup(m => m.Group(It.IsAny<string>())).Returns((ExpandoObject)all);
            mockClients.Setup(m => m.Clients(It.IsAny<List<string>>())).Returns((ExpandoObject)all);

            hub.AcceptChat(guid2, guid1);

            Assert.AreEqual(1, chatRoom.Id);
            Assert.AreEqual(2, chatRoom.Users.Count);
        }