Ejemplo n.º 1
0
        public void Messages()
        {
            var msg = new ChadderMessage();

            msg.Type      = MESSAGE_TYPE.TEXT;
            msg.Body      = "Testing messages";
            msg.myMessage = true;
            msg.fromId    = Guid.NewGuid().ToString();
            msg.messageId = Guid.NewGuid().ToString();

            var packed = new ChadderPackedMessageText(msg);
            var serial = packed.Serialize();

            var packed2 = ChadderEncryptedContent.Deserialize(serial) as ChadderPackedMessageText;

            Assert.NotNull(packed2);
            Assert.AreEqual(packed.Id, packed2.Id);
            Assert.AreEqual(packed.Group, packed2.Group);
            Assert.AreEqual(packed.Time, packed2.Time);
            Assert.AreEqual(packed.From, packed2.From);
            Assert.AreEqual(packed.Body, packed2.Body);

            packed = new ChadderPackedMessageText(msg);
            serial = packed.Serialize();

            packed2 = ChadderEncryptedContent.Deserialize(serial) as ChadderPackedMessageText;
            Assert.NotNull(packed2);
            Assert.AreEqual(packed.Id, packed2.Id);
            Assert.AreEqual(packed.Group, packed2.Group);
            Assert.AreEqual(packed.Time, packed2.Time);
            Assert.AreEqual(packed.From, packed2.From);
            Assert.AreEqual(packed.Body, packed2.Body);
        }
Ejemplo n.º 2
0
        public async void NewMessageProtocolTransition()
        {
            var source1 = await CreateAccount();

            var source2 = await CreateAccount();

            await source2.ChangeShareName(true);

            var result = await source1.addContact(source2.database.profile.myId);

            await source2.ChangeShareName(false);

            Ok(result.Item1);

            var contact1 = source1.database.getContact(source2.database.profile.myId);

            Assert.NotNull(contact1);
            source1.database.conversations.Clear();
            var conversation1 = await source1.database.GetConversationByContact(contact1);

            Assert.Null(conversation1);

            var contact2 = source2.database.getContact(source1.database.profile.myId);

            Assert.NotNull(contact2);
            var conversation2 = await source2.database.GetConversationByContact(contact2);

            Assert.NotNull(conversation2);

            var body = "Testing";
            var msg  = new ChadderMessage()
            {
                Type      = MESSAGE_TYPE.TEXT,
                messageId = Guid.NewGuid().ToString(),
                myMessage = true,
                Body      = "Test",
                fromId    = source1.database.profile.myId,
                LocalTime = DateTime.UtcNow,
                Status    = MESSAGE_STATUS.SENDING
            };
            var packed    = new ChadderPackedMessageText(msg);
            var key       = new ChadderECDHUserUserLegacy(source1.database, contact1);
            var encrypted = await ChadderAESEncryptedContent.Encrypt(source1, key, packed);

            await source2.SendNewMessage(conversation2, body);

            await Task.Delay(1000);

            Assert.AreEqual(2, conversation2.messages.Count);
        }