示例#1
0
        public void unmatchWithConversationTest()
        {
            Conversation conversation1 = new Conversation("Konfa 1", 1);
            IUser        user1         = new User("Pan A");

            bool hasConversation1     = false;
            bool hasWrongConversation = false;

            foreach (var conversation in user1.Conversations)
            {
                hasWrongConversation = true;
            }
            Assert.IsFalse(hasWrongConversation);
            hasWrongConversation = false;

            user1.MatchWithConversation(conversation1);

            foreach (var conversation in user1.Conversations)
            {
                if (conversation == conversation1)
                {
                    hasConversation1 = true;
                }
                else
                {
                    hasWrongConversation = true;
                }
            }
            Assert.IsTrue(hasConversation1);
            Assert.IsFalse(hasWrongConversation);
            hasConversation1     = false;
            hasWrongConversation = false;

            bool methodResult;

            methodResult = user1.UnmatchWithConversation(conversation1);
            Assert.IsTrue(methodResult);

            foreach (var conversation in user1.Conversations)
            {
                hasWrongConversation = true;
            }
            Assert.IsFalse(hasWrongConversation);
            hasWrongConversation = false;

            methodResult = user1.UnmatchWithConversation(conversation1);
            Assert.IsFalse(methodResult);
        }
示例#2
0
        public void matchWithConversationTest()
        {
            Conversation conversation1 = new Conversation("Konfa 1", 1);             //dopuszczamy możliwość stworzenia samodzielnej konwersacji do testów
            Conversation conversation2 = new Conversation("Konfa 2", 2);
            IUser        user1         = new User("Pan A");
            IUser        user2         = new User("Pani B");

            bool hasConversation1     = false;
            bool hasConversation2     = false;
            bool hasWrongConversation = false;

            foreach (var conversation in user1.Conversations)
            {
                hasWrongConversation = true;
            }
            Assert.IsFalse(hasWrongConversation);
            hasWrongConversation = false;
            foreach (var conversation in user2.Conversations)
            {
                hasWrongConversation = true;
            }
            Assert.IsFalse(hasWrongConversation);
            hasWrongConversation = false;

            bool methodResult;

            methodResult = user1.MatchWithConversation(conversation1);
            Assert.IsTrue(methodResult);
            methodResult = user1.MatchWithConversation(conversation2);
            Assert.IsTrue(methodResult);
            methodResult = user2.MatchWithConversation(conversation1);
            Assert.IsTrue(methodResult);

            foreach (var conversation in user1.Conversations)
            {
                if (conversation == conversation1)
                {
                    hasConversation1 = true;
                }
                else if (conversation == conversation2)
                {
                    hasConversation2 = true;
                }
                else
                {
                    hasWrongConversation = true;
                }
            }
            Assert.IsTrue(hasConversation1);
            Assert.IsTrue(hasConversation2);
            Assert.IsFalse(hasWrongConversation);
            hasConversation1     = false;
            hasConversation2     = false;
            hasWrongConversation = false;
            foreach (var conversation in user2.Conversations)
            {
                if (conversation == conversation1)
                {
                    hasConversation1 = true;
                }
                else
                {
                    hasWrongConversation = true;
                }
            }
            Assert.IsTrue(hasConversation1);
            Assert.IsFalse(hasWrongConversation);

            methodResult = user2.MatchWithConversation(conversation1);
            Assert.IsFalse(methodResult);
        }
        public void getUpdatesTest()
        {
            // Conversation
            Conversation conversation1 = new Conversation("Konfa 1", 1);

            // Users
            IUser user1 = new User("Mr. X");
            IUser user2 = new User("Ms. Y");

            // Matching
            conversation1.MatchWithUser(user1);
            conversation1.MatchWithUser(user2);
            user1.MatchWithConversation(conversation1);
            user2.MatchWithConversation(conversation1);

            // Messages
            //  Content
            IMessageContent msgContent1 = new TextContent("Heeejoooo");
            IMessageContent msgContent2 = new TextContent("No cześć");
            IMessageContent msgContent3 = new TextContent("Co tam słychać?");
            //  Timestamps
            DateTime datetime  = DateTime.Now;
            DateTime datetime2 = datetime + TimeSpan.FromSeconds(5);
            DateTime datetime3 = datetime + TimeSpan.FromSeconds(19);
            //  Sending
            Message sentMessage1 = conversation1.AddMessage(user1, -1, msgContent1, datetime);
            Message sentMessage2 = conversation1.AddMessage(user2, 1, msgContent2, datetime2);
            Message sentMessage3 = conversation1.AddMessage(user1, 2, msgContent3, datetime3);

            // Checks
            bool hasMessage2     = false;
            bool hasMessage3     = false;
            bool hasWrongMessage = false;

            foreach (var message in conversation1.GetUpdates(1).Messages)
            {
                if (message.ID == sentMessage2.ID)
                {
                    hasMessage2 = true;
                    Assert.IsTrue(message.Author.Name == sentMessage2.Author.Name);
                    Assert.IsTrue(message.TargetId == 1);
                    Assert.IsTrue(message.Content.getData() == sentMessage2.Content.getData());
                    Assert.IsTrue(message.SentTime == sentMessage2.SentTime);
                }
                else if (message.ID == sentMessage3.ID)
                {
                    hasMessage3 = true;
                    Assert.IsTrue(message.Author.Name == sentMessage3.Author.Name);
                    Assert.IsTrue(message.Parent.ID == 2);
                    Assert.IsTrue(message.Content.getData() == sentMessage3.Content.getData());
                    Assert.IsTrue(message.SentTime == sentMessage3.SentTime);
                }
                else
                {
                    hasWrongMessage = true;
                }
            }
            Assert.IsTrue(hasMessage2);
            Assert.IsTrue(hasMessage3);
            Assert.IsFalse(hasWrongMessage);
        }