public async Task <Result <DigitalOceanGetDomainRecordsResponse> > GetDNSRecordsAsync(DigitalOceanDomain domain, string token, CancellationToken cancellation) { string path = string.Format(_getDNSRecordsFormat, domain.Name); IFlurlRequest httpRequest = BuildRequest(token, path); IFlurlResponse response = await httpRequest.GetAsync(cancellation); HttpResponseMessage message = response.ResponseMessage; if (message.IsSuccessStatusCode) { string content = await message.Content.ReadAsStringAsync(); DigitalOceanGetDomainRecordsResponse records = JsonConvert.DeserializeObject <DigitalOceanGetDomainRecordsResponse>(content); return(Result.Ok(records).WithSuccess(string.Format(_getDNSRecordsSuccessMessageTemplate, records.DomainRecords.Count(), domain.Name))); } return(Result.Fail(string.Format(_getDNSRecordsFailureMessageTemplate, domain.Name))); }
public async Task Record_Is_Successfully_Retrieved() { string ipAddress = "100.100.100.100"; string name = "test"; int TTL = 1800; DNSRecordType type = DNSRecordType.A; DigitalOceanDomain domain = new DigitalOceanDomain(); DigitalOceanGetDomainRecordsResponse clientResponse = new DigitalOceanGetDomainRecordsResponse { DomainRecords = new List <DigitalOceanGetDomainRecordResponse> { new DigitalOceanGetDomainRecordResponse { Data = ipAddress, Name = name, Ttl = TTL, Type = type } } }; Result <DigitalOceanGetDomainRecordsResponse> clientResponeResult = Result.Ok(clientResponse); IDigitalOceanClient client = A.Fake <IDigitalOceanClient>(); IDigitalOceanDNSRecordReader reader = new DigitalOceanDNSRecordReader(client, _mappingHelper.Mapper); A.CallTo(() => client.GetDNSRecordsAsync(A <DigitalOceanDomain> .Ignored, A <string> .Ignored, A <CancellationToken> .Ignored)).Returns(clientResponeResult); Result <DNSRecordCollection> result = await reader.ReadAsync(domain, string.Empty, CancellationToken.None); Assert.True(result.IsSuccess); DNSRecordCollection dnsRecords = result.Value; Assert.True(dnsRecords.Count == 1); DNSRecord dnsRecord = result.Value.First(); Assert.Equal(dnsRecord.Data, ipAddress); Assert.Equal(dnsRecord.Name, name); Assert.Equal(dnsRecord.TTL, TTL); Assert.Equal(dnsRecord.Type, type); }