Ejemplo n.º 1
0
 public void Close_CallTwice_ThrowObjectDisposedException()
 {
     // Arrange
     using (var client = new DataStreamingClient(new IPEndPoint(IPAddress.Loopback, LISTENING_PORT)))
     {
         // Assert
         Assert.Throws <ObjectDisposedException>(() =>
         {
             client.Close();
             client.Close();
         });
     }
 }
Ejemplo n.º 2
0
        public void Close_ClientConnected_ClientDisconnected()
        {
            // Arrange
            int timesConnectedChangedRaised = 0;
            var actualConnectedStates       = new List <bool>();

            var client = new DataStreamingClient(new IPEndPoint(IPAddress.Loopback, LISTENING_PORT));

            client.ConnectChanged += (sender, args) =>
            {
                timesConnectedChangedRaised++;
                actualConnectedStates.Add(args.Connected);
            };

            var connectionTask = client.ConnectAsync();

            connectionTask.Wait(TimeSpan.FromSeconds(1));

            // Act
            client.Close();

            // Assert
            var expectedConnectedStates = new List <bool>
            {
                true,
                false
            };

            CollectionAssert.AreEquivalent(expectedConnectedStates, actualConnectedStates);
            Assert.AreEqual(2, timesConnectedChangedRaised);
        }