protected void ValidateVM(VirtualMachine vm, VirtualMachine vmOut, string expectedVMReferenceId) { Assert.True(!string.IsNullOrEmpty(vmOut.ProvisioningState)); Assert.True(vmOut.HardwareProfile.VirtualMachineSize == vm.HardwareProfile.VirtualMachineSize); Assert.NotNull(vmOut.StorageProfile.OSDisk); if (vm.StorageProfile.OSDisk != null) { Assert.True(vmOut.StorageProfile.OSDisk.Name == vm.StorageProfile.OSDisk.Name); Assert.True(vmOut.StorageProfile.OSDisk.VirtualHardDisk.Uri == vm.StorageProfile.OSDisk.VirtualHardDisk.Uri); Assert.True(vmOut.StorageProfile.OSDisk.Caching == vm.StorageProfile.OSDisk.Caching); Assert.True(vmOut.StorageProfile.OSDisk.DiskSizeGB == vm.StorageProfile.OSDisk.DiskSizeGB); if (vm.StorageProfile.OSDisk.EncryptionSettings != null) { var encryptionSettings = vm.StorageProfile.OSDisk.EncryptionSettings; Assert.NotNull(vmOut.StorageProfile.OSDisk.EncryptionSettings); var actualEncryptionSettings = vmOut.StorageProfile.OSDisk.EncryptionSettings; Assert.Equal(encryptionSettings.DiskEncryptionKey.SourceVault.ReferenceUri, actualEncryptionSettings.DiskEncryptionKey.SourceVault.ReferenceUri); Assert.Equal(encryptionSettings.DiskEncryptionKey.SecretUrl, actualEncryptionSettings.DiskEncryptionKey.SecretUrl); if (encryptionSettings.KeyEncryptionKey != null) { Assert.NotNull(encryptionSettings.KeyEncryptionKey); Assert.Equal(encryptionSettings.KeyEncryptionKey.SourceVault.ReferenceUri, actualEncryptionSettings.KeyEncryptionKey.SourceVault.ReferenceUri); Assert.Equal(encryptionSettings.KeyEncryptionKey.KeyUrl, actualEncryptionSettings.KeyEncryptionKey.KeyUrl); } } } if (vm.StorageProfile.DataDisks != null && vm.StorageProfile.DataDisks.Any()) { foreach (var dataDisk in vm.StorageProfile.DataDisks) { var dataDiskOut = vmOut.StorageProfile.DataDisks.FirstOrDefault( d => string.Equals(dataDisk.Name, d.Name, StringComparison.OrdinalIgnoreCase)); Assert.NotNull(dataDiskOut); // Disabling resharper null-ref check as it doesn't seem to understand the not-null assert above. // ReSharper disable PossibleNullReferenceException Assert.NotNull(dataDiskOut.VirtualHardDisk); Assert.NotNull(dataDiskOut.VirtualHardDisk.Uri); if (dataDisk.SourceImage != null && dataDisk.SourceImage.Uri != null) { Assert.NotNull(dataDiskOut.SourceImage); Assert.Equal(dataDisk.SourceImage.Uri, dataDiskOut.SourceImage.Uri); } // ReSharper enable PossibleNullReferenceException Assert.True(dataDiskOut.DiskSizeGB == dataDisk.DiskSizeGB); } } if(vm.OSProfile != null && vm.OSProfile.Secrets != null && vm.OSProfile.Secrets.Any()) { foreach (var secret in vm.OSProfile.Secrets) { Assert.NotNull(secret.VaultCertificates); var secretOut = vmOut.OSProfile.Secrets.FirstOrDefault( s => string.Equals(secret.SourceVault.ReferenceUri, s.SourceVault.ReferenceUri)); Assert.NotNull(secretOut); // Disabling resharper null-ref check as it doesn't seem to understand the not-null assert above. // ReSharper disable PossibleNullReferenceException Assert.NotNull(secretOut.VaultCertificates); var VaultCertComparer = new VaultCertComparer(); Assert.True(secretOut.VaultCertificates.SequenceEqual(secret.VaultCertificates, VaultCertComparer)); // ReSharper enable PossibleNullReferenceException } } if (vm.DiagnosticsProfile != null) { Assert.Equal(vm.DiagnosticsProfile.BootDiagnostics.Enabled, vmOut.DiagnosticsProfile.BootDiagnostics.Enabled); Assert.Equal(vm.DiagnosticsProfile.BootDiagnostics.StorageUri, vmOut.DiagnosticsProfile.BootDiagnostics.StorageUri); } Assert.NotNull(vmOut.AvailabilitySetReference); Assert.True(vm.AvailabilitySetReference.ReferenceUri.ToLowerInvariant() == vmOut.AvailabilitySetReference.ReferenceUri.ToLowerInvariant()); ValidatePlan(vm.Plan, vmOut.Plan); // TODO: it's null somtimes. //Assert.NotNull(vmOut.Properties.Id); //Assert.True(expectedVMReferenceId.ToLowerInvariant() == vmOut.Properties.Id.ToLowerInvariant()); }
protected void ValidateVM(VirtualMachine vm, VirtualMachine vmOut, string expectedVMReferenceId) { Assert.True(!string.IsNullOrEmpty(vmOut.ProvisioningState)); Assert.True(vmOut.HardwareProfile.VirtualMachineSize == vm.HardwareProfile.VirtualMachineSize); Assert.True(vmOut.StorageProfile.OSDisk != null); if (vm.StorageProfile.OSDisk != null) { Assert.True(vmOut.StorageProfile.OSDisk.Name == vm.StorageProfile.OSDisk.Name); Assert.True(vmOut.StorageProfile.OSDisk.VirtualHardDisk.Uri == vm.StorageProfile.OSDisk.VirtualHardDisk.Uri); Assert.True(vmOut.StorageProfile.OSDisk.Caching == vm.StorageProfile.OSDisk.Caching); } if (vm.StorageProfile.DataDisks != null && vm.StorageProfile.DataDisks.Any()) { foreach (var dataDisk in vm.StorageProfile.DataDisks) { var dataDiskOut = vmOut.StorageProfile.DataDisks.FirstOrDefault( d => string.Equals(dataDisk.Name, d.Name, StringComparison.OrdinalIgnoreCase)); Assert.NotNull(dataDiskOut); Assert.NotNull(dataDiskOut.VirtualHardDisk); Assert.NotNull(dataDiskOut.VirtualHardDisk.Uri); if (dataDisk.SourceImage != null && dataDisk.SourceImage.Uri != null) { Assert.NotNull(dataDiskOut.SourceImage); Assert.Equal(dataDisk.SourceImage.Uri, dataDiskOut.SourceImage.Uri); } } } if(vm.OSProfile != null && vm.OSProfile.Secrets != null && vm.OSProfile.Secrets.Any()) { foreach (var secret in vm.OSProfile.Secrets) { var secretOut = vmOut.OSProfile.Secrets.FirstOrDefault( s => string.Equals(secret.SourceVault.ReferenceUri, s.SourceVault.ReferenceUri)); var VaultCertComparer = new VaultCertComparer(); Assert.True(secretOut.VaultCertificates.SequenceEqual(secret.VaultCertificates, VaultCertComparer)); } } Assert.NotNull(vmOut.AvailabilitySetReference); Assert.True(vm.AvailabilitySetReference.ReferenceUri.ToLowerInvariant() == vmOut.AvailabilitySetReference.ReferenceUri.ToLowerInvariant()); ValidatePlan(vm.Plan, vmOut.Plan); // TODO: it's null somtimes. //Assert.NotNull(vmOut.Properties.Id); //Assert.True(expectedVMReferenceId.ToLowerInvariant() == vmOut.Properties.Id.ToLowerInvariant()); }