public void ThrowsWhenSettingPublicEnvironment() { Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>(); SetupConfirmation(commandRuntimeMock); var profile = new AzureRmProfile(); foreach (var env in AzureEnvironment.PublicEnvironments) { Assert.True(profile.GetEnvironment(env.Key) != null, string.Format("Key: {0} produces null environment. From profile {1}", env.Key, profile.ToString())); var cmdlet = new SetAzureRMEnvironmentCommand { CommandRuntime = commandRuntimeMock.Object, Name = env.Key, PublishSettingsFileUrl = "http://microsoft.com", DefaultProfile = profile }; var savedValue = env.Value.PublishSettingsFileUrl; cmdlet.InvokeBeginProcessing(); Assert.Throws <InvalidOperationException>(() => cmdlet.ExecuteCmdlet()); var environment = profile.GetEnvironment(env.Key); Assert.True(environment != null, string.Format("Key: {0} produces null environment. From profile {1}", env.Key, profile.ToString())); Assert.Equal(savedValue, environment.PublishSettingsFileUrl); Assert.NotEqual(cmdlet.PublishSettingsFileUrl, environment.PublishSettingsFileUrl); } }
public void ProfileSerializeDeserializeWorks() { var dataStore = new MockDataStore(); AzureSession.Instance.DataStore = dataStore; var profilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AzureSession.Instance.ProfileFile); var currentProfile = new AzureRmProfile(profilePath); var tenantId = Guid.NewGuid().ToString(); var environment = new AzureEnvironment { Name = "testCloud", ActiveDirectoryAuthority = "http://contoso.com" }; var account = new AzureAccount { Id = "*****@*****.**", Type = AzureAccount.AccountType.User, }; account.SetTenants(tenantId); var sub = new AzureSubscription { Id = new Guid().ToString(), Name = "Contoso Test Subscription", }; sub.SetAccount(account.Id); sub.SetEnvironment(environment.Name); sub.SetTenant(tenantId); var tenant = new AzureTenant { Id = tenantId, Directory = "contoso.com" }; currentProfile.DefaultContext = new AzureContext(sub, account, environment, tenant); currentProfile.EnvironmentTable[environment.Name] = environment; currentProfile.DefaultContext.TokenCache = new AzureTokenCache { CacheData = new byte[] { 1, 2, 3, 4, 5, 6, 8, 9, 0 } }; AzureRmProfile deserializedProfile; // Round-trip the exception: Serialize and de-serialize with a BinaryFormatter BinaryFormatter bf = new BinaryFormatter(); using (MemoryStream ms = new MemoryStream()) { // "Save" object state bf.Serialize(ms, currentProfile); // Re-use the same stream for de-serialization ms.Seek(0, 0); // Replace the original exception with de-serialized one deserializedProfile = (AzureRmProfile)bf.Deserialize(ms); } Assert.NotNull(deserializedProfile); var jCurrentProfile = currentProfile.ToString(); var jDeserializedProfile = deserializedProfile.ToString(); Assert.Equal(jCurrentProfile, jDeserializedProfile); }