public void UpdateVM_DoNotSerializeProtected()
        {
            string         guidString        = "f978ade9"; //We need to be under 24 char for storage, so making it shorter for almost all names
            string         resourceGroupName = string.Format("{0}-{1}-{2}", prefix, resourcePrefix, guidString);
            string         storageName       = string.Format("{0}{1}{2}", prefix, storagePrefix, guidString);
            string         vmName            = string.Format("{0}-{1}-{2}", prefix, vmPrefix, guidString);
            VirtualMachine vm1;
            ResourceGroup  resGroup = null;

            //string executingAssemblyPath = typeof(Microsoft.Rest.ClientRuntime.E2E.Tests.ScenarioTests.VMTests).GetTypeInfo().Assembly.Location;
            //HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords");

            using (base.MockContext = MockContext.Start(this.GetType().FullName))
            {
                try
                {
                    //Type.GetType("System.Int32").GetTypeInfo().Assembly.Location
                    string newVmId = "5C6F1669-C183-4BFC-9BBB-138E0892E917";
                    string asName  = "as5913";
                    resGroup = CreateResourceGroup(resourceGroupName);
                    StorageAccount storageAccount = CreateStorageAccount(resGroup, storageName);
                    ImageReference imageRef       = GetPlatformVMImage(useWindowsImage: true);
                    VirtualMachine vm             = CreateVirtualMachine(resGroup.Name, vmName, asName, storageAccount.Name, imageRef, out vm1);

                    //Create a new VM and Update VmId protected Property
                    MyVm myNewVm = new MyVm(vm);
                    myNewVm.UpdateVm(newVmId);
                    VirtualMachine updatedVm = myNewVm as VirtualMachine;

                    // Update VM
                    AzureOperationResponse <VirtualMachine> putResponse = Task <AzureOperationResponse <VirtualMachine> > .Run(async() =>
                    {
                        return(await ComputeClient.VirtualMachines.BeginCreateOrUpdateWithHttpMessagesAsync(resGroup.Name, updatedVm.Name, updatedVm).ConfigureAwait(false));
                    }).GetAwaiter().GetResult();

                    //Get Request Content and verify it does not contain VmId property
                    string requestContentStr = ComputeClient.GetRequestContent();
                    Assert.False(requestContentStr.Contains("VmId"));

                    //Get VM Object
                    VirtualMachine getVm = putResponse.Body;

                    // Verify the vmPutResponse does not contain updated VmId
                    Assert.NotEqual(newVmId, getVm.VmId);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    throw;
                }
                finally
                {
                    ResourceClient.ResourceGroups.Delete(resGroup.Name);
                }
            }
        }
Beispiel #2
0
 public MainWindow()
 {
     InitializeComponent();
     DataContext = new MyVm();
 }