public async Task Returns_Success_With_DNS_Records_When_Successfully_Retrieved() { IGoDaddyClient fakeClient = A.Fake <IGoDaddyClient>(); List <GoDaddyGetDNSRecordResponse> records = new List <GoDaddyGetDNSRecordResponse>() { CreateValidGoDaddyGetDNSRecordResponse(1), CreateValidGoDaddyGetDNSRecordResponse(2), CreateValidGoDaddyGetDNSRecordResponse(3) }; GoDaddyGetDNSRecordsResponse clientResponse = new GoDaddyGetDNSRecordsResponse(records); A.CallTo(() => fakeClient.GetDNSRecordsAsync(A <GoDaddyGetDNSRecordsRequest> .Ignored, A <CancellationToken> .Ignored)).Returns(Result.Ok(clientResponse)); GoDaddyDNSRecordReader reader = new GoDaddyDNSRecordReader(fakeClient, _mapper); GoDaddyAuthenticationDetails authicationDetails = new GoDaddyAuthenticationDetails("apiKey", "apiSecret"); Result <DNSRecordCollection> result = await reader.ReadAsync(string.Empty, authicationDetails, CancellationToken.None); DNSRecord firstRecord = result.Value.First(); Assert.True(result.IsSuccess); Assert.Equal(3, result.Value.Count); Assert.Equal("Data-1", firstRecord.Data); Assert.Equal("Name-1", firstRecord.Name); Assert.Equal(1, firstRecord.Port); }
public async Task <Result> ProcessAsync(GoDaddyAccount account, ExternalAddress externalAddress, CancellationToken cancellation) { Result result = Result.Ok(); GoDaddyAuthenticationDetails authenticationDetails = new GoDaddyAuthenticationDetails(account.ApiKey, account.ApiSecret); foreach (GoDaddyDomain domain in account.Domains) { result = result.Merge(await _domainProcessor.ProcessAsync(domain, externalAddress, authenticationDetails, cancellation)); } return(result); }
public async Task Returns_Failure_When_Getting_Record_Fails() { IGoDaddyClient fakeClient = A.Fake <IGoDaddyClient>(); A.CallTo(() => fakeClient.GetDNSRecordsAsync(A <GoDaddyGetDNSRecordsRequest> .Ignored, A <CancellationToken> .Ignored)).Returns(Result.Fail("failed")); GoDaddyDNSRecordReader reader = new GoDaddyDNSRecordReader(fakeClient, _mapper); GoDaddyAuthenticationDetails authicationDetails = new GoDaddyAuthenticationDetails("apiKey", "apiSecret"); Result <DNSRecordCollection> result = await reader.ReadAsync(string.Empty, authicationDetails, CancellationToken.None); Assert.True(result.IsFailed); }
public async Task Returns_Success_When_All_Records_Update() { IGoDaddyClient client = A.Fake <IGoDaddyClient>(); A.CallTo(() => client.UpdateDNSRecordAsync(A <GoDaddyUpdateDNSRecordsRequest> .Ignored, A <CancellationToken> .Ignored)).Returns(Result.Ok()); GoDaddyDNSRecordUpdater updater = new GoDaddyDNSRecordUpdater(client, _mapper); DNSRecordCollection records = new DNSRecordCollection(CreateValidDNSRecord(1), CreateValidDNSRecord(2)); GoDaddyAuthenticationDetails authicationDetails = new GoDaddyAuthenticationDetails("apiKey", "apiSecret"); Result result = await updater.UpdateAsync("aDomain.com", records, authicationDetails, CancellationToken.None); Assert.True(result.IsSuccess); }
public async Task No_Records_Are_Successfully_Created_If_Client_Fails() { IGoDaddyClient client = A.Fake <IGoDaddyClient>(); A.CallTo(() => client.UpdateDNSRecordAsync(A <GoDaddyUpdateDNSRecordsRequest> .Ignored, A <CancellationToken> .Ignored)).Returns(Result.Fail("Error")); GoDaddyDNSRecordUpdater updater = new GoDaddyDNSRecordUpdater(client, _mapper); DNSRecordCollection records = new DNSRecordCollection(CreateValidDNSRecord(1), CreateValidDNSRecord(2)); GoDaddyAuthenticationDetails authicationDetails = new GoDaddyAuthenticationDetails("apiKey", "apiSecret"); Result result = await updater.UpdateAsync("aDomain.com", records, authicationDetails, CancellationToken.None); Assert.True(result.IsFailed); Assert.Equal(2, result.Errors.Count); }
public async Task No_Records_Are_Successfully_Created_Returns_Failure() { IGoDaddyClient fakeClient = A.Fake <IGoDaddyClient>(); A.CallTo(() => fakeClient.CreateDNSRecordsAsync(A <GoDaddyCreateDNSRecordsRequest> .Ignored, A <CancellationToken> .Ignored)).Returns(Result.Fail("oops")); GoDaddyDNSRecordCreator creator = new GoDaddyDNSRecordCreator(fakeClient, _mapper); DNSRecordCollection dnsRecords = new DNSRecordCollection( new DNSRecord { Type = DNSRecordType.A }, new DNSRecord { Type = DNSRecordType.A }); GoDaddyAuthenticationDetails authicationDetails = new GoDaddyAuthenticationDetails(string.Empty, string.Empty); Result result = await creator.CreateAsync(string.Empty, dnsRecords, authicationDetails, CancellationToken.None); Assert.True(result.IsFailed); }
public async Task Records_Are_Created_And_Successful_Result_Returned() { IGoDaddyClient fakeClient = A.Fake <IGoDaddyClient>(); A.CallTo(() => fakeClient.CreateDNSRecordsAsync(A <GoDaddyCreateDNSRecordsRequest> .Ignored, A <CancellationToken> .Ignored)).Returns(Result.Ok()); GoDaddyDNSRecordCreator creator = new GoDaddyDNSRecordCreator(fakeClient, _mapper); DNSRecordCollection dnsRecords = new DNSRecordCollection( new DNSRecord { Type = DNSRecordType.A }, new DNSRecord { Type = DNSRecordType.A }); GoDaddyAuthenticationDetails authicationDetails = new GoDaddyAuthenticationDetails(string.Empty, string.Empty); Result result = await creator.CreateAsync(string.Empty, dnsRecords, authicationDetails, CancellationToken.None); Assert.True(result.IsSuccess); A.CallTo(() => fakeClient.CreateDNSRecordsAsync(A <GoDaddyCreateDNSRecordsRequest> .Ignored, A <CancellationToken> .Ignored)).MustHaveHappenedOnceExactly(); }
public async Task ProcessAsync_ReadFails_ReturnsFailureResult() { IGoDaddyDNSRecordCreator dnsCreator = A.Fake <IGoDaddyDNSRecordCreator>(); A.CallTo(() => dnsCreator.CreateAsync(A <string> .Ignored, A <DNSRecordCollection> .Ignored, A <GoDaddyAuthenticationDetails> .Ignored, A <CancellationToken> .Ignored)) .Returns(Result.Ok()); IDNSRecordCollectionMutator mutator = A.Fake <IDNSRecordCollectionMutator>(); A.CallTo(() => mutator.Mutate(A <DNSRecordCollection> .Ignored, A <IDNSRecordCollectionMutation> .Ignored)) .Returns(DNSRecordCollection.Empty()); IGoDaddyDNSRecordReader dnsReader = A.Fake <IGoDaddyDNSRecordReader>(); A.CallTo(() => dnsReader.ReadAsync(A <string> .Ignored, A <GoDaddyAuthenticationDetails> .Ignored, A <CancellationToken> .Ignored)) .Returns(Result.Fail("Reader Failure")); IGoDaddyDNSRecordUpdater dnsUpdater = A.Fake <IGoDaddyDNSRecordUpdater>(); A.CallTo(() => dnsUpdater.UpdateAsync(A <string> .Ignored, A <DNSRecordCollection> .Ignored, A <GoDaddyAuthenticationDetails> .Ignored, A <CancellationToken> .Ignored)) .Returns(Result.Ok()); IGoDaddyDomainProcessor domainProcessor = new GoDaddyDomainProcessor(dnsCreator, mutator, dnsReader, dnsUpdater); GoDaddyDomain domain = new GoDaddyDomain() { Name = "GoDaddy Domain" }; ExternalAddress externalAddress = A.Fake <ExternalAddress>(); GoDaddyAuthenticationDetails authenticationDetails = A.Fake <GoDaddyAuthenticationDetails>(); Result result = await domainProcessor.ProcessAsync(domain, externalAddress, authenticationDetails, new CancellationToken()); Assert.False(result.IsSuccess); Assert.True(result.IsFailed); }
public async Task <Result <DNSRecordCollection> > ReadAsync(string domainName, GoDaddyAuthenticationDetails authentication, CancellationToken cancellation) { GoDaddyGetDNSRecordsRequest request = new GoDaddyGetDNSRecordsRequest(authentication.ApiKey, authentication.ApiSecret, DNSRecordType.A, domainName); Result <GoDaddyGetDNSRecordsResponse> result = await _client.GetDNSRecordsAsync(request, cancellation); if (result.IsSuccess) { IList <DNSRecord> records = _mapper.Map <IList <DNSRecord> >(result.Value.Records); return(Result.Ok(new DNSRecordCollection(records)).Merge(result)); } return(result.ToResult()); }
public async Task <Result> ProcessAsync(GoDaddyDomain domain, ExternalAddress externalAddress, GoDaddyAuthenticationDetails authentication, CancellationToken cancellation) { Result <DNSRecordCollection> activeDnsRecordsResult = await _dnsRecordReader.ReadAsync(domain.Name, authentication, cancellation); if (activeDnsRecordsResult.IsFailed) { return(activeDnsRecordsResult); } IDNSRecordCollectionMutation[] mutations = GetMutations(externalAddress); DNSRecordCollection configurationRecords = new DNSRecordCollection(domain.Records); DNSRecordCollection hydratedDnsRecords = _dnsRecordMutator.Mutate(configurationRecords, mutations); DNSRecordCollection newRecords = activeDnsRecordsResult.Value.WhereNew(hydratedDnsRecords); DNSRecordCollection updatedRecords = activeDnsRecordsResult.Value.WhereUpdated(hydratedDnsRecords); Result create = await _dnsRecordCreator.CreateAsync(domain.Name, newRecords, authentication, cancellation); Result update = await _dnsRecordUpdater.UpdateAsync(domain.Name, updatedRecords, authentication, cancellation); return(activeDnsRecordsResult.Merge(create, update)); }
public async Task <Result> UpdateAsync(string domainName, DNSRecordCollection records, GoDaddyAuthenticationDetails authentication, CancellationToken cancellation) { Result result = Result.Ok(); foreach (DNSRecord record in records) { GoDaddyUpdateDNSRecord mappedRecord = _mapper.Map <GoDaddyUpdateDNSRecord>(record); GoDaddyUpdateDNSRecordsRequest request = new GoDaddyUpdateDNSRecordsRequest(authentication.ApiKey, authentication.ApiSecret, domainName, record.Type, record.Name, mappedRecord); Result updateResult = await _client.UpdateDNSRecordAsync(request, cancellation); result = result.Merge(updateResult); } return(result); }
public async Task <Result> CreateAsync(string domainName, DNSRecordCollection records, GoDaddyAuthenticationDetails authentication, CancellationToken cancellation) { if (records.Any()) { IEnumerable <GoDaddyCreateDNSRecordRequest> recordRequests = _mapper.Map <IEnumerable <GoDaddyCreateDNSRecordRequest> >(records); GoDaddyCreateDNSRecordsRequest request = new GoDaddyCreateDNSRecordsRequest(authentication.ApiKey, authentication.ApiSecret, recordRequests, domainName); return(await _client.CreateDNSRecordsAsync(request, cancellation)); } return(Result.Ok()); }