public async Task Run(TestContext context) { var url = this.Url; var db = this.Database; var remoteConn = context.Connection as IRemoteConnection; if (string.IsNullOrEmpty(url) && remoteConn != null) { url = remoteConn.Url.ToString(); } if (string.IsNullOrEmpty(db)) { db = context.Connection.Database; } var prefs = new ConnectionPreferences(); prefs.Headers.UserAgent = "InnovatorAdmin UnitTest"; var conn = await Factory.GetConnection(url, prefs, true).ToTask(); ICredentials cred; switch (this.Type) { case CredentialType.Anonymous: cred = new AnonymousCredentials(db); break; case CredentialType.Windows: cred = new WindowsCredentials(db); break; default: if (_password.IsNullOrEmpty()) { cred = context.CredentialStore.OfType <ExplicitCredentials>() .FirstOrDefault(c => string.Equals(c.Database, db) && string.Equals(c.Username, this.UserName)); } else { cred = new ExplicitCredentials(db, this.UserName, _password); } break; } if (cred == null) { throw new InvalidOperationException("Could not create credentials for this login type"); } await conn.Login(cred, true).ToTask(); context.PushConnection(conn); }
/// <summary> /// Code for executing the command /// </summary> public async Task Run(TestContext context) { var conn = context.PopConnection(); if (context.Connection == null) { context.PushConnection(conn); } else { var remote = conn as IRemoteConnection; if (remote != null) remote.Logout(false, true); } }
/// <summary> /// Code for executing the command /// </summary> public async Task Run(TestContext context) { var conn = context.PopConnection(); if (context.Connection == null) { context.PushConnection(conn); } else { var remote = conn as IRemoteConnection; if (remote != null) { remote.Logout(false, true); } } }
public async Task Run(TestContext context) { var url = this.Url; var db = this.Database; var remoteConn = context.Connection as IRemoteConnection; if (string.IsNullOrEmpty(url) && remoteConn != null) url = remoteConn.Url.ToString(); if (string.IsNullOrEmpty(db)) db = context.Connection.Database; var prefs = new ConnectionPreferences() { UserAgent = "InnovatorAdmin UnitTest" }; var conn = await Factory.GetConnection(url, prefs, true).ToTask(); ICredentials cred; switch (this.Type) { case CredentialType.Anonymous: cred = new AnonymousCredentials(db); break; case CredentialType.Windows: cred = new WindowsCredentials(db); break; default: if (_password.IsNullOrEmpty()) { cred = context.CredentialStore.OfType<ExplicitCredentials>() .FirstOrDefault(c => string.Equals(c.Database, db) && string.Equals(c.Username, this.UserName)); } else { cred = new ExplicitCredentials(db, this.UserName, _password); } break; } if (cred == null) throw new InvalidOperationException("Could not create credentials for this login type"); await conn.Login(cred, true).ToTask(); context.PushConnection(conn); }