public async Task ProcessAsync_AnyFailReturnsFailureResult() { GoDaddyDomain domainOne = new GoDaddyDomain(); GoDaddyDomain domainTwo = new GoDaddyDomain(); IGoDaddyDomainProcessor domainProcessor = A.Fake <IGoDaddyDomainProcessor>(); A.CallTo(() => domainProcessor.ProcessAsync(domainOne, A <ExternalAddress> .Ignored, A <GoDaddyAuthenticationDetails> .Ignored, A <CancellationToken> .Ignored)).Returns(Result.Ok()); A.CallTo(() => domainProcessor.ProcessAsync(domainTwo, A <ExternalAddress> .Ignored, A <GoDaddyAuthenticationDetails> .Ignored, A <CancellationToken> .Ignored)).Returns(Result.Fail("This failed")); GoDaddyAccountProcessor processor = new GoDaddyAccountProcessor(domainProcessor); GoDaddyAccount account = new GoDaddyAccount() { Domains = new List <GoDaddyDomain>() { domainOne, domainTwo } }; ExternalAddress externalAddress = new ExternalAddress() { IPv4Address = IPAddress.Parse("100.100.100.100") }; Result result = await processor.ProcessAsync(account, externalAddress, new CancellationToken()); Assert.True(result.IsFailed); }
public void Validate_MissingRecords_ReturnIsNotValid() { GoDaddyDomain domain = new GoDaddyDomain() { Name = "GoDaddy Domain", }; IValidator <GoDaddyDomain> validator = new GoDaddyDomainValidator(); ValidationResult result = validator.Validate(domain); Assert.False(result.IsValid); }
public void Validate_MissingName_ReturnIsNotValid() { GoDaddyDomain domain = new GoDaddyDomain() { Records = CreateValidDNSRecordCollection() }; IValidator <GoDaddyDomain> validator = new GoDaddyDomainValidator(); ValidationResult result = validator.Validate(domain); Assert.False(result.IsValid); }
public void Validate_ValidDomain_ReturnIsValid() { GoDaddyDomain domain = new GoDaddyDomain() { Name = "GoDaddy Domain", Records = CreateValidDNSRecordCollection() }; IValidator <GoDaddyDomain> validator = new GoDaddyDomainValidator(); ValidationResult result = validator.Validate(domain); Assert.True(result.IsValid); }
public async Task GetDomainTest() { using (var client = new GoDaddyHttpClient()) { var expected = new GoDaddyDomain() { Domain = _domain }; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "sso-key", "UzQxLikm_46KxDFnbjN7cQjmw6wocia:46L26ydpkwMaKZV6uVdDWe"); client.BaseAddress = new Uri("https://api.ote-godaddy.com/v1/"); client.DomainApiCall = _domainApiCall; var goDaddyApi = new ApiCaller <GoDaddyDomain, GoDaddyDnsRecord>(client, _log); var domain = await goDaddyApi.GetDomain(); Assert.AreEqual(expected.Domain, domain.Domain); } }
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 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); }