public void StopAfterStart_ShouldCancelProperly()
        {
            Boolean         wasFound       = false;
            String          endPointToScan = "localhost";
            PortScanManager instance       = new PortScanManager(endPointToScan);

            instance.PortScanResult += (sender, e) =>
            {
                Debug.WriteLine("Port scan found: {0} ({1})", e.Port, e.PortType);
                wasFound = true;
            };

            instance.Start();
            instance.Stop();

            try
            {
                Task.WaitAll(instance.Tasks.ToArray());
            }
            catch (AggregateException exception)
            {
                if (exception.InnerException is TaskCanceledException)
                {
                }
                else
                {
                    Assert.Fail("TaskCanceledException should have been thrown.");
                }
            }
        }
        /// <summary>
        /// Defines the method to be called when the command is invoked.
        /// </summary>
        /// <param name="parameter">Data used by the command.  If the
        /// command does not require data to be passed, this object
        /// can be set to null.</param>
        public void Execute(object parameter)
        {
            _canExecute = false;
            IsActive    = true;
            OnCanExecuteChanged();

            CurrentPortScanManager = new PortScanManager(HostName);
            PortScanResults.Clear();
            CurrentPortScanManager.PortScanResult += (sender, e) =>
            {
                App.CurrentDispatcher.Invoke(() =>
                {
                    PortScanResults.Add(e);
                });
            };

            CurrentPortScanManager.Start(1, 600, PortTypes.Tcp);

            Task.Factory.StartNew(() =>
            {
                Task.WaitAll(CurrentPortScanManager.Tasks.ToArray());

                App.CurrentDispatcher.Invoke(() =>
                {
                    _canExecute = true;
                    OnCanExecuteChanged();
                    IsActive = false;
                });
            });
        }
        public void StartWithHighStopArguments_ThrowsException()
        {
            Boolean         wasFound       = false;
            String          endPointToScan = "localhost";
            PortScanManager instance       = new PortScanManager(endPointToScan);

            instance.PortScanResult += (sender, e) =>
            {
                Debug.WriteLine("Port scan found: {0} ({1})", e.Port, e.PortType);
                wasFound = true;
            };

            instance.Start(120, UInt16.MaxValue + 1, PortTypes.Tcp);

            Assert.Fail("Should have thrown ArgumentOutOfRangeException.");
        }
        public void StartWithValidUdpSettings_ShouldFindSomething()
        {
            Boolean         wasFound       = false;
            String          endPointToScan = "localhost";
            PortScanManager instance       = new PortScanManager(endPointToScan);

            instance.PortScanResult += (sender, e) =>
            {
                Debug.WriteLine("Port scan found: {0} ({1})", e.Port, e.PortType);
                wasFound = true;
            };

            instance.Start(120, 150, PortTypes.Udp);

            Task.WaitAll(instance.Tasks.ToArray());

            Assert.IsTrue(wasFound);
        }