public void CanCreateResourceGroup()
 {
     using (MockContext context = MockContext.Start(this.GetType().FullName))
     {
         string groupName = TestUtilities.GenerateName("csmrg");
         ResourceManagementClient client = this.GetResourceManagementClient(context, new RecordedDelegatingHandler());
         var result = client.ResourceGroups.CreateOrUpdate(groupName,
                                                           new ResourceGroup
         {
             Location = DefaultLocation,
             Tags     = new Dictionary <string, string>()
             {
                 { "department", "finance" }, { "tagname", "tagvalue" }
             },
         });
         var listResult  = client.ResourceGroups.List();
         var listedGroup = listResult.FirstOrDefault((g) => string.Equals(g.Name, groupName, StringComparison.Ordinal));
         Assert.NotNull(listedGroup);
         Assert.Equal("finance", listedGroup.Tags["department"]);
         Assert.Equal("tagvalue", listedGroup.Tags["tagname"]);
         Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(DefaultLocation, listedGroup.Location),
                     string.Format("Expected location '{0}' did not match actual location '{1}'", DefaultLocation, listedGroup.Location));
         var gottenGroup = client.ResourceGroups.Get(groupName);
         Assert.NotNull(gottenGroup);
         Assert.Equal(groupName, gottenGroup.Name);
         Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(DefaultLocation, gottenGroup.Location),
                     string.Format("Expected location '{0}' did not match actual location '{1}'", DefaultLocation, gottenGroup.Location));
     }
 }
