コード例 #1
0
        public async Task ReturnsFailureWhenUpdateFails()
        {
            DNSRecordCollection dnsRecordCollection = DNSRecordCollection.Empty();
            DigitalOceanDomain  domain          = new DigitalOceanDomain();
            ExternalAddress     externalAddress = new ExternalAddress();

            IDNSRecordCollectionMutator dnsRecordMutator = A.Fake <IDNSRecordCollectionMutator>();

            A.CallTo(() => dnsRecordMutator.Mutate(A <DNSRecordCollection> .Ignored, A <IDNSRecordCollectionMutation> .Ignored)).Returns(dnsRecordCollection);

            IDigitalOceanDNSRecordCreator dnsRecordCreator = A.Fake <IDigitalOceanDNSRecordCreator>();

            A.CallTo(() => dnsRecordCreator.CreateAsync(A <string> .Ignored, A <DNSRecordCollection> .Ignored, A <string> .Ignored, A <CancellationToken> .Ignored)).Returns(Result.Ok());

            IDigitalOceanDNSRecordReader dnsRecordReader = A.Fake <IDigitalOceanDNSRecordReader>();

            A.CallTo(() => dnsRecordReader.ReadAsync(A <DigitalOceanDomain> .Ignored, A <string> .Ignored, A <CancellationToken> .Ignored)).Returns(Result.Ok(dnsRecordCollection));

            IDigitalOceanDNSRecordUpdater dnsRecordUpdater = A.Fake <IDigitalOceanDNSRecordUpdater>();

            A.CallTo(() => dnsRecordUpdater.UpdateAsync(A <string> .Ignored, A <DNSRecordCollection> .Ignored, A <string> .Ignored, A <CancellationToken> .Ignored)).Returns(Result.Fail("Error."));

            IDigitalOceanDomainProcessor processor = new DigitalOceanDomainProcessor(dnsRecordMutator, dnsRecordCreator, dnsRecordReader, dnsRecordUpdater);
            Result result = await processor.ProcessAsync(domain, externalAddress, string.Empty, new CancellationToken());

            Assert.True(result.IsFailed);
        }
コード例 #2
0
        public async Task <Result> ProcessAsync(DigitalOceanDomain domain, ExternalAddress externalAddress, string token, CancellationToken cancellation)
        {
            Result <DNSRecordCollection> activeDnsRecordsResult = await _dnsRecordReader.ReadAsync(domain, token, cancellation);

            if (activeDnsRecordsResult.IsFailed)
            {
                return(activeDnsRecordsResult);
            }

            IDNSRecordCollectionMutation[] mutations = GetMutations(externalAddress, activeDnsRecordsResult.Value);

            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, token, cancellation);

            Result update = await _dnsRecordUpdater.UpdateAsync(domain.Name, updatedRecords, token, cancellation);

            return(activeDnsRecordsResult.Merge(create, update));
        }