Ping() public method

Check that the server is alive.
public Ping ( ) : IAsyncResult
return IAsyncResult
示例#1
0
        public void PingCallTest()
        {
            // ARRANGE
            using (AutoResetEvent waitEvent = new AutoResetEvent(false))
            {
                ResultEventArgs<PingResult> result = null;
                IServerService etsyServer = new ServerService(new EtsyContext(NetsyData.EtsyApiKey));
                etsyServer.PingCompleted += (s, e) =>
                {
                    result = e;
                    waitEvent.Set();
                };

                // ACT
                etsyServer.Ping();
                bool signalled = waitEvent.WaitOne(Constants.WaitTimeout);

                // ASSERT
                // check that the event was fired, did not time out
                Assert.IsTrue(signalled, "Not signalled");

                // check the data
                Assert.IsNotNull(result);
                TestHelpers.CheckResultSuccess(result);

                Assert.AreEqual(1, result.ResultValue.Count);
                Assert.AreEqual(1, result.ResultValue.Results.Length);
                Assert.AreEqual("pong", result.ResultValue.Results[0]);
                Assert.IsNull(result.ResultValue.Params);
            }
        }
示例#2
0
        public void PingTest()
        {
            EtsyContext etsyContext = new EtsyContext(Constants.DummyEtsyApiKey);
            MockFixedDataRequestGenerator requestGenerator = new MockFixedDataRequestGenerator(PingRawResults);
            DataRetriever dataRetriever = new DataRetriever(new NullDataCache(), requestGenerator);
            IServerService etsyListingsService = new ServerService(etsyContext, dataRetriever);

            using (AutoResetEvent waitEvent = new AutoResetEvent(false))
            {
                ResultEventArgs<PingResult> result = null;
                etsyListingsService.PingCompleted += (s, e) =>
                {
                    result = e;
                    waitEvent.Set();
                };

                // ACT
                etsyListingsService.Ping();
                bool signalled = waitEvent.WaitOne(Constants.WaitTimeout);

                // ASSERT

                // check that the event was fired, did not time out
                Assert.IsTrue(signalled, "Not signalled");

                TestHelpers.CheckResultSuccess(result);
            }
        }
示例#3
0
        public void PingApiKeyInvalidTest()
        {
            // ARRANGE
            using (AutoResetEvent waitEvent = new AutoResetEvent(false))
            {
                ResultEventArgs<PingResult> result = null;
                IServerService etsyServer = new ServerService(new EtsyContext("InvalidKey"));
                etsyServer.PingCompleted += (s, e) =>
                {
                    result = e;
                    waitEvent.Set();
                };

                // ACT
                etsyServer.Ping();
                bool signalled = waitEvent.WaitOne(Constants.WaitTimeout);

                // ASSERT
                // check that the event was fired, did not time out
                Assert.IsTrue(signalled, "Not signalled");

                // check the data - should fail
                Assert.IsNotNull(result);
                Assert.IsNotNull(result.ResultStatus);
                Assert.IsFalse(result.ResultStatus.Success);
                Assert.AreEqual(WebExceptionStatus.ProtocolError, result.ResultStatus.WebStatus);
            }
        }
示例#4
0
        public void PingApiKeyMissingTest()
        {
            // ARRANGE
            ResultEventArgs<PingResult> result = null;
            IServerService stsyServer = new ServerService(new EtsyContext(string.Empty));
            stsyServer.PingCompleted += (s, e) => result = e;

            // ACT
            stsyServer.Ping();

            // check the data
            TestHelpers.CheckResultFailure(result);
        }