public void ShouldCreateOneVMRole()
        {
            var mockChannel = new MockRequestChannel();

            var vmRoleToCreate = new VMRole 
            {
                Name = vmRoleName,
                Label = vmRoleLabel
            };

            var vmRoleToReturn = new VMRole
            {
                Name = vmRoleName,
                Label = vmRoleLabel,
            };
            mockChannel.AddReturnObject(vmRoleToReturn, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() });

            Guid? jobOut;
            var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel));
            var createdVMRole = vmRoleOperations.Create(cloudServiceName, vmRoleToCreate, out jobOut);

            Assert.NotNull(createdVMRole);
            Assert.Equal(vmRoleToReturn.Name, createdVMRole.Name);
            Assert.Equal(vmRoleToReturn.Label, createdVMRole.Label);

            var requestList = mockChannel.ClientRequests;
            Assert.Equal(1, requestList.Count);
            Assert.Equal(HttpMethod.Post.ToString(), requestList[0].Item1.Method);

            // Check the URI (for Azure consistency)
            Assert.Equal(String.Format(genericBaseUri,cloudServiceName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1));
        }
        public void ShouldCreateOneVMRole()
        {
            var mockChannel = new MockRequestChannel();

            var vmRoleToCreate = new VMRole
            {
                Name  = vmRoleName,
                Label = vmRoleLabel
            };

            var vmRoleToReturn = new VMRole
            {
                Name  = vmRoleName,
                Label = vmRoleLabel,
            };

            mockChannel.AddReturnObject(vmRoleToReturn, new WebHeaderCollection {
                "x-ms-request-id:" + Guid.NewGuid()
            });

            Guid?jobOut;
            var  vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel));
            var  createdVMRole    = vmRoleOperations.Create(cloudServiceName, vmRoleToCreate, out jobOut);

            Assert.IsNotNull(createdVMRole);
            Assert.IsInstanceOfType(createdVMRole, typeof(VMRole));
            Assert.AreEqual(vmRoleToReturn.Name, createdVMRole.Name);
            Assert.AreEqual(vmRoleToReturn.Label, createdVMRole.Label);

            var requestList = mockChannel.ClientRequests;

            Assert.AreEqual(1, requestList.Count);
            Assert.AreEqual(HttpMethod.Post.ToString(), requestList[0].Item1.Method);

            // Check the URI (for Azure consistency)
            Assert.AreEqual(String.Format(genericBaseUri, cloudServiceName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1));
        }
        public override void ExecuteCmdlet()
        {
            Guid?  vmRolejobId           = Guid.Empty;
            VMRole createdVmRole         = null;
            IEnumerable <VMRole> results = null;

            var vmRoleOperations = new VMRoleOperations(this.WebClientFactory);
            var newVMRole        = new VMRole()
            {
                Name  = this.Name,
                Label = this.Label,
                ResourceDefinition    = this.ResourceDefinition,
                InstanceView          = null,
                ResourceConfiguration = null,
                ProvisioningState     = null,
                Substate = null,
            };

            if (this.ParameterSetName == WAPackCmdletParameterSets.QuickCreate)
            {
                var cloudService = new Utilities.WAPackIaaS.DataContract.CloudService()
                {
                    Name  = this.Name,
                    Label = this.Label
                };

                Guid?cloudServiceJobId      = Guid.Empty;
                var  cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory);
                cloudServiceOperations.Create(cloudService, out cloudServiceJobId);
                WaitForJobCompletion(cloudServiceJobId);

                try
                {
                    createdVmRole = vmRoleOperations.Create(this.Name, newVMRole, out vmRolejobId);
                    WaitForJobCompletion(vmRolejobId);

                    var vmRole = vmRoleOperations.Read(this.Name, this.Name);
                    results = new List <VMRole>()
                    {
                        vmRole
                    };
                }
                catch (Exception)
                {
                    cloudServiceOperations.Delete(this.Name, out cloudServiceJobId);
                    WaitForJobCompletion(cloudServiceJobId);
                    throw;
                }
            }
            else if (this.ParameterSetName == WAPackCmdletParameterSets.FromCloudService)
            {
                createdVmRole = vmRoleOperations.Create(this.CloudService.Name, newVMRole, out vmRolejobId);
                WaitForJobCompletion(vmRolejobId);

                var vmRole = vmRoleOperations.Read(this.CloudService.Name, this.Name);
                results = new List <VMRole>()
                {
                    vmRole
                };
            }

            this.GenerateCmdletOutput(results);
        }
        public override void ExecuteCmdlet()
        {
            Guid? vmRolejobId = Guid.Empty;
            VMRole createdVmRole = null;
            IEnumerable<VMRole> results = null;

            var vmRoleOperations = new VMRoleOperations(this.WebClientFactory);
            var newVMRole = new VMRole()
            {
                Name = this.Name,
                Label = this.Label,
                ResourceDefinition = this.ResourceDefinition,
                InstanceView = null,
                ResourceConfiguration = null,
                ProvisioningState = null,
                Substate = null,
            };

            if (this.ParameterSetName == WAPackCmdletParameterSets.QuickCreate)
            {
                var cloudService = new Utilities.WAPackIaaS.DataContract.CloudService()
                {
                    Name = this.Name,
                    Label = this.Label
                };

                Guid? cloudServiceJobId = Guid.Empty;
                var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory);
                cloudServiceOperations.Create(cloudService, out cloudServiceJobId);
                WaitForJobCompletion(cloudServiceJobId);

                try
                {
                    createdVmRole = vmRoleOperations.Create(this.Name, newVMRole, out vmRolejobId);
                    WaitForJobCompletion(vmRolejobId);

                    var vmRole = vmRoleOperations.Read(this.Name, this.Name);
                    results = new List<VMRole>() { vmRole };
                }
                catch (Exception)
                {
                    cloudServiceOperations.Delete(this.Name, out cloudServiceJobId);
                    WaitForJobCompletion(cloudServiceJobId);
                    throw;
                }
            }
            else if (this.ParameterSetName == WAPackCmdletParameterSets.FromCloudService)
            {
                createdVmRole = vmRoleOperations.Create(this.CloudService.Name, newVMRole, out vmRolejobId);
                WaitForJobCompletion(vmRolejobId);

                var vmRole = vmRoleOperations.Read(this.CloudService.Name, this.Name);
                results = new List<VMRole>() { vmRole };
            }

            this.GenerateCmdletOutput(results);
        }