예제 #1
0
        public async Task SubscribeTopic()
        {
            const string emailAddress          = "*****@*****.**";
            var          subscriptionWaitDelay = TimeSpan.FromMinutes(2);

            // create new topic
            var name = UtilityMethods.GenerateName("SubscribeTopic");
            var createTopicRequest = new CreateTopicRequest
            {
                Name = name
            };
            var createTopicResult = await Client.CreateTopicAsync(createTopicRequest);

            var topicArn = createTopicResult.TopicArn;

            _topicArns.Add(topicArn);

            // subscribe an email address to the topic
            var subscribeRequest = new SubscribeRequest
            {
                Protocol = "email",
                Endpoint = emailAddress,
                TopicArn = topicArn
            };
            await Client.SubscribeAsync(subscribeRequest);

            // wait until subscription has been confirmed, maximum wait time of two minutes
            // by default
            string subArn = null;
            var    latest = DateTime.Now + subscriptionWaitDelay;

            while (DateTime.Now < latest)
            {
                // get subscriptions for topic
                var listSubscriptionsRequest = new ListSubscriptionsByTopicRequest
                {
                    TopicArn = topicArn
                };
                var subs = (await Client.ListSubscriptionsByTopicAsync(listSubscriptionsRequest)).Subscriptions;
                Assert.Equal(1, subs.Count);

                // test whether the subscription has been confirmed
                var subscription = subs[0];
                if (!string.Equals(subscription.SubscriptionArn, "PendingConfirmation", StringComparison.Ordinal))
                {
                    subArn = subscription.SubscriptionArn;
                    break;
                }

                // wait
                UtilityMethods.Sleep(TimeSpan.FromSeconds(15));
            }

            // verify that the subscription was confirmed and the arn has been set
            Assert.NotNull(subArn);

            // publish a message to the topic
            await Client.PublishAsync(new PublishRequest
            {
                TopicArn = topicArn,
                Subject  = "Test subject",
                Message  = "Test message"
            });

            // delete the subscription
            await Client.UnsubscribeAsync(new UnsubscribeRequest
            {
                SubscriptionArn = subArn
            });
        }
예제 #2
0
 //[Fact]
 public void TestJson()
 {
     UtilityMethods.RunAsSync(TestJson_Async);
 }
예제 #3
0
        public void DelegationSetTests()
        {
            string createdZoneId = null;

            try
            {
                List <string> createdSets = new List <string>();

                var sets     = Client.ListReusableDelegationSetsAsync(new ListReusableDelegationSetsRequest()).Result;
                var setCount = sets.DelegationSets.Count;

                var callerReference = "DNSMigration" + DateTime.Now.ToFileTime();
                var createResponse  = Client.CreateReusableDelegationSetAsync(new CreateReusableDelegationSetRequest
                {
                    CallerReference = callerReference
                }).Result;
                Assert.NotNull(createResponse.Location);
                var delegationSet = createResponse.DelegationSet;
                Assert.NotNull(delegationSet);
                Assert.NotNull(delegationSet.CallerReference);
                Assert.NotNull(delegationSet.Id);
                Assert.NotNull(delegationSet.NameServers);
                Assert.NotEqual(0, delegationSet.NameServers.Count);
                createdSets.Add(delegationSet.Id);

                sets = Client.ListReusableDelegationSetsAsync(new ListReusableDelegationSetsRequest()).Result;
                Assert.Equal(setCount + 1, sets.DelegationSets.Count);

                CreateHostedZoneRequest createRequest = new CreateHostedZoneRequest
                {
                    Name             = ZONE_NAME,
                    CallerReference  = CALLER_REFERENCE,
                    HostedZoneConfig = new HostedZoneConfig {
                        Comment = COMMENT
                    },
                    DelegationSetId = delegationSet.Id
                };
                createdZoneId = UtilityMethods.WaitUntilSuccess <string>(() =>
                                                                         Client.CreateHostedZoneAsync(createRequest).Result.HostedZone.Id
                                                                         );

                var hostedZoneInfo = Client.GetHostedZoneAsync(new GetHostedZoneRequest
                {
                    Id = createdZoneId
                }).Result;
                Assert.NotNull(hostedZoneInfo.VPCs);
                Assert.False(hostedZoneInfo.HostedZone.Config.PrivateZone);
                Assert.Equal(delegationSet.Id, hostedZoneInfo.DelegationSet.Id);

                var hostedZones = Client.ListHostedZonesAsync(new ListHostedZonesRequest
                {
                    DelegationSetId = delegationSet.Id
                }).Result.HostedZones;
                Assert.Equal(1, hostedZones.Count);

                // add a second set
                callerReference = "DNSMigration" + DateTime.Now.ToFileTime();
                createResponse  = Client.CreateReusableDelegationSetAsync(new CreateReusableDelegationSetRequest
                {
                    CallerReference = callerReference
                }).Result;
                delegationSet = createResponse.DelegationSet;
                createdSets.Add(delegationSet.Id);

                int    totalSetCount = 0;
                string nextMarker    = null;
                do
                {
                    var response = Client.ListReusableDelegationSetsAsync(new ListReusableDelegationSetsRequest
                    {
                        MaxItems = "1",
                        Marker   = nextMarker
                    }).Result;
                    totalSetCount += response.DelegationSets.Count;
                    nextMarker     = response.NextMarker;
                } while (!string.IsNullOrEmpty(nextMarker));
                Assert.Equal(setCount + 2, totalSetCount);

                Client.DeleteHostedZoneAsync(new DeleteHostedZoneRequest
                {
                    Id = createdZoneId
                }).Wait();
                createdZoneId = null;

                foreach (var setId in createdSets)
                {
                    Client.DeleteReusableDelegationSetAsync(new DeleteReusableDelegationSetRequest
                    {
                        Id = setId
                    }).Wait();
                }

                sets = Client.ListReusableDelegationSetsAsync(new ListReusableDelegationSetsRequest()).Result;
                Assert.Equal(setCount, sets.DelegationSets.Count);
            }
            finally
            {
                DeleteHostedZone(createdZoneId);
            }
        }
