void Basic()
        {
            var time = TrivialNtpClient.RetrieveTime("0.medo64.pool.ntp.org");
            var diff = DateTime.UtcNow - time;

            Assert.True(Math.Abs(diff.TotalSeconds) < 1);
        }
Beispiel #2
0
 async public void NonExistingHostAsync()
 {
     using var client = new TrivialNtpClient("nonexisting.medo64.com");
     await Assert.ThrowsAsync <InvalidOperationException>(async() => {
         var time = await client.RetrieveTimeAsync();
     });
 }
Beispiel #3
0
 public void NonExistingHost()
 {
     using var client = new TrivialNtpClient("nonexisting.medo64.com");
     Assert.Throws <InvalidOperationException>(() => {
         var time = client.RetrieveTime();
     });
 }
Beispiel #4
0
        public void Basic()
        {
            var time = TrivialNtpClient.RetrieveTime("0.medo64.pool.ntp.org");
            var diff = DateTime.UtcNow - time;

            Assert.InRange <double>(diff.TotalSeconds, -2, 2);
        }
        void InvalidPort(object data)
        {
            int port = (int)data;

            Assert.Throws <ArgumentOutOfRangeException>(() => {
                using (var client = new TrivialNtpClient("0.medo64.pool.ntp.org", port)) { }
            });
        }
        void InvalidHostName(object data)
        {
            var hostName = data as string;

            Assert.Throws <ArgumentOutOfRangeException>(() => {
                using (var client = new TrivialNtpClient(hostName)) { }
            });
        }
        async public void Async()
        {
            var time = await TrivialNtpClient.RetrieveTimeAsync("0.medo64.pool.ntp.org");

            var diff = DateTime.UtcNow - time;

            Assert.True(Math.Abs(diff.TotalSeconds) < 5);
        }
Beispiel #8
0
        public void InvalidPort(object data)
        {
            var port = (int)data;

            Assert.Throws <ArgumentOutOfRangeException>(() => {
                var _ = new TrivialNtpClient("0.medo64.pool.ntp.org", port);
            });
        }
Beispiel #9
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();
     });
 }
Beispiel #10
0
 public void Timeout()
 {
     using var client = new TrivialNtpClient("0.medo64.pool.ntp.org")
           {
               Timeout = 1
           };
     Assert.Throws <InvalidOperationException>(() => {
         var time = client.RetrieveTime();
     });
 }