Esempio n. 1
0
        public void ConstructorSetup_DoesNotThrow()
        {
            Utils.MethodStart();

            foreach (var timeoutPing in EnumValues.GetTimeoutMs())
            {
                foreach (var timeoutTask in EnumValues.GetTimeoutMs())
                {
                    foreach (var dontFragment in EnumValues.GetBool())
                    {
                        foreach (var bufferSize in EnumValues.GetBytes())
                        {
                            foreach (var ttl in EnumValues.GetBytes())
                            {
                                Assert.DoesNotThrow(() =>
                                {
                                    _ = new PingEntity(timeoutPing, bufferSize, ttl, dontFragment, timeoutTask, false);
                                    _ = new PingEntity(timeoutPing, bufferSize, ttl, dontFragment, timeoutTask, false);
                                    _ = new PingEntity(timeoutPing, bufferSize, ttl, dontFragment, timeoutTask, false);
                                });
                                Assert.DoesNotThrowAsync(async() => await Task.Run(() =>
                                {
                                    _ = new PingEntity(timeoutPing, bufferSize, ttl, dontFragment, timeoutTask, false);
                                    _ = new PingEntity(timeoutPing, bufferSize, ttl, dontFragment, timeoutTask, false);
                                    _ = new PingEntity(timeoutPing, bufferSize, ttl, dontFragment, timeoutTask, false);
                                }));
                            }
                        }
                    }
                }
            }

            Utils.MethodComplete();
        }
Esempio n. 2
0
        private static PingEntity Map(IPing c, WorldEntity world, PlayerEntity player)
        {
            var result = new PingEntity();

            Fill(result, world, player);
            return(result);
        }
Esempio n. 3
0
        public async Task HTTP_Ping_Return_BadOption_Status_When_ValidStatusCode_Is_Not_200()
        {
            ConfigEntity.Protocol        = Protocol.Http;
            ConfigEntity.ValidStatusCode = 201;

            var mockLogger = new Mock <ILogger>();

            mockLogger.Setup(x => x.LogAsync(It.IsAny <LogParams>())).Returns(Task.CompletedTask);

            var mockProtocolProviderManager = new Mock <IProtocolProviderManager>();

            mockProtocolProviderManager
            .Setup(x => x.GetProvider(It.IsAny <ConfigEntity>()))
            .Returns(new HttpPing());

            var pingEntity = new PingEntity
            {
                ConfigEntity     = ConfigEntity,
                ProtocolProvider = mockProtocolProviderManager.Object.GetProvider(It.IsAny <ConfigEntity>())
            };

            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <IProtocolProvider, HttpPing>()
                                  .BuildServiceProvider();

            var httpPing  = serviceProvider.GetService <IProtocolProvider>();
            var pingReply = await httpPing.PingAsync(DateTime.Now, pingEntity, mockLogger.Object);

            Assert.AreEqual(IPStatus.BadOption, pingReply.Status);
        }
Esempio n. 4
0
        public async Task Benchmark_Test_Yandex_ICMP_Ping_Return_Success_Status()
        {
            ConfigEntity.Host     = "ya.ru";
            ConfigEntity.Protocol = Protocol.Icmp;

            var mockLogger = new Mock <ILogger>();

            mockLogger.Setup(x => x.LogAsync(It.IsAny <LogParams>())).Returns(Task.CompletedTask);

            var mockProtocolProviderManager = new Mock <IProtocolProviderManager>();

            mockProtocolProviderManager
            .Setup(x => x.GetProvider(It.IsAny <ConfigEntity>()))
            .Returns(new IcmpPing());

            var pingEntity = new PingEntity
            {
                ConfigEntity     = ConfigEntity,
                ProtocolProvider = mockProtocolProviderManager.Object.GetProvider(It.IsAny <ConfigEntity>())
            };

            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <IProtocolProvider, IcmpPing>()
                                  .BuildServiceProvider();

            var icmpPing  = serviceProvider.GetService <IProtocolProvider>();
            var pingReply = await icmpPing.PingAsync(DateTime.Now, pingEntity, mockLogger.Object);

            Assert.AreEqual(IPStatus.Success, pingReply.Status);
        }
Esempio n. 5
0
        public void ConstructorSetupDefault_DoesNotThrow()
        {
            Utils.MethodStart();

            Assert.DoesNotThrow(() =>
            {
                _ = new PingEntity();
            });
            Assert.DoesNotThrowAsync(async() => await Task.Run(() =>
            {
                _ = new PingEntity();
            }));

            Utils.MethodComplete();
        }
Esempio n. 6
0
        public void OpenAsync_DoesNotThrow()
        {
            Utils.MethodStart();

            foreach (var timeoutPing in EnumValues.GetBytes())
            {
                foreach (var timeoutRepeat in EnumValues.GetBytes())
                {
                    foreach (var dontFragment in EnumValues.GetBool())
                    {
                        foreach (var bufferSize in EnumValues.GetBytes())
                        {
                            foreach (var ttl in EnumValues.GetBytes())
                            {
                                if ((timeoutPing > 127 && timeoutPing < 257) && (timeoutRepeat > 127 && timeoutRepeat < 257) &&
                                    (bufferSize >= 0 && bufferSize < 1465) && (ttl > 0 && ttl < 256))
                                {
                                    Assert.DoesNotThrow(() =>
                                    {
                                        var ping = new PingEntity(timeoutPing: timeoutPing, bufferSize: bufferSize, ttl: ttl, dontFragment: dontFragment,
                                                                  timeoutTask: timeoutRepeat, useRepeat: false);
                                        TestContext.WriteLine($@"{ping.Settings}");
                                        ping.Hosts.Add("google.com");
                                        ping.Hosts.Add("microsoft.com");
                                        ping.Hosts.Add("127.0.0.1");
                                        ping.Hosts.Add("yandex.com");
                                        ping.Hosts.Add("localhost");
                                        var task = Task.Run(async() =>
                                        {
                                            await ping.OpenAsync().ConfigureAwait(true);
                                        });
                                        task.Wait();
                                        var taskClose = Task.Run(async() =>
                                        {
                                            await ping.CloseAsync().ConfigureAwait(true);
                                        });
                                        taskClose.Wait();
                                        TestContext.WriteLine($@"{ping.Log}");
                                    });
                                }
                            }
                        }
                    }
                }
            }

            Utils.MethodComplete();
        }