示例#1
0
 async public void NonExistingHostAsync()
 {
     using var client = new TrivialNtpClient("nonexisting.medo64.com");
     await Assert.ThrowsAsync <InvalidOperationException>(async() => {
         var time = await client.RetrieveTimeAsync();
     });
 }
示例#2
0
        async void Async()
        {
            var time = await TrivialNtpClient.RetrieveTimeAsync("0.medo64.pool.ntp.org");

            var diff = DateTime.UtcNow - time;

            Assert.True(Math.Abs(diff.TotalSeconds) < 1);
        }
示例#3
0
        async public void Async()
        {
            var time = await TrivialNtpClient.RetrieveTimeAsync("0.medo64.pool.ntp.org");

            var diff = DateTime.UtcNow - time;

            Assert.InRange <double>(diff.TotalSeconds, -2, 2);
        }
示例#4
0
 async public void TimeoutAsync()
 {
     using var client = new TrivialNtpClient("0.medo64.pool.ntp.org")
           {
               Timeout = 1
           };
     await Assert.ThrowsAsync <InvalidOperationException>(async() => {
         var time = await client.RetrieveTimeAsync();
     });
 }