예제 #1
0
        public void CommsServer_SendNullMessageThrowsException()
        {
            var socketFactory = new MockSocketFactory();
            var server        = new SsdpCommunicationsServer(socketFactory);

            UdpEndPoint destination = new UdpEndPoint()
            {
                IPAddress = "192.168.1.100", Port = 1701
            };

            server.SendMessage(null, destination);
        }
예제 #2
0
        public void CommsServer_FullConstructor_SpecifiedPortUsedForUnicastSocket()
        {
            var socketFactory = new MockSocketFactory();
            var server        = new SsdpCommunicationsServer(socketFactory, 1702, 4);

            server.SendMessage(System.Text.UTF8Encoding.UTF8.GetBytes("Hello!"), new UdpEndPoint()
            {
                IPAddress = "192.168.1.100", Port = 1900
            });
            var mockSocket = socketFactory.UnicastSocket as MockSocket;

            Assert.AreEqual(1702, mockSocket.LocalPort);
        }
예제 #3
0
        public void CommsServer_DisposeServerDisposesUnicastSocket()
        {
            var socketFactory = new MockSocketFactory();
            var server        = new SsdpCommunicationsServer(socketFactory);

            server.SendMessage(System.Text.UTF8Encoding.UTF8.GetBytes("Hello!"), new UdpEndPoint()
            {
                IPAddress = "192.168.1.100", Port = 1701
            });
            server.Dispose();

            var mockSocket = socketFactory.UnicastSocket as MockSocket;

            Assert.IsTrue(mockSocket.IsDisposed);
        }
예제 #4
0
        public void CommsServer_SendMessageV6SendsToSsdpMulticastGroupOnUnicastSoket()
        {
            var socketFactory = new MockSocketFactory();
            var server        = new SsdpCommunicationsServer(socketFactory);

            string message = "Hello Everyone!";

            server.SendMessage(System.Text.UTF8Encoding.UTF8.GetBytes(message), new UdpEndPoint
            {
                IPAddress = SsdpConstants.MulticastLinkLocalAddressV6,
                Port      = SsdpConstants.MulticastPort
            });

            Assert.IsNotNull(socketFactory.UnicastSocket);

            var mockSocket = socketFactory.UnicastSocket as MockSocket;

            Assert.AreEqual(message, System.Text.UTF8Encoding.UTF8.GetString(mockSocket.LastMessage));
            Assert.AreEqual(SsdpConstants.MulticastLinkLocalAddressV6, mockSocket.LastSentTo.IPAddress);
            Assert.AreEqual(SsdpConstants.MulticastPort, mockSocket.LastSentTo.Port);
        }
예제 #5
0
        public void CommsServer_SendMessageSendsOnUnicastSocket()
        {
            var socketFactory = new MockSocketFactory();
            var server        = new SsdpCommunicationsServer(socketFactory);

            string      message     = "Hello!";
            UdpEndPoint destination = new UdpEndPoint()
            {
                IPAddress = "192.168.1.100", Port = 1701
            };

            server.SendMessage(System.Text.UTF8Encoding.UTF8.GetBytes(message), destination);

            Assert.IsNotNull(socketFactory.UnicastSocket);

            var mockSocket = socketFactory.UnicastSocket as MockSocket;

            Assert.AreEqual(message, System.Text.UTF8Encoding.UTF8.GetString(mockSocket.LastMessage));
            Assert.AreEqual(destination.IPAddress, mockSocket.LastSentTo.IPAddress);
            Assert.AreEqual(destination.Port, mockSocket.LastSentTo.Port);
        }
예제 #6
0
        public void CommsServer_StopListeningForResponsesDisposesUnicastSocket()
        {
            var socketFactory = new MockSocketFactory();
            var server        = new SsdpCommunicationsServer(socketFactory);

            string      message     = "Hello!";
            UdpEndPoint destination = new UdpEndPoint()
            {
                IPAddress = "192.168.1.100", Port = 1701
            };

            server.SendMessage(System.Text.UTF8Encoding.UTF8.GetBytes(message), destination);

            var mockSocket = socketFactory.UnicastSocket as MockSocket;

            Assert.IsFalse(mockSocket.IsDisposed);

            server.StopListeningForResponses();

            Assert.IsTrue(mockSocket.IsDisposed);
        }