Exemple #1
0
        public async Task UpdateDns_SingleDomainCorrectNewIp_ShouldUpdateTheDnsWithCorrectIp()
        {
            // Arrange
            string currentExternalIp = "1.2.3.4";
            string currentRecordedIp = "5.6.7.8";
            string subdomain         = "test.example.com";
            string zoneId            = "ABCD123456";
            var    domain            = new HostedDomainInfo()
            {
                ZoneId     = zoneId,
                DomainName = subdomain
            };

            var mockAmazonClient = new Mock <IAmazonRoute53>();

            mockAmazonClient.Setup(m => m.ListResourceRecordSetsAsync(It.IsAny <ListResourceRecordSetsRequest>(), CancellationToken.None))
            .ReturnsAsync(new ListResourceRecordSetsResponse()
            {
                ResourceRecordSets = new List <ResourceRecordSet>()
                {
                    new ResourceRecordSet()
                    {
                        Name            = subdomain,
                        ResourceRecords = new List <ResourceRecord>()
                        {
                            new ResourceRecord()
                            {
                                Value = currentRecordedIp
                            }
                        }
                    }
                }
            });

            var dnsUpdater = new DnsUpdater(mockAmazonClient.Object);

            // Act
            await dnsUpdater.UpdateSingleAsync(currentExternalIp, domain);

            // Assert
            mockAmazonClient.Verify(m => m.ChangeResourceRecordSetsAsync(It.Is <ChangeResourceRecordSetsRequest>(c => c.ChangeBatch.Changes.Count == 1), CancellationToken.None), Times.Once);
            mockAmazonClient.Verify(m => m.ChangeResourceRecordSetsAsync(It.Is <ChangeResourceRecordSetsRequest>(c => c.ChangeBatch.Changes.First().ResourceRecordSet.ResourceRecords.First().Value == currentExternalIp), CancellationToken.None), Times.Once);
        }
Exemple #2
0
        public async Task UpdateDns_SingleDomainCorrectExistingIp_ShowuldNotCallAwsClient()
        {
            // Arrange
            string currentExternalIp = "1.2.3.4";
            string currentRecordedIp = "1.2.3.4";
            string subdomain         = "test.example.com";
            string zoneId            = "ABCD123456";
            var    domain            = new HostedDomainInfo()
            {
                ZoneId     = zoneId,
                DomainName = subdomain
            };

            var mockAmazonClient = new Mock <IAmazonRoute53>();

            mockAmazonClient.Setup(m => m.ListResourceRecordSetsAsync(It.IsAny <ListResourceRecordSetsRequest>(), CancellationToken.None))
            .ReturnsAsync(new ListResourceRecordSetsResponse()
            {
                ResourceRecordSets = new List <ResourceRecordSet>()
                {
                    new ResourceRecordSet()
                    {
                        Name            = subdomain,
                        ResourceRecords = new List <ResourceRecord>()
                        {
                            new ResourceRecord()
                            {
                                Value = currentRecordedIp
                            }
                        }
                    }
                }
            });

            var dnsUpdater = new DnsUpdater(mockAmazonClient.Object);

            // Act
            await dnsUpdater.UpdateSingleAsync(currentExternalIp, domain);

            // Assert
            mockAmazonClient.Verify(m => m.ChangeResourceRecordSetsAsync(It.IsAny <ChangeResourceRecordSetsRequest>(), CancellationToken.None), Times.Never);
        }