public bool DeliverMessage(string to, XmppXElement element)
 {
     var session = server.SessionManager.GetSession(to);
     if (session != null)
         session.Send(element);
     else
         return false;
     return true;
 }
        private string GetStanzaAsString(XmppXElement xel, string type, int number)
        {
            var stanza = xel
                         .Elements("stanza")
                         .FirstOrDefault(s => s.Attribute("type").Value == type && s.Attribute("id").Value == number.ToString());

            return(stanza?
                   .DescendantNodes()
                   .Where(d => d.NodeType == System.Xml.XmlNodeType.CDATA)
                   .Cast <XCData>()
                   .FirstOrDefault()
                   .Value
                   .Trim(' ', '\r', '\n'));
        }
Example #3
0
        public void TestRosterExchangeItem()
        {
            var item = XmppXElement.LoadXml(Resource.Get("Xmpp.RosterItemExchange.item1.xml")).ShouldBeOfType <Matrix.Xmpp.RosterItemExchange.RosterExchangeItem>();

            Assert.Equal(item.Action == Matrix.Xmpp.RosterItemExchange.Action.Add, true);

            var item3 = XmppXElement.LoadXml(Resource.Get("Xmpp.RosterItemExchange.item2.xml")).ShouldBeOfType <Matrix.Xmpp.RosterItemExchange.RosterExchangeItem>();

            Assert.Equal(item3.Action == Matrix.Xmpp.RosterItemExchange.Action.Add, true);

            var item4 = XmppXElement.LoadXml(Resource.Get("Xmpp.RosterItemExchange.item3.xml")).ShouldBeOfType <Matrix.Xmpp.RosterItemExchange.RosterExchangeItem>();

            Assert.Equal(item4.Action == Matrix.Xmpp.RosterItemExchange.Action.Modify, true);
        }
Example #4
0
        public void Info_Sub_Element_Should_Exist()
        {
            var metadata = XmppXElement.LoadXml(Resource.Get("Xmpp.Avatar.metadata.xml")).Cast <Metadata>();

            var info = metadata.Info;

            info.ShouldNotBeNull();
            info.CountBytes.ShouldBe(123456);
            info.Height.ShouldBe(64);
            info.Width.ShouldBe(64);
            info.Id.ShouldBe("357a8123a30844a3aa99861b6349264ba67a5694");
            info.Uri.ShouldBe(new System.Uri("http://avatars.example.org/happy.gif"));
            info.Type.ShouldBe("image/gif");
        }
        public async Task Send_Group_Chat_Message_With_Auto_Id_Test()
        {
            var mock = new Mock <IStanzaSender>();

            XmppXElement result = null;

            mock.Setup(s => s.SendAsync(It.IsAny <XmppXElement>()))
            .Callback <XmppXElement>((el) => result = el)
            .Returns(Task.CompletedTask);

            await mock.Object.SendGroupChatMessageAsync(new Jid("*****@*****.**"), "hello world", true);

            result.Cast <Message>().Id.ShouldNotBeNull();
            result.Cast <Message>().Id.Length.ShouldBeGreaterThan(1);
        }
Example #6
0
        public void TestAffiliations()
        {
            var affs = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Owner.affiliations1.xml")).Cast <Affiliations>();

            IEnumerable <Affiliation> affiliations = affs.GetAffiliations();

            Assert.Equal(affs.Node, "princely_musings");

            Assert.Equal(affiliations.Count(), 2);
            Assert.Equal(affiliations.ToArray()[0].AffiliationType, AffiliationType.Owner);
            Assert.Equal(affiliations.ToArray()[1].AffiliationType, AffiliationType.Outcast);

            Assert.Equal(affiliations.ToArray()[0].Jid.Equals("*****@*****.**"), true);
            Assert.Equal(affiliations.ToArray()[1].Jid.Equals("*****@*****.**"), true);
        }
        public void TestRegister2()
        {
            Matrix.Xmpp.Register.Register reg1 = XmppXElement.LoadXml(Resource.Get("Xmpp.Register.register_query2.xml")).ShouldBeOfType <Matrix.Xmpp.Register.Register>();

            Assert.Equal(reg1.Instructions, "instructions");
            Assert.Equal(reg1.Username, "user");
            Assert.Equal(reg1.Password, "12345");
            Assert.Equal(reg1.Email, "*****@*****.**");
            Assert.Equal(reg1.Name, "name");
            Assert.Equal(reg1.First, "first");
            Assert.Equal(reg1.Last, "last");
            Assert.Equal(reg1.Nick, "nick");
            Assert.Equal(reg1.Misc, "misc");
            Assert.Equal(reg1.Remove, false);
        }
