Beispiel #1
0
        public async void ScanAllRange_ShouldThrowHostNullException()
        {
            string       host         = null;
            RangeOfPorts rangeOfPorts = _validRange;

            IScanner scanner = new RangeOfPortsScanner
            {
                Host  = host,
                Ports = rangeOfPorts.GetPortsArray(),
            };

            scanner.OnScanEnding += Scanner_OnScanEnding;

            await Assert.ThrowsAsync <ArgumentNullException>("Host", async() => await scanner.ScanAllAsync());
        }
Beispiel #2
0
        public async void ScanAllRange_ShouldDoNothingBecauseHostAreEmpty()
        {
            string       host         = "";
            RangeOfPorts rangeOfPorts = _validRange;

            IScanner scanner = new RangeOfPortsScanner
            {
                Host  = host,
                Ports = rangeOfPorts.GetPortsArray(),
            };

            scanner.OnScanEnding += Scanner_OnScanEnding;

            await scanner.ScanAllAsync();

            Assert.False(_results.HostIsValid);
        }
Beispiel #3
0
        public async void ScanAllRange_ShouldThrowRangeExceptionBecausePortsNotInitialized()
        {
            string       host         = "localhost";
            RangeOfPorts rangeOfPorts = new RangeOfPorts();

            await Assert.ThrowsAsync <RangeOfPortsException>(async() =>
            {
                IScanner scanner = new RangeOfPortsScanner
                {
                    Host  = host,
                    Ports = rangeOfPorts.GetPortsArray(),
                };
                scanner.OnScanEnding += Scanner_OnScanEnding;

                await scanner.ScanAllAsync();
            });
        }
Beispiel #4
0
        public async void ScanAllRange_ShouldThrowRangeExceptionBecausePortsIncorrect()
        {
            string       host         = "localhost";
            RangeOfPorts rangeOfPorts = new RangeOfPorts
            {
                FromTcp = 20,
                ToTcp   = 15,
            };

            await Assert.ThrowsAsync <RangeOfPortsException>(async() =>
            {
                IScanner scanner = new RangeOfPortsScanner
                {
                    Host  = host,
                    Ports = rangeOfPorts.GetPortsArray(),
                };
                scanner.OnScanEnding += Scanner_OnScanEnding;

                await scanner.ScanAllAsync();
            });
        }
Beispiel #5
0
        public async void ScanAllRange_ShouldScanRangeOfPorts()
        {
            string       host         = "localhost";
            RangeOfPorts rangeOfPorts = _validRange;

            IScanner scanner = new RangeOfPortsScanner
            {
                Host  = host,
                Ports = rangeOfPorts.GetPortsArray(),
            };

            scanner.OnScanEnding += Scanner_OnScanEnding;

            await scanner.ScanAllAsync();

            Assert.True(_results.HostIsValid);
            foreach (var result in _results.PortsAfterScan)
            {
                Assert.True(result.State == PortState.Opened || result.State == PortState.Closed);
            }
        }