예제 #4
0
        public void VPCTests()
        {
            var    vpc1          = CreateVPC();
            var    vpc2          = CreateVPC();
            string createdZoneId = null;

            try
            {
                CreateHostedZoneRequest createRequest = new CreateHostedZoneRequest
                {
                    Name             = ZONE_NAME,
                    CallerReference  = CALLER_REFERENCE,
                    HostedZoneConfig = new HostedZoneConfig {
                        Comment = COMMENT
                    },
                    VPC = vpc1
                };
                createdZoneId = UtilityMethods.WaitUntilSuccess <string>(() =>
                                                                         Client.CreateHostedZoneAsync(createRequest).Result.HostedZone.Id
                                                                         );

                var hostedZoneInfo = Client.GetHostedZoneAsync(new GetHostedZoneRequest
                {
                    Id = createdZoneId
                }).Result;
                Assert.NotNull(hostedZoneInfo.VPCs);
                Assert.Equal(1, hostedZoneInfo.VPCs.Count);
                Assert.True(hostedZoneInfo.HostedZone.Config.PrivateZone);

                var changeInfo = Client.AssociateVPCWithHostedZoneAsync(new AssociateVPCWithHostedZoneRequest
                {
                    VPC          = vpc2,
                    Comment      = COMMENT,
                    HostedZoneId = createdZoneId
                }).Result.ChangeInfo;
                Assert.NotNull(changeInfo);
                Assert.NotNull(changeInfo.Comment);
                assertValidChangeInfo(changeInfo);

                hostedZoneInfo = Client.GetHostedZoneAsync(new GetHostedZoneRequest
                {
                    Id = createdZoneId
                }).Result;
                Assert.NotNull(hostedZoneInfo.VPCs);
                Assert.Equal(2, hostedZoneInfo.VPCs.Count);

                changeInfo = Client.DisassociateVPCFromHostedZoneAsync(new DisassociateVPCFromHostedZoneRequest
                {
                    HostedZoneId = createdZoneId,
                    VPC          = vpc2
                }).Result.ChangeInfo;
                assertValidChangeInfo(changeInfo);

                hostedZoneInfo = Client.GetHostedZoneAsync(new GetHostedZoneRequest
                {
                    Id = createdZoneId
                }).Result;
                Assert.NotNull(hostedZoneInfo.VPCs);
                Assert.Equal(1, hostedZoneInfo.VPCs.Count);

                changeInfo = Client.DeleteHostedZoneAsync(new DeleteHostedZoneRequest
                {
                    Id = createdZoneId
                }).Result.ChangeInfo;
                assertValidChangeInfo(changeInfo);
            }
            finally
            {
                DeleteVPC(vpc1);
                DeleteVPC(vpc2);
                DeleteHostedZone(createdZoneId);
            }
        }