Example #8
0
        internal void Publish()
        {
            // TODO: need this to roll up existing ones as well though
            XmppXElement pubkeys = new XmppXElement("urn:xmpp:openpgp:0", "pubkeys");
            XmppXElement pubkey  = new XmppXElement("urn:xmpp:openpgp:0", "pubkey")
            {
                Value = Convert.ToBase64String(this.secretKey.PublicKey.GetEncoded())
            };

            pubkeys.Add(pubkey);
            var item = new Matrix.Xmpp.PubSub.Item();

            item.Add(pubkeys);
            this.xmpp.pubsubManager.PublishItem("", "urn:xmpp:openpgp:0", item);
        }
Example #9
0
        public void TestPubsubSubscriptions()
        {
            var ps = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Owner.pubsub1.xml")).Cast <Matrix.Xmpp.PubSub.Owner.PubSub>();

            Assert.Equal(ps.Type, PubSubOwnerType.Subscriptions);
            Assert.NotEqual(ps.Type, PubSubOwnerType.Purge);

            ps = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Owner.pubsub2.xml")).Cast <Matrix.Xmpp.PubSub.Owner.PubSub>();
            Assert.Equal(ps.Type, PubSubOwnerType.Delete);
            Assert.Equal(ps.Delete.Node, "princely_musings");

            ps = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Owner.pubsub3.xml")).Cast <Matrix.Xmpp.PubSub.Owner.PubSub>();
            Assert.Equal(ps.Type, PubSubOwnerType.Purge);
            Assert.Equal(ps.Purge.Node, "princely_musings");
        }
        public void XmlWithUnicodeTagsTest()
        {
            StreamParser parser = new StreamParser();
            XmppXElement el     = null;

            parser.OnStreamElement += (XmppXElement e) => el = e;

            string xml = @"<foo><फ़क /></foo>";

            var b1 = Encoding.UTF8.GetBytes(xml);

            parser.Write(b1, 0, b1.Length);

            el.Name.LocalName.ShouldBe("फ़क");
        }
Example #11
0
        public static Settings.Settings LoadSettings()
        {
            XmppXElement set = null;

            if (File.Exists(SettingsFilename))
            {
                set = XmppXElement.LoadXml(File.ReadAllText(SettingsFilename));
            }
            if (set is Settings.Settings)
            {
                return(set as Settings.Settings);
            }

            return(new Settings.Settings());
        }
Example #12
0
        public void TestEnabled()
        {
            var enabled = XmppXElement.LoadXml(Resource.Get("Xmpp.StreamManagement.enabled1.xml")).Cast <Enabled>();

            Assert.Equal(enabled.Id, "abcd");
            Assert.Equal(enabled.Resume, true);

            var enabled2 = XmppXElement.LoadXml(Resource.Get("Xmpp.StreamManagement.enabled2.xml")).Cast <Enabled>();

            Assert.Equal(enabled2.Resume, true);

            var enabled3 = XmppXElement.LoadXml(Resource.Get("Xmpp.StreamManagement.enabled3.xml")).Cast <Enabled>();

            Assert.Equal(enabled3.Resume, false);
        }
Example #13
0
        public void TestSubscriptions()
        {
            var subs = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Owner.subscriptions1.xml")).Cast <Subscriptions>();

            Assert.Equal(subs.Node, "princely_musings");
            IEnumerable <Subscription> ss = subs.GetSubscriptions();


            Assert.Equal(ss.Count(), 2);
            Assert.Equal(ss.ToArray()[0].Jid.Equals("*****@*****.**"), true);
            Assert.Equal(ss.ToArray()[0].SubscriptionState, SubscriptionState.None);

            Assert.Equal(ss.ToArray()[1].Jid.Equals("*****@*****.**"), true);
            Assert.Equal(ss.ToArray()[1].SubscriptionState, SubscriptionState.Subscribed);
        }
