public void ResolveSrvRecords_should_throw_when_service_is_null(bool async) { var subject = new DnsClientWrapper(); Exception exception; if (async) { exception = Record.Exception(() => subject.ResolveSrvRecords(null, CancellationToken.None)); } else { exception = Record.Exception(() => subject.ResolveSrvRecordsAsync(null, CancellationToken.None).GetAwaiter().GetResult()); } var e = exception.Should().BeOfType <ArgumentNullException>().Subject; e.ParamName.Should().Be("service"); }
public void ResolveSrvRecords_should_return_expected_result(string service, string[] expectedEndPoints, bool async) { var subject = new DnsClientWrapper(); List <SrvRecord> result; if (async) { result = subject.ResolveSrvRecords(service, CancellationToken.None); } else { result = subject.ResolveSrvRecordsAsync(service, CancellationToken.None).GetAwaiter().GetResult(); } var actualEndPoints = result.Select(s => EndPointHelper.ToString(s.EndPoint)).ToList(); actualEndPoints.Should().BeEquivalentTo(expectedEndPoints); }
public void ResolveSrvRecords_should_throw_when_cancellation_is_already_requested(bool async) { var subject = new DnsClientWrapper(); var service = "_mongodb._tcp.test5.test.build.10gen.cc"; var cts = new CancellationTokenSource(); cts.Cancel(); Exception exception; if (async) { exception = Record.Exception(() => subject.ResolveSrvRecords(service, cts.Token)); } else { exception = Record.Exception(() => subject.ResolveSrvRecordsAsync(service, cts.Token).GetAwaiter().GetResult()); } exception.Should().BeOfType <OperationCanceledException>(); }