Exemplo n.º 2
0
        public void CreateResourceWithPlan()
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                string groupName     = TestUtilities.GenerateName("csmrg");
                string resourceName  = TestUtilities.GenerateName("csmr");
                string password      = TestUtilities.GenerateName("p@ss");
                var    client        = GetResourceManagementClient(context, handler);
                string mySqlLocation = "centralus";
                var    groupIdentity = new ResourceIdentity
                {
                    ResourceName = resourceName,
                    ResourceProviderNamespace = "Sendgrid.Email",
                    ResourceType = "accounts",
                    ResourceProviderApiVersion = SendGridResourceProviderVersion
                };

                client.SetRetryPolicy(new RetryPolicy <HttpStatusCodeErrorDetectionStrategy>(1));

                client.ResourceGroups.CreateOrUpdate(groupName, new ResourceGroup {
                    Location = "centralus"
                });
                var createOrUpdateResult = client.Resources.CreateOrUpdate(groupName, groupIdentity.ResourceProviderNamespace, "", groupIdentity.ResourceType,
                                                                           groupIdentity.ResourceName, groupIdentity.ResourceProviderApiVersion,
                                                                           new GenericResource
                {
                    Location = mySqlLocation,
                    Plan     = new Plan {
                        Name = "free", Publisher = "Sendgrid", Product = "sendgrid_azure", PromotionCode = ""
                    },
                    Tags = new Dictionary <string, string> {
                        { "provision_source", "RMS" }
                    },
                    Properties = JObject.Parse("{'password':'******','acceptMarketingEmails':false,'email':'*****@*****.**'}"),
                }
                                                                           );

                Assert.True(ResourcesManagementTestUtilities.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.Equal("free", createOrUpdateResult.Plan.Name);

                var getResult = client.Resources.Get(groupName, groupIdentity.ResourceProviderNamespace,
                                                     "", groupIdentity.ResourceType, groupIdentity.ResourceName, groupIdentity.ResourceProviderApiVersion);

                Assert.Equal(resourceName, getResult.Name);
                Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(mySqlLocation, getResult.Location),
                            string.Format("Resource location for resource '{0}' does not match expected location '{1}'", getResult.Location, mySqlLocation));
                Assert.NotNull(getResult.Plan);
                Assert.Equal("free", getResult.Plan.Name);
            }
        }
        public void CreateResourceWithPlan()
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                string groupName     = TestUtilities.GenerateName("csmrg");
                string resourceName  = TestUtilities.GenerateName("csmr");
                var    client        = GetResourceManagementClient(handler);
                string mySqlLocation = GetMySqlLocation(client);
                var    groupIdentity = new ResourceIdentity
                {
                    ResourceName = resourceName,
                    ResourceProviderNamespace = "SuccessBricks.ClearDB",
                    ResourceType = "databases",
                    ResourceProviderApiVersion = StoreResourceProviderVersion
                };

                client.SetRetryPolicy(new RetryPolicy <DefaultHttpErrorDetectionStrategy>(1));

                client.ResourceGroups.CreateOrUpdate(groupName, new ResourceGroup {
                    Location = this.ResourceGroupLocation
                });
                var createOrUpdateResult = client.Resources.CreateOrUpdate(groupName, groupIdentity,
                                                                           new GenericResource
                {
                    Location = mySqlLocation,
                    Plan     = new Plan {
                        Name = "Free"
                    },
                    Tags = new Dictionary <string, string> {
                        { "provision_source", "RMS" }
                    }
                }
                                                                           );

                Assert.Equal(HttpStatusCode.OK, createOrUpdateResult.StatusCode);
                Assert.Equal(resourceName, createOrUpdateResult.Resource.Name);
                Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(mySqlLocation, createOrUpdateResult.Resource.Location),
                            string.Format("Resource location for resource '{0}' does not match expected location '{1}'", createOrUpdateResult.Resource.Location, mySqlLocation));
                Assert.NotNull(createOrUpdateResult.Resource.Plan);
                Assert.Equal("Free", createOrUpdateResult.Resource.Plan.Name);

                var getResult = client.Resources.Get(groupName, groupIdentity);

                Assert.Equal(HttpStatusCode.OK, getResult.StatusCode);
                Assert.Equal(resourceName, getResult.Resource.Name);
                Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(mySqlLocation, getResult.Resource.Location),
                            string.Format("Resource location for resource '{0}' does not match expected location '{1}'", getResult.Resource.Location, mySqlLocation));
                Assert.NotNull(getResult.Resource.Plan);
                Assert.Equal("Free", getResult.Resource.Plan.Name);
            }
        }
        public void CreatedResourceIsAvailableInList()
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                string groupName    = TestUtilities.GenerateName("csmrg");
                string resourceName = TestUtilities.GenerateName("csmr");
                var    client       = GetResourceManagementClient(context, handler);
                string location     = GetWebsiteLocation(client);

                client.SetRetryPolicy(new RetryPolicy <HttpStatusCodeErrorDetectionStrategy>(1));

                client.ResourceGroups.CreateOrUpdate(groupName, new ResourceGroup {
                    Location = this.ResourceGroupLocation
                });
                var createOrUpdateResult = client.Resources.CreateOrUpdate(groupName, "Microsoft.Web", "", "serverFarms", resourceName, WebResourceProviderVersion,
                                                                           new GenericResource
                {
                    Location = location,
                    Sku      = new Sku
                    {
                        Name = "S1"
                    },
                    Properties = JObject.Parse("{}")
                }
                                                                           );

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

                var listResult = client.Resources.ListByResourceGroup(groupName);

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

                listResult = client.Resources.ListByResourceGroup(groupName, new ODataQuery <GenericResourceFilter> {
                    Top = 10
                });

                Assert.Single(listResult);
                Assert.Equal(resourceName, listResult.First().Name);
                Assert.True(string.Equals("Microsoft.Web/serverFarms", createOrUpdateResult.Type, StringComparison.InvariantCultureIgnoreCase));
                Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(location, listResult.First().Location),
                            string.Format("Resource list location for website '{0}' does not match expected location '{1}'", listResult.First().Location, location));
            }
        }