Example #14
0
        public void TestEvent7()
        {
            DateTime     dt    = DateTime.MinValue;
            XmppXElement xmpp1 = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Event.event7.xml")).Cast <Matrix.Xmpp.PubSub.Event.Event>();

            var ev = xmpp1 as Matrix.Xmpp.PubSub.Event.Event;

            Assert.NotEqual(ev.Type, PubSubEventType.Items);
            Assert.Equal(ev.Type, PubSubEventType.Subscription);

            Assert.Equal(ev.Subscription.Node, "princely_musings");
            Assert.Equal(ev.Subscription.Jid.Equals("*****@*****.**"), true);
            Assert.Equal(ev.Subscription.Id, "ba49252aaa4f5d320c24d3766f0bdcade78c78d3");
            Assert.Equal(ev.Subscription.SubscriptionState, Matrix.Xmpp.PubSub.SubscriptionState.Subscribed);

            dt = ev.Subscription.Expiry;


            var ev2 = new Matrix.Xmpp.PubSub.Event.Event
            {
                Type         = PubSubEventType.Subscription,
                Subscription =
                {
                    Node = "princely_musings",
                    Jid  = "*****@*****.**",
                    Id   = "ba49252aaa4f5d320c24d3766f0bdcade78c78d3",
                    SubscriptionState = Matrix.Xmpp.PubSub.SubscriptionState.Subscribed,
                    Expiry            = dt
                }
            };

            ev2.ShouldBe(Resource.Get("Xmpp.PubSub.Event.event7.xml"));


            ev2 = new Matrix.Xmpp.PubSub.Event.Event
            {
                Type         = PubSubEventType.Subscription,
                Subscription =
                {
                    Node = "princely_musings",
                    Jid  = "*****@*****.**",
                    Id   = "ba49252aaa4f5d320c24d3766f0bdcade78c78d3",
                    SubscriptionState = Matrix.Xmpp.PubSub.SubscriptionState.Subscribed,
                    Expiry            = dt
                }
            };
            ev2.ShouldBe(Resource.Get("Xmpp.PubSub.Event.event7.xml"));
        }
Example #15
0
        public async Task SubscribeTest()
        {
            var mock = new Mock <IStanzaSender>();

            XmppXElement result = null;

            mock.Setup(s => s.SendAsync(It.IsAny <XmppXElement>()))
            .Callback <XmppXElement>((el) => result = el)
            .Returns(Task.CompletedTask);

            string expectedResult = "<presence xmlns='jabber:client' to='*****@*****.**' type='subscribe'/>";

            await mock.Object.SubscribeAsync(new Jid("*****@*****.**"));

            result.ShouldBe(expectedResult);
        }
        public async Task Send_Group_Chat_Message_Test()
        {
            var mock = new Mock <IStanzaSender>();

            XmppXElement result = null;

            mock.Setup(s => s.SendAsync(It.IsAny <XmppXElement>()))
            .Callback <XmppXElement>((el) => result = el)
            .Returns(Task.CompletedTask);

            string expectedResult = "<message xmlns='jabber:client' to='*****@*****.**' type='groupchat'><body>hello world</body></message>";

            await mock.Object.SendGroupChatMessageAsync(new Jid("*****@*****.**"), "hello world", false);

            result.ShouldBe(expectedResult);
        }
        public void TestSubscriptions()
        {
            var subs = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.subscription1.xml")).Cast <Subscriptions>();

            Assert.Equal(subs.Node, "princely_musings");
            IEnumerable <Subscription> ss = subs.GetSubscriptions();

            Assert.Equal(ss.Count(), 2);
            Assert.Equal(ss.ToArray()[0].Jid.Equals("*****@*****.**"), true);
            Assert.Equal(ss.ToArray()[0].SubscriptionState, SubscriptionState.Subscribed);
            Assert.Equal(ss.ToArray()[0].Id, "123");

            Assert.Equal(ss.ToArray()[1].Jid.Equals("*****@*****.**"), true);
            Assert.Equal(ss.ToArray()[1].SubscriptionState, SubscriptionState.Unconfigured);
            Assert.Equal(ss.ToArray()[1].Id, "456");
        }
