Beispiel #1
0
        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);
        }