コード例 #1
0
        public void GetSecurityGroupByName()
        {
            // Arrange
            string vpcId = Ec2Client.DescribeVpcs(new DescribeVpcsRequest())
                           .Vpcs.First(vpc => vpc.Tags.First(tag => tag.Key == "Name").Value == "Infrastructure Dev")
                           .VpcId;
            string securityGroupName = Conventions.DefaultSecurityGroupName;

            // Act
            var securityGroup = Service.GetSecurityGroup(securityGroupName, vpcId);

            // Assert
            securityGroup.Should().NotBeNull();
        }
コード例 #2
0
        public void CreateDefaultSecurityGroup_Ok()
        {
            // Arrange
            string vpcId = Ec2Client.DescribeVpcs(new DescribeVpcsRequest())
                           .Vpcs.First(vpc => vpc.Tags.First(tag => tag.Key == "Name").Value == "Infrastructure Dev")
                           .VpcId;

            // .. Verify that the security group doesn't already exist since this test relies on it not existing
            var describeSgs = new DescribeSecurityGroupsRequest {
                GroupNames = new List <string> {
                    _testSecurityGroupName
                }
            };

            try
            {
                Ec2Client.DescribeSecurityGroups(describeSgs);
            }
            catch (AmazonEC2Exception e)
            {
                if (e.Message == "The security group 'Test_SeeMe_DeleteMe' does not exist")
                {
                    // This is what we want to happen so let's keep going
                }
                else
                {
                    throw;
                }
            }

            // Act
            Assert.AreEqual(Creator.SecurityGroupName, _testSecurityGroupName);
            string sgId = Creator.TryCreateDefaultSecurityGroup(vpcId);

            // Assert
            sgId.Should().NotBeNull();
        }