public void Sends_Stream_Header_To_Transmit_Pipe()
        {
            var sentHeader = default(XmlElement);

            HandlersRegistry.RegisterTransmitPipeHandler <XmlElement>(request => sentHeader = request);

            MessageSender.SendTransportMessage(TransportMessage.Opened);

            Assert.NotNull(sentHeader);
            Assert.Equal("stream:stream", sentHeader.Name);
        }
Beispiel #2
0
        public async Task SendUnsubscribeRequestAsync_Sends_Correct_Presence_Stanza()
        {
            var subscriptionJid = $"{Guid.NewGuid()}@domain.com";
            var expectedStanza  = PresenceStanza.New(PresenceStanza.Type.Unsubscribe).To(subscriptionJid);
            var actualStanza    = default(XmlElement);

            HandlersRegistry.RegisterTransmitPipeHandler <XmlElement>(e => actualStanza = e);

            await MessageSender.SendUnsubscribeRequestAsync(subscriptionJid);

            Assert.Equal(expectedStanza, actualStanza);
        }
Beispiel #3
0
        public async Task SendRosterItemUpdateAsync_Sends_Correct_Request_Stanza()
        {
            var item           = new RosterItem("*****@*****.**", "user");
            var expectedStanza = CreateRosterStanza(IqStanza.Type.Set, item).From(jid);
            var actualStanza   = default(XmlElement);

            HandlersRegistry.RegisterTransmitPipeHandler <XmlElement>(s => actualStanza = s);

            var requestId = await MessageSender.SendRosterItemUpdateAsync(jid, item);

            expectedStanza.Id(requestId);

            Assert.Equal(expectedStanza, actualStanza);
        }
Beispiel #4
0
        public async Task SendRosterRequestAsync_Sends_Roster_Request_Stanza()
        {
            var expectedStanza = CreateRosterStanza(IqStanza.Type.Get).From(jid);
            var actualStanza   = default(XmlElement);

            HandlersRegistry.RegisterTransmitPipeHandler <XmlElement>(s => actualStanza = s);

            var requestId = await MessageSender.SendRosterRequestAsync(jid);

            expectedStanza.Id(requestId);

            Assert.False(string.IsNullOrEmpty(requestId));
            Assert.Equal(expectedStanza, actualStanza);
        }
        public void Can_Negotiate_Tls_Feature()
        {
            XmlElement sentElement      = default;
            bool?      setTlsSend       = default;
            var        featuresResponse = new XmlElement("stream:features", new XmlElement("starttls").Xmlns(XmppNamespaces.Tls));

            HandlersRegistry.RegisterTransmitPipeHandler <XmlElement>(request => sentElement           = request);
            HandlersRegistry.RegisterTransportMessageHandler(TransportMessage.SetTls, () => setTlsSend = true);

            MessageSender.SendTransportMessage(TransportMessage.Opened);
            MessageSender.SendToReceivePipe(StreamHeader.Client());
            MessageSender.SendToReceivePipe(featuresResponse);

            Assert.Equal("starttls", sentElement.Name);

            MessageSender.SendToReceivePipe(new XmlElement("proceed").Xmlns(XmppNamespaces.Tls));
            Assert.True(setTlsSend);
        }
Beispiel #6
0
        public async Task SendStatusUpdateAsync_Sends_Correct_Presence_Stanza()
        {
            var expectedStatus = new PresenceStatus
            {
                AvailabilitySubstate = AvailabilitySubstate.Chat,
                StatusText           = Guid.NewGuid().ToString()
            };
            var token      = new CancellationToken();
            var sentStanza = default(XmlElement);

            HandlersRegistry.RegisterTransmitPipeHandler <XmlElement>(e => sentStanza = e);

            await MessageSender.SendStatusUpdateAsync(expectedStatus, token);

            Assert.NotNull(sentStanza);
            Assert.Equal(expectedStatus.StatusText, sentStanza.Child("status").Value);
            Assert.Equal(expectedStatus.AvailabilitySubstate.ToString().ToLower(), sentStanza.Child("show").Value);
        }
Beispiel #7
0
        public async Task SendRosterItemRemoveRequestAsync_Sends_Correct_Request_Stanza()
        {
            var item           = new RosterItem("*****@*****.**", "user");
            var expectedStanza = CreateRosterStanza(IqStanza.Type.Set, item).From(jid);
            var itemElement    = expectedStanza.Child("query").Child("item");

            itemElement.SetAttributeValue("subscription", "remove");
            var actualStanza = default(XmlElement);

            HandlersRegistry.RegisterTransmitPipeHandler <XmlElement>(s => actualStanza = s);


            var requestId = await MessageSender.SendRosterItemRemoveRequestAsync(jid, item);

            expectedStanza.Id(requestId);

            Assert.Equal(expectedStanza, actualStanza);
        }