Example #18
0
        public void TypeTest()
        {
            var xmpp1 = XmppXElement.LoadXml(Resource.Get("Xmpp.Dialback.verify1.xml"));

            xmpp1.ShouldBeOfType <Verify>();
            xmpp1.Cast <Verify>().Type.ShouldBe(VerifyType.Valid);

            var xmpp2 = XmppXElement.LoadXml(Resource.Get("Xmpp.Dialback.verify2.xml"));

            xmpp2.ShouldBeOfType <Verify>();
            xmpp2.Cast <Verify>().Type.ShouldBe(VerifyType.Invalid);

            var xmpp3 = XmppXElement.LoadXml(Resource.Get("Xmpp.Dialback.verify3.xml"));

            xmpp3.ShouldBeOfType <Verify>();
            xmpp3.Cast <Verify>().Type.ShouldBe(VerifyType.None);
        }
Example #19
0
        public void Test1()
        {
            XmppXElement xmpp1 = XmppXElement.LoadXml(XML1);

            xmpp1.ShouldBeOfType <Note>();

            var note = xmpp1 as Note;

            if (note != null)
            {
                note.Value.ShouldBe(VALUE);
                note.Value.ShouldNotBe("dummy");
                note.Type.ShouldBe(NoteType.Info);
                note.Type.ShouldNotBe(NoteType.Error);
                note.Type.ShouldNotBe(NoteType.Warn);
            }
        }
        public void DescendantsTest()
        {
            var msg      = XmppXElement.LoadXml(Resource.Get("Xml.message.xml")).Cast <Message>();
            var elements = msg.Descendants <Matrix.Xmpp.XData.Data>();

            elements.ShouldNotBeNull();
            elements.Count().ShouldBe(1);

            var firstResult = elements.First();

            firstResult.ShouldBeOfType <Matrix.Xmpp.XData.Data>();

            var elements2 = msg.Descendants <Matrix.Xmpp.XData.Field>();

            elements2.ShouldNotBeNull();
            elements2.Count().ShouldBeGreaterThan(1);
        }