예제 #5
0
        public void HealthCheckTests()
        {
            var createRequest = new CreateHealthCheckRequest()
            {
                CallerReference   = Guid.NewGuid().ToString(),
                HealthCheckConfig = new HealthCheckConfig()
                {
                    Type             = "TCP",
                    Port             = 22,
                    IPAddress        = "12.12.12.12",
                    RequestInterval  = 10,
                    FailureThreshold = 5
                }
            };
            var createResponse = Client.CreateHealthCheckAsync(createRequest).Result;

            Assert.NotNull(createResponse.HealthCheck.Id);
            Assert.Equal(10, createResponse.HealthCheck.HealthCheckConfig.RequestInterval);
            Assert.Equal(5, createResponse.HealthCheck.HealthCheckConfig.FailureThreshold);
            string healthCheckId = createResponse.HealthCheck.Id;

            var listResponse = Client.ListHealthChecksAsync().Result;

            Assert.NotNull(listResponse.HealthChecks.FirstOrDefault(x => x.Id == healthCheckId));

            GetHealthCheckStatusResponse status = null;
            var stopTime = DateTime.Now + maxWaitTime;

            while (DateTime.Now < stopTime)
            {
                try
                {
                    status = Client.GetHealthCheckStatusAsync(new GetHealthCheckStatusRequest
                    {
                        HealthCheckId = healthCheckId
                    }).Result;
                    break;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    UtilityMethods.Sleep(TimeSpan.FromSeconds(10));
                }
            }
            Assert.NotNull(status);
            Assert.NotNull(status.HealthCheckObservations);

            var healthCheck = Client.GetHealthCheckAsync(new GetHealthCheckRequest
            {
                HealthCheckId = healthCheckId
            }).Result.HealthCheck;

            Assert.NotNull(healthCheck);
            Assert.NotNull(healthCheck.Id);
            Assert.NotNull(healthCheck.HealthCheckConfig);

            var tagSet = Client.ListTagsForResourceAsync(new ListTagsForResourceRequest
            {
                ResourceType = TagResourceType.Healthcheck,
                ResourceId   = healthCheckId
            }).Result.ResourceTagSet;

            Assert.NotNull(tagSet);
            Assert.NotNull(tagSet.ResourceId);
            Assert.NotNull(tagSet.ResourceType);
            Assert.NotNull(tagSet.Tags);
            Assert.Equal(0, tagSet.Tags.Count);

            Client.ChangeTagsForResourceAsync(new ChangeTagsForResourceRequest
            {
                ResourceType = TagResourceType.Healthcheck,
                ResourceId   = healthCheckId,
                AddTags      = new List <Tag>
                {
                    new Tag {
                        Key = "Test", Value = "true"
                    }
                }
            }).Wait();

            tagSet = Client.ListTagsForResourceAsync(new ListTagsForResourceRequest
            {
                ResourceType = TagResourceType.Healthcheck,
                ResourceId   = healthCheckId
            }).Result.ResourceTagSet;
            Assert.NotNull(tagSet);
            Assert.NotNull(tagSet.ResourceId);
            Assert.NotNull(tagSet.ResourceType);
            Assert.NotNull(tagSet.Tags);
            Assert.Equal(1, tagSet.Tags.Count);
            Assert.Equal("Test", tagSet.Tags[0].Key);
            Assert.Equal("true", tagSet.Tags[0].Value);

            Client.DeleteHealthCheckAsync(new DeleteHealthCheckRequest()
            {
                HealthCheckId = healthCheckId
            }).Wait();

            listResponse = Client.ListHealthChecksAsync().Result;
            Assert.Null(listResponse.HealthChecks.FirstOrDefault(x => x.Id == healthCheckId));
        }