public async Task MxTermExpanded() { string host1 = "host1"; string host2 = "host2"; string ip1 = "192.168.1.1"; string ip2 = "192.168.1.2"; A.CallTo(() => _dnsClient.GetMxRecords(A<string>._)) .Returns(Task.FromResult(new DnsResult<List<string>> (new List<string> { host1, host2 }, 200))); A.CallTo(() => _dnsClient.GetARecords(A<string>._)) .ReturnsNextFromSequence( Task.FromResult(new DnsResult<List<string>>(new List<string> { ip1, ip2 }, 200)), Task.FromResult(new DnsResult<List<string>>(new List<string> { ip1 }, 200))); Mx mx = new Mx("", Qualifier.Pass, new DomainSpec(""), new DualCidrBlock(new Ip4CidrBlock(32), new Ip6CidrBlock(128))); SpfRecords spfRecords = await _spfMxTermExpander.Process("", mx); Assert.That(spfRecords, Is.Null); Assert.That(mx.MxHosts.Count, Is.EqualTo(2)); Assert.That(mx.MxHosts[0].Host, Is.EqualTo(host1)); Assert.That(mx.MxHosts[1].Host, Is.EqualTo(host2)); Assert.That(mx.MxHosts[0].Ip4S.Count, Is.EqualTo(2)); Assert.That(mx.MxHosts[1].Ip4S.Count, Is.EqualTo(1)); Assert.That(mx.MxHosts[0].Ip4S[0], Is.EqualTo(ip1)); Assert.That(mx.MxHosts[0].Ip4S[1], Is.EqualTo(ip2)); Assert.That(mx.MxHosts[1].Ip4S[0], Is.EqualTo(ip1)); Assert.That(mx.AllErrors, Is.Empty); }
public async Task <SpfRecords> Process(string domain, Term term) { A a = term as A; string aDomain = string.IsNullOrEmpty(a.DomainSpec.Domain) ? domain : a.DomainSpec.Domain; DnsResult <List <string> > ips = await _dnsClient.GetARecords(aDomain); if (ips.IsErrored) { string message = string.Format(SpfExpansionResource.FailedARecordQueryErrorMessage, aDomain, ips.Error); string markdown = string.Format(SpfExpansionMarkdownResource.FailedARecordQueryErrorMessage, aDomain, ips.Error); a.AddError(new Error(Id, ErrorType.Error, message, markdown)); } else { a.Ip4s = ips.Value; } return(null); }