Example #21
0
        public void TestErrors()
        {
            XmppXElement.LoadXml(Resource.Get("Xmpp.Client.error3.xml")).Cast <Matrix.Xmpp.Client.Error>().Condition.ShouldBe(Matrix.Xmpp.Base.ErrorCondition.Forbidden);
            XmppXElement.LoadXml(Resource.Get("Xmpp.Client.error4.xml")).Cast <Matrix.Xmpp.Client.Error>().Condition.ShouldBe(Matrix.Xmpp.Base.ErrorCondition.Gone);
            XmppXElement.LoadXml(Resource.Get("Xmpp.Client.error5.xml")).Cast <Matrix.Xmpp.Client.Error>().Condition.ShouldBe(Matrix.Xmpp.Base.ErrorCondition.InternalServerError);
            XmppXElement.LoadXml(Resource.Get("Xmpp.Client.error6.xml")).Cast <Matrix.Xmpp.Client.Error>().Condition.ShouldBe(Matrix.Xmpp.Base.ErrorCondition.ItemNotFound);
            XmppXElement.LoadXml(Resource.Get("Xmpp.Client.error7.xml")).Cast <Matrix.Xmpp.Client.Error>().Condition.ShouldBe(Matrix.Xmpp.Base.ErrorCondition.JidMalformed);
            XmppXElement.LoadXml(Resource.Get("Xmpp.Client.error8.xml")).Cast <Matrix.Xmpp.Client.Error>().Condition.ShouldBe(Matrix.Xmpp.Base.ErrorCondition.BadRequest);
            XmppXElement.LoadXml(Resource.Get("Xmpp.Client.error9.xml")).Cast <Matrix.Xmpp.Client.Error>().Condition.ShouldBe(Matrix.Xmpp.Base.ErrorCondition.NotAcceptable);
            XmppXElement.LoadXml(Resource.Get("Xmpp.Client.error10.xml")).Cast <Matrix.Xmpp.Client.Error>().Condition.ShouldBe(Matrix.Xmpp.Base.ErrorCondition.NotAuthorized);
            XmppXElement.LoadXml(Resource.Get("Xmpp.Client.error11.xml")).Cast <Matrix.Xmpp.Client.Error>().Condition.ShouldBe(Matrix.Xmpp.Base.ErrorCondition.NotModified);
            XmppXElement.LoadXml(Resource.Get("Xmpp.Client.error12.xml")).Cast <Matrix.Xmpp.Client.Error>().Condition.ShouldBe(Matrix.Xmpp.Base.ErrorCondition.PaymentRequired);

            var err = XmppXElement.LoadXml(Resource.Get("Xmpp.Client.error1.xml")).Cast <Matrix.Xmpp.Client.Error>();

            err.Text.ShouldBe("dummy text");
        }
        internal async Task ResumeAsync(CancellationToken cancellationToken)
        {
            this.xmppConnection.XmppSessionState.Value = SessionState.Resuming;

            var res = await SendAsync <Resumed, Failed>(
                new Resume()
            {
                PreviousId        = this.StreamId,
                LastHandledStanza = IncomingStanzaCounter.Value
            }
                , cancellationToken
                );

            if (res.OfType <Resumed>())
            {
                var resumed = res.Cast <Resumed>();

                OutgoingStanzaCounter.Value = resumed.LastHandledStanza;
                StreamId = resumed.PreviousId;

                xmppConnection.XmppSessionState.Value = SessionState.Resumed;

                // send stanzas
                var toResend = new XmppXElement[unacked.Count];
                unacked.Values.CopyTo(toResend, 0);
                unacked.Clear();
                foreach (var el in toResend)
                {
                    await SendAsync(el);
                }
            }
            else if (res.OfType <Failed>())
            {
                // reset all values to default
                IsEnabled = false;
                StreamId  = null;
                CanResume = false;
                IncomingStanzaCounter.Reset();
                OutgoingStanzaCounter.Reset();
                unacked.Clear(); // TODO, let users know about the lost packages

                // set state, so we can continue automatically with resource binding
                this.xmppConnection.XmppSessionState.Value = SessionState.ResumeFailed;
            }
        }
        public void TestMessageWuthSecurityLabel()
        {
            var msg      = XmppXElement.LoadXml(Resource.Get("Xmpp.SecurityLabels.message1.xml")).Cast <Message>();
            var secLabel = msg.Element <SecurityLabel>();

            Assert.Equal(secLabel != null, true);

            var display = secLabel.DisplayMarking;

            Assert.Equal(display.ForegroundColor == Color.Black, true);
            Assert.Equal(display.BackgroundColor == Color.Red, true);
            Assert.Equal(display.Value, "SECRET");

            var label = secLabel.Label;
            var ess   = label.EssSecurityLabel;

            Assert.Equal(ess.Value.Trim(), "MQYCAQQGASk=");
        }
        public void BuildCompression()
        {
            var expectedXml1 = Resource.Get("Xmpp.Compression.compression1.xml");
            var comp         = new Matrix.Xmpp.Stream.Features.Compression();

            comp.AddMethod(Methods.Zlib);
            comp.ShouldBe(expectedXml1);

            var comp1 = XmppXElement.LoadXml(Resource.Get("Xmpp.Compression.compression1.xml")).Cast <Matrix.Xmpp.Stream.Features.Compression>();

            comp1.Supports(Methods.Zlib).ShouldBe(true);
            comp1.Supports(Methods.Lzw).ShouldBe(false);

            var comp2 = XmppXElement.LoadXml(Resource.Get("Xmpp.Compression.compression2.xml")).Cast <Matrix.Xmpp.Stream.Features.Compression>();

            comp2.Supports(Methods.Zlib).ShouldBe(false);
            comp2.Supports(Methods.Lzw).ShouldBe(false);
        }
        public void TestCatalog()
        {
            var catalog = XmppXElement.LoadXml(Resource.Get("Xmpp.SecurityLabels.catalog1.xml")).Cast <Catalog>();

            Assert.Equal(catalog != null, true);
            Assert.Equal(catalog.To.Bare, "example.com");
            Assert.Equal(catalog.CatalogName, "Default");
            Assert.Equal(catalog.Description, "an example set of labels");
            Assert.Equal(catalog.Restrictive, false);

            var items = catalog.GetItems();

            Assert.Equal(items.Count(), 4);
            var item1 = items.ElementAt(0);

            Assert.Equal(item1.Selector, "Classified|SECRET");
            var seclabel1 = item1.SecurityLabel;

            Assert.Equal(seclabel1.DisplayMarking.ForegroundColor == Color.Black, true);
            Assert.Equal(seclabel1.DisplayMarking.BackgroundColor == Color.Red, true);
            Assert.Equal(seclabel1.DisplayMarking.Value, "SECRET");

            var item2 = items.ElementAt(1);

            Assert.Equal(item2.Selector, "Classified|CONFIDENTIAL");
            var seclabel2 = item2.SecurityLabel;

            Assert.Equal(seclabel2.DisplayMarking.ForegroundColor == Color.Black, true);
            Assert.Equal(seclabel2.DisplayMarking.BackgroundColor == Color.Navy, true);
            Assert.Equal(seclabel2.DisplayMarking.Value, "CONFIDENTIAL");

            var item3 = items.ElementAt(2);

            Assert.Equal(item3.Selector, "Classified|RESTRICTED");
            var seclabel3 = item3.SecurityLabel;

            Assert.Equal(seclabel3.DisplayMarking.ForegroundColor == Color.Black, true);
            Assert.Equal(seclabel3.DisplayMarking.BackgroundColor == Color.Aqua, true);
            Assert.Equal(seclabel3.DisplayMarking.Value, "RESTRICTED");

            var item4 = items.ElementAt(3);

            Assert.Equal(item4.Selector, "UNCLASSIFIED");
        }
