public static int SetUpDefaultRemoteAppTemplateCreate(Mock <IRemoteAppManagementClient> clientMock, string imageName, string id, string region, string vhdPath) { const int numberOfTemplatesCreated = 1; TemplateImageResult response = new TemplateImageResult() { RequestId = "1111-33444", StatusCode = System.Net.HttpStatusCode.Accepted, TemplateImage = new TemplateImage() { Name = imageName, Status = TemplateImageStatus.UploadPending, Type = TemplateImageType.PlatformImage, RegionList = new List <string>() { region } } }; mockTemplates = new List <TemplateImage>() { new TemplateImage() { Name = response.TemplateImage.Name, Status = response.TemplateImage.Status, Id = response.TemplateImage.Id, NumberOfLinkedCollections = response.TemplateImage.NumberOfLinkedCollections, Type = response.TemplateImage.Type, RegionList = response.TemplateImage.RegionList } }; OperationResultWithTrackingId responseWithTrackingId = new OperationResultWithTrackingId() { RequestId = "2222-1111-33424", StatusCode = System.Net.HttpStatusCode.OK }; UploadScriptResult responseUpload = new UploadScriptResult() { RequestId = "1111-33333-5", StatusCode = System.Net.HttpStatusCode.OK, Script = "$i = 1; foreach ($arg in $Args) { echo \"The $i parameter is $arg\"; $i++ }; return $true", // mock script just prints out arguments }; ISetup <IRemoteAppManagementClient, Task <OperationResultWithTrackingId> > SetupStorageTemplate = clientMock.Setup(c => c.TemplateImages.EnsureStorageInRegionAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())); SetupStorageTemplate.Returns(Task.Factory.StartNew(() => responseWithTrackingId)); ISetup <IRemoteAppManagementClient, Task <TemplateImageResult> > SetupSetTemplate = clientMock.Setup(c => c.TemplateImages.SetAsync(It.IsAny <TemplateImageDetails>(), It.IsAny <CancellationToken>())); SetupSetTemplate.Returns(Task.Factory.StartNew(() => response)); ISetup <IRemoteAppManagementClient, Task <UploadScriptResult> > SetupUploadTemplate = clientMock.Setup(c => c.TemplateImages.GetUploadScriptAsync(It.IsAny <CancellationToken>())); SetupUploadTemplate.Returns(Task.Factory.StartNew(() => responseUpload)); return(numberOfTemplatesCreated); }
public static void SetUpDefaultRemoteAppRenameTemplate(Mock <IRemoteAppManagementClient> clientMock, string newName, string id) { TemplateImageResult response = new TemplateImageResult() { StatusCode = System.Net.HttpStatusCode.Accepted, RequestId = "12345", TemplateImage = new TemplateImage() { Id = id, Name = newName, RegionList = new List <string>() { "West US" } } }; mockTemplates = new List <TemplateImage>() { new TemplateImage() { Id = response.TemplateImage.Id, Name = response.TemplateImage.Name, RegionList = response.TemplateImage.RegionList } }; ISetup <IRemoteAppManagementClient, Task <TemplateImageResult> > setup = clientMock.Setup(c => c.TemplateImages.SetAsync(It.IsAny <TemplateImageDetails>(), It.IsAny <CancellationToken>())); setup.Returns(Task.Factory.StartNew(() => response)); return; }
public void CanGetTemplateImageByName() { using (UndoContext context = UndoContext.Current) { context.Start(); RemoteAppManagementClient client = GetRemoteAppManagementClient(); TemplateImageListResult templatImagesList = client.TemplateImages.List(); Assert.NotNull(templatImagesList); Assert.NotEmpty(templatImagesList.RemoteAppTemplateImageList); Assert.True(templatImagesList.StatusCode == System.Net.HttpStatusCode.OK); foreach (TemplateImage image in templatImagesList.RemoteAppTemplateImageList) { TemplateImageResult imageByNameResponse = client.TemplateImages.Get(image.Name); Assert.NotNull(imageByNameResponse); Assert.NotNull(imageByNameResponse.TemplateImage); Assert.True(imageByNameResponse.TemplateImage.Id == image.Id); Assert.True(imageByNameResponse.TemplateImage.Name == image.Name); } } }
private bool GetTemplate(string imageName) { TemplateImageResult response = null; response = CallClient(() => Client.TemplateImages.Get(imageName), Client.TemplateImages); if (response != null) { WriteObject(response.TemplateImage); } return(found); }
public override void ExecuteCmdlet() { TemplateImageResult response = null; TemplateImageDetails details = null; TemplateImage matchingTemplate = null; matchingTemplate = FilterTemplateImage(ImageName, Operation.Update); details = new TemplateImageDetails() { Id = matchingTemplate.Id, Region = matchingTemplate.RegionList[0], Name = NewName }; response = CallClient(() => Client.TemplateImages.Set(details), Client.TemplateImages); if (response != null) { WriteObject(response.TemplateImage); } }
private void ImportTemplateImage() { TemplateImageResult response = null; TemplateImageDetails details = null; EnsureStorageInRegion(Location); FilterTemplateImage(ImageName, Operation.Create); details = new TemplateImageDetails() { Name = ImageName, Region = Location, SourceImageSasUri = GetAzureVmSasUri(AzureVmImageName) }; response = CallClient(() => Client.TemplateImages.Set(details), Client.TemplateImages); if (response != null) { WriteObject(response.TemplateImage); } }
public static int SetUpDefaultRemoteAppTemplatesByName(Mock <IRemoteAppManagementClient> clientMock, string imageName) { TemplateImageResult response = new TemplateImageResult() { RequestId = "222-1234-9999", StatusCode = System.Net.HttpStatusCode.OK, TemplateImage = new TemplateImage() { Name = imageName, Status = TemplateImageStatus.Ready, Id = "1111", NumberOfLinkedCollections = 2, Type = TemplateImageType.PlatformImage, RegionList = new List <string>() { "West US" } } }; mockTemplates = new List <TemplateImage>() { new TemplateImage() { Name = response.TemplateImage.Name, Status = response.TemplateImage.Status, Id = response.TemplateImage.Id, NumberOfLinkedCollections = response.TemplateImage.NumberOfLinkedCollections, Type = response.TemplateImage.Type, RegionList = response.TemplateImage.RegionList } }; ISetup <IRemoteAppManagementClient, Task <TemplateImageResult> > Setup = clientMock.Setup(c => c.TemplateImages.GetAsync(It.IsAny <String>(), It.IsAny <CancellationToken>())); Setup.Returns(Task.Factory.StartNew(() => response)); return(mockTemplates.Count); }
private TemplateImage StartTemplateUpload(TemplateImage image) { TemplateImageResult response = null; TemplateImageDetails details = null; TemplateImage templateImage = null; EnsureStorageInRegion(Location); if (Resume) { templateImage = image; } else { details = new TemplateImageDetails() { Name = ImageName, Region = Location }; response = CallClient_ThrowOnError(() => Client.TemplateImages.Set(details)); templateImage = response.TemplateImage; if (templateImage == null) { throw new RemoteAppServiceException(String.Format( System.Globalization.CultureInfo.InvariantCulture, Commands_RemoteApp.TemplateImageCreationFailedErrorFormat, ImageName, Location) , ErrorCategory.InvalidResult); } } return(templateImage); }
public static bool ContainsExpectedResult(List <TemplateImageResult> expectedResult, TemplateImageResult operationResult) { bool isIdentical = false; foreach (TemplateImageResult expected in expectedResult) { isIdentical = expected.RequestId == operationResult.RequestId; isIdentical &= expected.StatusCode == operationResult.StatusCode; isIdentical &= expected.TemplateImage.Name == operationResult.TemplateImage.Name; isIdentical &= expected.TemplateImage.Status == operationResult.TemplateImage.Status; isIdentical &= expected.TemplateImage.Id == operationResult.TemplateImage.Id; isIdentical &= expected.TemplateImage.NumberOfLinkedCollections == operationResult.TemplateImage.NumberOfLinkedCollections; isIdentical &= expected.TemplateImage.Type == operationResult.TemplateImage.Type; if (isIdentical) { break; } } return(isIdentical); }
public void CanCreateTemplateImagesSuccessfully() { using (UndoContext context = UndoContext.Current) { context.Start(); string imageName = "my_unit_test_created_templateimage"; string returnedImageName = null; HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient client = GetRemoteAppManagementClient(); TemplateImageResult setResponse; AzureOperationResponse deleteResponse; TemplateImageListResult listResponse = null; IList <TemplateImage> imageList; TemplateImage myImage = null; bool foundTestImage = false; string newName = "renamed_my_test_image"; TemplateImageDetails renameDetails = null; TemplateImageDetails newImageDetails = new TemplateImageDetails() { Name = imageName, Region = "West US" }; Assert.DoesNotThrow(() => { setResponse = client.TemplateImages.Set(newImageDetails); }); // now check the list Assert.DoesNotThrow(() => { listResponse = client.TemplateImages.List(); imageList = listResponse.RemoteAppTemplateImageList; foreach (TemplateImage image in imageList) { if ((image.Name == imageName)) { foreach (string region in image.RegionList) { if (region == newImageDetails.Region) { foundTestImage = true; // cleanup returnedImageName = image.Name; myImage = image; break; } } } } }); Assert.True(foundTestImage); Assert.False(string.IsNullOrEmpty(returnedImageName)); Assert.NotNull(myImage); // rename the image renameDetails = new TemplateImageDetails() { Id = myImage.Id, Name = newName, Region = "West US" }; setResponse = null; Assert.DoesNotThrow(() => { setResponse = client.TemplateImages.Set(renameDetails); }); Assert.NotNull(setResponse); Assert.NotNull(setResponse.TemplateImage); Assert.Equal(System.Net.HttpStatusCode.OK, setResponse.StatusCode); // verify that we have an image with the new name TemplateImageResult imageResponse = null; Assert.DoesNotThrow(() => { imageResponse = client.TemplateImages.Get(newName); }); Assert.NotNull(imageResponse); Assert.NotNull(imageResponse.TemplateImage); Assert.Equal(newName, imageResponse.TemplateImage.Name); Assert.True(imageResponse.TemplateImage.RegionList.Contains("West US"), "Unexpected region of the renamed image: " + String.Join(", ", imageResponse.TemplateImage.RegionList)); Assert.DoesNotThrow(() => { deleteResponse = client.TemplateImages.Delete(newName); }); } }