Exemplo n.º 5
0
        public void CreatedResourceIsAvailableInList()
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                string groupName       = TestUtilities.GenerateName("csmrg");
                string resourceName    = TestUtilities.GenerateName("csmr");
                var    client          = GetResourceManagementClient(context, handler);
                string websiteLocation = GetWebsiteLocation(client);

                client.SetRetryPolicy(new RetryPolicy <HttpStatusCodeErrorDetectionStrategy>(1));

                client.ResourceGroups.CreateOrUpdate(groupName, new ResourceGroup {
                    Location = this.ResourceGroupLocation
                });
                var createOrUpdateResult = client.Resources.CreateOrUpdate(groupName, "Microsoft.Web", "", "sites", resourceName, WebResourceProviderVersion,
                                                                           new GenericResource
                {
                    Location   = websiteLocation,
                    Properties = JObject.Parse("{'name':'" + resourceName + "','siteMode':'Limited','computeMode':'Shared', 'sku':'Free', 'workerSize': 0}"),
                }
                                                                           );

                Assert.NotNull(createOrUpdateResult.Id);
                Assert.Equal(resourceName, createOrUpdateResult.Name);
                Assert.Equal("Microsoft.Web/sites", createOrUpdateResult.Type);
                Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(websiteLocation, createOrUpdateResult.Location),
                            string.Format("Resource location for website '{0}' does not match expected location '{1}'", createOrUpdateResult.Location, websiteLocation));

                var listResult = client.Resources.ListByResourceGroup(groupName);

                Assert.Single(listResult);
                Assert.Equal(resourceName, listResult.First().Name);
                Assert.Equal("Microsoft.Web/sites", listResult.First().Type);
                Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(websiteLocation, listResult.First().Location),
                            string.Format("Resource list location for website '{0}' does not match expected location '{1}'", listResult.First().Location, websiteLocation));

                listResult = client.Resources.ListByResourceGroup(groupName, new ODataQuery <GenericResourceFilter> {
                    Top = 10
                });

                Assert.Single(listResult);
                Assert.Equal(resourceName, listResult.First().Name);
                Assert.Equal("Microsoft.Web/sites", listResult.First().Type);
                Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(websiteLocation, listResult.First().Location),
                            string.Format("Resource list location for website '{0}' does not match expected location '{1}'", listResult.First().Location, websiteLocation));
            }
        }
        public void CreatedResourceIsAvailableInList()
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                string groupName       = TestUtilities.GenerateName("csmrg");
                string resourceName    = TestUtilities.GenerateName("csmr");
                var    client          = GetResourceManagementClient(handler);
                string websiteLocation = "westus";

                client.SetRetryPolicy(new RetryPolicy <DefaultHttpErrorDetectionStrategy>(1));

                client.ResourceGroups.CreateOrUpdate(groupName, new ResourceGroup {
                    Location = this.ResourceGroupLocation
                });
                var createOrUpdateResult = client.Resources.CreateOrUpdate(groupName, new ResourceIdentity
                {
                    ResourceName = resourceName,
                    ResourceProviderNamespace = "Microsoft.Web",
                    ResourceType = "sites",
                    ResourceProviderApiVersion = WebResourceProviderVersion
                },
                                                                           new GenericResource
                {
                    Location   = websiteLocation,
                    Properties = "{'name':'" + resourceName + "','siteMode':'Limited','computeMode':'Shared', 'sku':'Free', 'workerSize': 0}",
                }
                                                                           );

                Assert.Equal(HttpStatusCode.OK, createOrUpdateResult.StatusCode);
                Assert.NotNull(createOrUpdateResult.Resource.Id);
                Assert.Equal(resourceName, createOrUpdateResult.Resource.Name);
                Assert.Equal("Microsoft.Web/sites", createOrUpdateResult.Resource.Type);
                Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(websiteLocation, createOrUpdateResult.Resource.Location),
                            string.Format("Resource location for website '{0}' does not match expected location '{1}'", createOrUpdateResult.Resource.Location, websiteLocation));

                var listResult = client.Resources.List(new ResourceListParameters
                {
                    ResourceGroupName = groupName
                });

                Assert.Equal(1, listResult.Resources.Count);
                Assert.Equal(resourceName, listResult.Resources[0].Name);
                Assert.Equal("Microsoft.Web/sites", listResult.Resources[0].Type);
                Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(websiteLocation, listResult.Resources[0].Location),
                            string.Format("Resource list location for website '{0}' does not match expected location '{1}'", listResult.Resources[0].Location, websiteLocation));

                listResult = client.Resources.List(new ResourceListParameters
                {
                    ResourceGroupName = groupName,
                    Top = 10
                });

                Assert.Equal(1, listResult.Resources.Count);
                Assert.Equal(resourceName, listResult.Resources[0].Name);
                Assert.Equal("Microsoft.Web/sites", listResult.Resources[0].Type);
                Assert.True(ResourcesManagementTestUtilities.LocationsAreEqual(websiteLocation, listResult.Resources[0].Location),
                            string.Format("Resource list location for website '{0}' does not match expected location '{1}'", listResult.Resources[0].Location, websiteLocation));
            }
        }