예제 #1
0
        public async Task PingClientReturnsJsonWhenHelloAcmProviderIsSelected()
        {
            PingClient <HelloAcmPingDataProvider> client = new PingClient <HelloAcmPingDataProvider>();

            string data = await client.GetDataAsync("?host=8.8.8.8");

            try
            {
                _ = JsonConvert.DeserializeObject(data);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            data = await client.GetDataAsync("?host=google.com");

            try
            {
                _ = JsonConvert.DeserializeObject(data);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);

                return;
            }

            Assert.Pass();
        }
예제 #2
0
        public async Task WhenReady_ShouldReturnOk()
        {
            PingClient pingClient = TestApplication.GetPingClient();

            (bool ok, PingResponse? response) = await pingClient.Ready();

            ok.Should().BeTrue();
            response.Should().NotBeNull();
        }
예제 #3
0
        public async Task WhenAskedForLogs_ShouldReturnData()
        {
            PingClient pingClient = TestApplication.GetPingClient();

            PingLogs?logs = await pingClient.GetLogs();

            logs.Should().NotBeNull();
            logs !.Count.Should().BeGreaterThan(0);
            logs.Messages.Should().NotBeNull();
            logs.Messages !.Count.Should().BeGreaterThan(0);
        }
예제 #4
0
        public async Task WhenPinged_ShouldReturnOk()
        {
            TestWebsiteHost host = TestApplication.GetHost();

            PingClient pingClient = host.GetPingClient();

            (bool ok, PingResponse? response) = await pingClient.Ping();

            ok.Should().BeTrue();
            response.Should().NotBeNull();
        }
예제 #5
0
        public async Task Setup()
        {
            // create server
            server = new Server {
                Ports    = { new ServerPort("localhost", 10042, ServerCredentials.Insecure) },
                Services = { ServerServiceDefinition.CreateBuilder().AddMethod(PingMethod, ServerMethod).Build() },
            };
            server.Start();

            // create client
            channel = new Channel("localhost", 10042, ChannelCredentials.Insecure);
            await channel.ConnectAsync();

            client = new PingClient(new DefaultCallInvoker(channel));
        }
예제 #6
0
        public async Task <PingAnalysisResult> Get(string address)
        {
            this.ValidateAddressInput(address);


            PingClient <HelloAcmPingDataProvider> client = new PingClient <HelloAcmPingDataProvider>();
            string data = await client.GetDataAsync($"?host={address}");

            bool isSuccess = !string.IsNullOrWhiteSpace(data);

            return(new PingAnalysisResult
            {
                IsSuccessful = isSuccess,
                ResultText = data
            });
        }
예제 #7
0
        public void Setup()
        {
            // create client, the channel will actually never connect because call logic will be short-circuited
            channel = new Channel("localhost", 10042, ChannelCredentials.Insecure);
            client  = new PingClient(new DefaultCallInvoker(channel));

            var native = NativeMethods.Get();

            // replace the implementation of a native method with a fake
            NativeMethods.Delegates.grpcsharp_call_start_unary_delegate fakeCallStartUnary = (CallSafeHandle call, BatchContextSafeHandle ctx, byte[] sendBuffer, UIntPtr sendBufferLen, WriteFlags writeFlags, MetadataArraySafeHandle metadataArray, CallFlags metadataFlags) => {
                return(native.grpcsharp_test_call_start_unary_echo(call, ctx, sendBuffer, sendBufferLen, writeFlags, metadataArray, metadataFlags));
            };
            native.GetType().GetField(nameof(native.grpcsharp_call_start_unary)).SetValue(native, fakeCallStartUnary);

            NativeMethods.Delegates.grpcsharp_completion_queue_pluck_delegate fakeCqPluck = (CompletionQueueSafeHandle cq, IntPtr tag) => {
                return(new CompletionQueueEvent {
                    type = CompletionQueueEvent.CompletionType.OpComplete,
                    success = 1,
                    tag = tag
                });
            };
            native.GetType().GetField(nameof(native.grpcsharp_completion_queue_pluck)).SetValue(native, fakeCqPluck);
        }
 // Link processors to each other in a chain.
 public PingMeshExtension(ITelemetryProcessor next)
 {
     m_pingClient = new PingClient();
     this.Next    = next;
 }