Пример #1
0
        public async Task CreateResourceWithPlan()
        {
            string groupName                 = Recording.GenerateAssetName("csmrg");
            string resourceName              = Recording.GenerateAssetName("csmr");
            string password                  = Recording.GenerateAssetName("p@ss");
            string mySqlLocation             = "centralus";
            string resourceProviderNamespace = "Sendgrid.Email";
            string resourceType              = "accounts";

            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup("centralus"));

            var rawCreateOrUpdateResult = await ResourcesOperations.StartCreateOrUpdateAsync(
                groupName,
                resourceProviderNamespace,
                "",
                resourceType,
                resourceName,
                SendGridResourceProviderVersion,
                new GenericResource
            {
                Location = mySqlLocation,
                Plan     = new Plan {
                    Name = "free", Publisher = "Sendgrid", Product = "sendgrid_azure", PromotionCode = ""
                },
                Tags = new Dictionary <string, string> {
                    { "provision_source", "RMS" }
                },
                Properties = new Dictionary <string, object>
                {
                    {
                        "password", password
                    },
                    {
                        "acceptMarketingEmails", false
                    },
                    {
                        "email", "*****@*****.**"
                    }
                }
            }
                );

            var createOrUpdateResult = (await WaitForCompletionAsync(rawCreateOrUpdateResult)).Value;

            Assert.True(Utilities.LocationsAreEqual(mySqlLocation, createOrUpdateResult.Location),
                        string.Format("Resource location for resource '{0}' does not match expected location '{1}'", createOrUpdateResult.Location, mySqlLocation));
            Assert.NotNull(createOrUpdateResult.Plan);
            Assert.AreEqual("free", createOrUpdateResult.Plan.Name);

            var getResult = await ResourcesOperations.GetAsync(groupName, resourceProviderNamespace,
                                                               "", resourceType, resourceName, SendGridResourceProviderVersion);

            Assert.AreEqual(resourceName, getResult.Value.Name);
            Assert.True(Utilities.LocationsAreEqual(mySqlLocation, getResult.Value.Location),
                        string.Format("Resource location for resource '{0}' does not match expected location '{1}'", getResult.Value.Location, mySqlLocation));
            Assert.NotNull(getResult.Value.Plan);
            Assert.AreEqual("free", getResult.Value.Plan.Name);
        }
        public async Task CreatedResourceIsAvailableInListFilteredByTagNameAndValue()
        {
            string groupName          = Recording.GenerateAssetName("csmrg");
            string resourceName       = Recording.GenerateAssetName("csmr");
            string resourceNameNoTags = Recording.GenerateAssetName("csmr");
            string tagName            = Recording.GenerateAssetName("csmtn");
            string tagValue           = Recording.GenerateAssetName("csmtv");
            string location           = GetWebsiteLocation();
            string filter             = "tagName eq '" + tagName + "' and tagValue eq '" + tagValue + "'";

            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(this.ResourceGroupLocation));

            await ResourcesOperations.StartCreateOrUpdateAsync(
                groupName,
                "Microsoft.Web",
                "",
                "serverFarms",
                resourceName,
                WebResourceProviderVersion,
                new GenericResource
            {
                Tags     = { { tagName, tagValue } },
                Location = location,
                Sku      = new Sku
                {
                    Name = "S1"
                },
                Properties = new Dictionary <string, object> {
                }
            }
                );

            if (Mode == RecordedTestMode.Record)
            {
                Thread.Sleep(15 * 1000);
            }

            await ResourcesOperations.StartCreateOrUpdateAsync(
                groupName,
                "Microsoft.Web",
                "",
                "serverFarms",
                resourceNameNoTags,
                WebResourceProviderVersion,
                new GenericResource
            {
                Location = location,
                Sku      = new Sku
                {
                    Name = "S1"
                },
                Properties = new Dictionary <string, object> {
                }
            }
                );

            if (Mode == RecordedTestMode.Record)
            {
                Thread.Sleep(15 * 1000);
            }

            var listResult = await ResourcesOperations.ListByResourceGroupAsync(groupName, filter, null, null).ToEnumerableAsync();

            Assert.IsTrue(listResult.Count() == 1);
            Assert.AreEqual(resourceName, listResult.First().Name);

            var getResult = await ResourcesOperations.GetAsync(
                groupName,
                "Microsoft.Web",
                "",
                "serverFarms",
                resourceName,
                WebResourceProviderVersion);

            Assert.AreEqual(resourceName, getResult.Value.Name);
            Assert.True(getResult.Value.Tags.Keys.Contains(tagName));
        }