예제 #1
0
        public void serializeTest()
        {
            IServerChatSystem chatSystem        = new ServerChatSystem();
            IUser             user1             = chatSystem.AddNewUser("Jaś Kowalski");
            IUser             user2             = chatSystem.AddNewUser("Kasia Źdźbło");
            Conversation      savedConversation = chatSystem.AddConversation("Konfa 1", user1, user2);
            IMessageContent   msgContent1       = new TextContent("Heeejoooo");
            IMessageContent   msgContent2       = new TextContent("Heeej");
            DateTime          datetime          = DateTime.Now;
            Message           sentMessage1      = chatSystem.SendMessage(savedConversation.ID, "Jaś Kowalski", -1, msgContent1, datetime);
            Message           sentMessage2      = chatSystem.SendMessage(savedConversation.ID, "Kasia Źdźbło", sentMessage1.ID, msgContent2, datetime);

            ClientChatSystem clientChatSystem        = new ClientChatSystem();
            IUser            userClient1             = clientChatSystem.AddNewUser("Jaś Kowalski");
            IUser            userClient2             = clientChatSystem.AddNewUser("Kasia Źdźbło");
            Conversation     savedClientConversation = clientChatSystem.AddConversation(savedConversation.Serialize(new ConcreteSerializer()), new ConcreteDeserializer());

            bool msg1Present     = false;
            bool msg2Present     = false;
            bool wrongMsgPresent = false;

            foreach (var message in savedClientConversation.Messages)
            {
                if (message.ID == sentMessage1.ID)
                {
                    msg1Present = true;
                    Assert.AreEqual(message.Author.Name, userClient1.Name);                     // There is no way serialization keeps references
                    Assert.AreSame(message.Author, savedClientConversation.Users.ToArray()[0]);
                    Assert.IsNull(message.Parent);
                    Assert.AreEqual(message.Content.getData(), sentMessage1.Content.getData());
                    Assert.AreEqual(message.SentTime, sentMessage1.SentTime);
                }
                else if (message.ID == sentMessage2.ID)
                {
                    msg2Present = true;
                    Assert.AreEqual(message.Author.Name, userClient2.Name);
                    Assert.IsNotNull(message.Parent.ID);                     //to be deleted when test passes
                    Assert.AreEqual(message.TargetId, sentMessage1.ID);      //to be deleted but this passes
                    Assert.AreEqual(message.Parent.ID, sentMessage1.ID);     //while this causes the test to fail
                    Assert.AreEqual(message.Content.getData(), sentMessage2.Content.getData());
                    Assert.AreEqual(message.SentTime, sentMessage2.SentTime);
                }
                else
                {
                    wrongMsgPresent = true;
                }
            }
            Assert.IsTrue(msg1Present);
            Assert.IsTrue(msg2Present);
            Assert.IsFalse(wrongMsgPresent);
        }
예제 #2
0
        public void logInTest()
        {
            IClientChatSystem chatSystem = new ClientChatSystem();

            Assert.IsFalse(chatSystem.logIn(new User("Kasia Źdźbło", chatSystem as ChatSystem)));
            chatSystem.AddNewUser("Kasia Źdźbło");
            Assert.IsTrue(chatSystem.logIn(new User("Kasia Źdźbło", chatSystem as ChatSystem)));
            Assert.IsTrue(chatSystem.LoggedUserName == "Kasia Źdźbło");
        }
예제 #3
0
        public void getUserNameTest()
        {
            IClientChatSystem chatSystem = new ClientChatSystem();
            string            name       = chatSystem.LoggedUserName;

            Assert.IsNull(name);
            IUser user1 = chatSystem.AddNewUser("Jaś Kowalski");

            chatSystem.logIn(new User("Jaś Kowalski", chatSystem as ChatSystem));
            name = chatSystem.LoggedUserName;
            Assert.IsTrue(name == "Jaś Kowalski");
        }
예제 #4
0
        public void applyUpdatesTest()
        {
            // Creating 'server' chat system
            IServerChatSystem chatSystem = new ServerChatSystem();
            // Creating two users
            IUser user1 = chatSystem.AddNewUser("Jaś Kowalski");
            IUser user2 = chatSystem.AddNewUser("Kasia Źdźbło");
            // Creating a conversation with those users
            Conversation savedConversation = chatSystem.AddConversation("Konfa 1", user1, user2);
            // Sending a message
            IMessageContent msgContent1  = new TextContent("Heeejoooo");
            DateTime        datetime     = DateTime.Now;
            Message         sentMessage1 = chatSystem.SendMessage(savedConversation.ID, "Jaś Kowalski", Guid.Empty, msgContent1, datetime);
            // Creating client chat system
            IClientChatSystem clientChatSystem = new ClientChatSystem();

            clientChatSystem.AddNewUser("Kasia Źdźbło");
            // Applying updates
            clientChatSystem.applyUpdates(chatSystem.getUpdatesToUser("Kasia Źdźbło", datetime - TimeSpan.FromSeconds(3)));
            // Checks
            bool conversationPresent = false;

            foreach (var conversation in clientChatSystem.GetUser("Kasia Źdźbło").Conversations)
            {
                if (conversation.ID == savedConversation.ID)
                {
                    conversationPresent = true;
                    bool messagePresent = false;
                    foreach (var message in conversation.Messages)
                    {
                        if (message.ID == sentMessage1.ID && message.Content.getData() == sentMessage1.Content.getData())
                        {
                            messagePresent = true;
                        }
                    }
                    Assert.IsTrue(messagePresent);
                }
            }
            Assert.IsTrue(conversationPresent);
        }