public void Properties_Default() { using (var client = new Ntp.NtpClient()) { Assert.That(client.Host.HostName, Is.EqualTo("www268.ziyu.net")); Assert.That(client.Host.AddressList.Length, Is.AtLeast(1)); Assert.That(client.Port, Is.EqualTo(123)); Assert.That(client.Timeout, Is.EqualTo(TimeSpan.FromSeconds(5))); } }
public void Timeout_Throws() => Assert.That( () => { using (var client = new Ntp.NtpClient()) { client.Timeout = TimeSpan.FromMilliseconds(1); client.GetAsync().Wait(); } }, Throws.TypeOf <AggregateException>() .And .InnerException .TypeOf <TimeoutException>() );
public async Task GetAsync(string src, uint version, uint poll, Cube.Net.Ntp.Stratum stratum) { using (var client = new Ntp.NtpClient(src)) { var pkt = await client.GetAsync(); Assert.That(pkt.IsValid, Is.True); Assert.That(pkt.LeapIndicator, Is.EqualTo(Cube.Net.Ntp.LeapIndicator.NoWarning)); Assert.That(pkt.Version, Is.EqualTo(version)); Assert.That(pkt.Mode, Is.EqualTo(Cube.Net.Ntp.Mode.Server)); Assert.That(pkt.Stratum, Is.EqualTo(stratum)); Assert.That(pkt.PollInterval, Is.EqualTo(poll)); Assert.That(pkt.Precision, Is.GreaterThan(0.0).And.LessThan(1.0)); Assert.That(pkt.RootDelay, Is.GreaterThanOrEqualTo(0.0)); Assert.That(pkt.RootDispersion, Is.GreaterThanOrEqualTo(0.0)); Assert.That(pkt.ReferenceID, Is.Not.Null.And.Not.Empty); Assert.That(pkt.ReferenceTimestamp, Is.Not.Null); Assert.That(pkt.KeyID, Is.Empty); Assert.That(pkt.MessageDigest, Is.Empty); Assert.That(pkt.NetworkDelay.TotalSeconds, Is.GreaterThan(0.0).And.LessThan(1.0)); Assert.That(pkt.LocalClockOffset.TotalSeconds, Is.EqualTo(0).Within(60)); } }