Example #26
0
        public void TestEmail()
        {
            Email email1 = XmppXElement.LoadXml(Resource.Get("Xmpp.Vcard.email1.xml")).Cast <Email>();

            email1.Address.ShouldBe("*****@*****.**");
            email1.IsPreferred.ShouldBeFalse();


            Email email2 = XmppXElement.LoadXml(Resource.Get("Xmpp.Vcard.email2.xml")).Cast <Email>();

            email2.Address.ShouldBe("*****@*****.**");
            email2.IsPreferred.ShouldBeTrue();

            email1.ShouldBe(Resource.Get("Xmpp.Vcard.email1.xml"));

            Email email4 = new Email("*****@*****.**", true);

            email4.ShouldBe(Resource.Get("Xmpp.Vcard.email2.xml"));
        }
Example #27
0
        /// <summary>
        /// parse a response struct
        /// </summary>
        /// <param name="el">The el.</param>
        /// <returns></returns>
        private static StructParameter ParseStruct(XmppXElement el)
        {
            #region Xml sample
            //<struct>
            //   <member>
            //      <name>x</name>
            //      <value><i4>20</i4></value>
            //   </member>
            //   <member>
            //      <name>y</name>
            //      <value><string>cow</string></value>
            //   </member>
            //   <member>
            //      <name>z</name>
            //      <value><double>3,14</double></value>
            //   </member>
            //</struct>
            #endregion

            var structParameter = new StructParameter();

            var members = el.Elements <Member>();

            foreach (var member in members)
            {
                var xElementName = member.Element <Name>();
                if (xElementName == null)
                {
                    continue;
                }

                var name = xElementName.Value;

                // parse this member value
                var xElementValue = member.Element <Value>();
                if (xElementValue != null)
                {
                    structParameter.Add(name, ParseValue(xElementValue));
                }
            }
            return(structParameter);
        }
Example #28
0
        public void TestEvent()
        {
            var ev = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Event.event1.xml")).Cast <Matrix.Xmpp.PubSub.Event.Event>();

            Assert.Equal(ev.Type, PubSubEventType.Items);
            Assert.NotEqual(ev.Type, PubSubEventType.Delete);

            var items = ev.Items;

            Assert.Equal(items.GetItems().Count(), 2);
            Assert.NotEqual(items.GetItems().Count(), 5);

            Assert.Equal(items.GetItems().ToArray()[0].Id, "ab");
            Assert.Equal(items.GetItems().ToArray()[1].Id, "cd");


            ev = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Event.event2.xml")).Cast <Matrix.Xmpp.PubSub.Event.Event>();

            Assert.Equal(ev.Type, PubSubEventType.Items);
            items = ev.Items;
            Assert.Equal(items.GetRetracts().Count(), 1);
            Assert.NotEqual(items.GetRetracts().Count(), 2);
            Assert.Equal(items.GetRetracts().ToArray()[0].Id, "ae890ac52d0df67ed7cfdf51b644e901");
            Assert.NotEqual(items.GetRetracts().ToArray()[0].Id, "_ae890ac52d0df67ed7cfdf51b644e901");


            ev = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Event.event3.xml")).Cast <Matrix.Xmpp.PubSub.Event.Event>();
            Assert.Equal(ev.Type, PubSubEventType.Configuration);
            Assert.NotEqual(ev.Type, PubSubEventType.Delete);


            ev = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Event.event4.xml")).Cast <Matrix.Xmpp.PubSub.Event.Event>();
            Assert.NotEqual(ev.Type, PubSubEventType.Items);
            Assert.Equal(ev.Type, PubSubEventType.Delete);
            Assert.Equal(ev.Delete.Node, "princely_musings");

            ev = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Event.event5.xml")).Cast <Matrix.Xmpp.PubSub.Event.Event>();
            Assert.NotEqual(ev.Type, PubSubEventType.Items);
            Assert.Equal(ev.Type, PubSubEventType.Purge);
            Assert.Equal(ev.Purge.Node, "princely_musings");
        }
