public async Task CreatedAndDeleteResourceById()
        {
            string subscriptionId = "b9f138a1-1d64-4108-8413-9ea3be1c1b2d";
            string groupName      = Recording.GenerateAssetName("csmrg");
            string resourceName   = Recording.GenerateAssetName("csmr");

            string location = this.GetWebsiteLocation();

            string resourceId = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Web/serverFarms/{2}", subscriptionId, groupName, resourceName);
            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(location));

            var createOrUpdateResult = await ResourcesOperations.StartCreateOrUpdateByIdAsync(
                resourceId,
                WebResourceProviderVersion,
                new GenericResource
            {
                Location = location,
                Sku      = new Sku
                {
                    Name = "S1"
                },
                Properties = new Dictionary <string, object> {
                }
            }
                );

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

            Assert.AreEqual(resourceName, listResult.First().Name);

            await ResourcesOperations.StartDeleteByIdAsync(
                resourceId, WebResourceProviderVersion);
        }
        public async Task CreatedResourceIsAvailableInList()
        {
            string groupName    = Recording.GenerateAssetName("csmrg");
            string resourceName = Recording.GenerateAssetName("csmr");
            string location     = GetWebsiteLocation();

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

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

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

            Assert.NotNull(createOrUpdateResult.Id);
            Assert.AreEqual(resourceName, createOrUpdateResult.Name);
            Assert.True(string.Equals("Microsoft.Web/serverFarms", createOrUpdateResult.Type, StringComparison.InvariantCultureIgnoreCase));
            Assert.True(Utilities.LocationsAreEqual(location, createOrUpdateResult.Location),
                        string.Format("Resource location for website '{0}' does not match expected location '{1}'", createOrUpdateResult.Location, location));
            ;

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

            Assert.IsTrue(listResult.Count() == 1);
            Assert.AreEqual(resourceName, listResult.First().Name);
            Assert.True(string.Equals("Microsoft.Web/serverFarms", createOrUpdateResult.Type, StringComparison.InvariantCultureIgnoreCase));
            Assert.True(Utilities.LocationsAreEqual(location, listResult.First().Location),
                        string.Format("Resource list location for website '{0}' does not match expected location '{1}'", listResult.First().Location, location));

            var listResult2 = ResourcesOperations.ListByResourceGroupAsync(groupName, null, null, 10).ToEnumerableAsync();

            Assert.IsTrue(listResult.Count() == 1);
            Assert.AreEqual(resourceName, listResult2.Result.First().Name);
            Assert.True(string.Equals("Microsoft.Web/serverFarms", createOrUpdateResult.Type, StringComparison.InvariantCultureIgnoreCase));
            Assert.True(Utilities.LocationsAreEqual(location, listResult.First().Location),
                        string.Format("Resource list location for website '{0}' does not match expected location '{1}'", listResult.First().Location, location));
        }
        public async Task CreatedAndDeleteResource()
        {
            string groupName    = Recording.GenerateAssetName("csmrg");
            string resourceName = Recording.GenerateAssetName("csmr");

            string location = this.GetWebsiteLocation();
            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(location));

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

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

            Assert.AreEqual(resourceName, listResult.First().Name);

            await ResourcesOperations.StartDeleteAsync(
                groupName,
                "Microsoft.Web",
                "",
                "serverfarms",
                resourceName,
                WebResourceProviderVersion);
        }
        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));
        }