Example #29
0
        public void TestDescription()
        {
            var desc = XmppXElement.LoadXml(Resource.Get("Xmpp.Jingle.description1.xml")).Cast <Description>();

            Assert.Equal(desc.Media == Media.Audio, true);
            var payloads = desc.GetPayloadTypes();

            Assert.Equal(payloads.Count(), 2);

            var p1 = payloads.ToArray()[0];
            var p2 = payloads.ToArray()[1];

            Assert.Equal(p1.Id, 110);
            Assert.Equal(p2.Id, 97);

            Assert.Equal(p1.Name, "SPEEX");
            Assert.Equal(p2.Name, "SPEEX");

            Assert.Equal(p1.Clockrate, 16000);
            Assert.Equal(p2.Clockrate, 8000);
        }
        public void Test1()
        {
            XmppXElement xmpp1 = XmppXElement.LoadXml(XML1);

            xmpp1.ShouldBeOfType <Actions>();

            var actions = xmpp1 as Actions;

            if (actions != null)
            {
                actions.Execute.ShouldBe(Matrix.Xmpp.AdHocCommands.Action.Complete);
                actions.Execute.ShouldNotBe(Matrix.Xmpp.AdHocCommands.Action.Execute);
                actions.Execute.ShouldNotBe(Matrix.Xmpp.AdHocCommands.Action.None);

                actions.Previous.ShouldBeTrue();
                actions.Complete.ShouldBeTrue();
                actions.Next.ShouldBeFalse();

                actions.Action.ShouldBe(Matrix.Xmpp.AdHocCommands.Action.Complete | Matrix.Xmpp.AdHocCommands.Action.Prev);
            }
        }
        public void TestAffiliations()
        {
            var affs = XmppXElement.LoadXml(Resource.Get("Xmpp.PubSub.Owner.affiliations4.xml")).Cast <Affiliations>();

            IEnumerable <Affiliation> affiliations = affs.GetAffiliations();

            Assert.Equal(affs.Node, "princely_musings");

            Assert.Equal(affiliations.Count(), 5);
            Assert.Equal(affiliations.ToArray()[0].AffiliationType, AffiliationType.Owner);
            Assert.Equal(affiliations.ToArray()[1].AffiliationType, AffiliationType.Publisher);
            Assert.Equal(affiliations.ToArray()[2].AffiliationType, AffiliationType.Outcast);
            Assert.Equal(affiliations.ToArray()[3].AffiliationType, AffiliationType.Owner);
            Assert.Equal(affiliations.ToArray()[4].AffiliationType, AffiliationType.PublishOnly);

            Assert.Equal(affiliations.ToArray()[0].Node, "node1");
            Assert.Equal(affiliations.ToArray()[1].Node, "node2");
            Assert.Equal(affiliations.ToArray()[2].Node, "node5");
            Assert.Equal(affiliations.ToArray()[3].Node, "node6");
            Assert.NotEqual(affiliations.ToArray()[3].Node, "node7");
        }
Example #32
0
 public void Send(XmppXElement element)
 {
     Send(element.ToString());
 }
Example #33
0
 public void Send(XmppXElement element, DataSentAction action)
 {
     Send(element.ToString(), action);
 }
Example #34
0
 public void Send(XmppXElement element, object userState)
 {
     Send(element.ToString(), userState);
 }
Example #35
0
 public void UpdateSubscribers(XmppXElement element)
 {
     foreach (var item in Roster.GetRoster())
     {
         if (item.Subscription == Xmpp.Roster.Subscription.to
             || item.Subscription == Xmpp.Roster.Subscription.both)
         {
             server.MessageManager.DeliverMessage(item.Jid.User, element);
         }
     }
 }