public void TestConnectionSummaryComparer() { var summary1 = new ConnectionSummary() { ServerName = "localhost", DatabaseName = "master", UserName = "******" }; var summary2 = new ConnectionSummary() { ServerName = "localhost", DatabaseName = "master", UserName = "******" }; var comparer = new ConnectionSummaryComparer(); Assert.True(comparer.Equals(summary1, summary2)); summary2.DatabaseName = "tempdb"; Assert.False(comparer.Equals(summary1, summary2)); Assert.False(comparer.Equals(null, summary2)); Assert.False(summary1.GetHashCode() == summary2.GetHashCode()); }
/// <summary> /// Change the database context of a connection. /// </summary> /// <param name="ownerUri">URI of the owner of the connection</param> /// <param name="newDatabaseName">Name of the database to change the connection to</param> public void ChangeConnectionDatabaseContext(string ownerUri, string newDatabaseName) { ConnectionInfo info; if (TryFindConnection(ownerUri, out info)) { try { if (info.SqlConnection.State == ConnectionState.Open) { info.SqlConnection.ChangeDatabase(newDatabaseName); } info.ConnectionDetails.DatabaseName = newDatabaseName; // Fire a connection changed event ConnectionChangedParams parameters = new ConnectionChangedParams(); ConnectionSummary summary = info.ConnectionDetails; parameters.Connection = summary.Clone(); parameters.OwnerUri = ownerUri; ServiceHost.SendEvent(ConnectionChangedNotification.Type, parameters); } catch (Exception e) { Logger.Write( LogLevel.Error, string.Format( "Exception caught while trying to change database context to [{0}] for OwnerUri [{1}]. Exception:{2}", newDatabaseName, ownerUri, e.ToString()) ); } } }
public void TestConnectionSummaryComparerHashCode(bool objectNull, string serverName, string databaseName, string userName) { // Given a connection summary and comparer object ConnectionSummary summary = null; if (!objectNull) { summary = new ConnectionSummary() { ServerName = serverName, DatabaseName = databaseName, UserName = userName }; } ConnectionSummaryComparer comparer = new ConnectionSummaryComparer(); // If I compute a hash code int hashCode = comparer.GetHashCode(summary); if (summary == null || (serverName == null && databaseName == null && userName == null)) { // Then I expect it to be 31 for a null summary Assert.Equal(31, hashCode); } else { // And not 31 otherwise Assert.NotEqual(31, hashCode); } }
/// <summary> /// Remove a reference to an autocomplete cache from a URI. If /// it is the last URI connected to a particular connection, /// then remove the cache. /// </summary> public async Task RemoveAutoCompleteCacheUriReference(ConnectionSummary summary, string ownerUri) { RemoveScriptParseInfo(ownerUri); // currently this method is disabled, but we need to reimplement now that the // implementation of the 'cache' has changed. await Task.FromResult(0); }
/// <summary> /// Create a copy of a ConnectionSummary object /// </summary> public static ConnectionSummary Clone(this ConnectionSummary summary) { return(new ConnectionSummary() { ServerName = summary.ServerName, DatabaseName = summary.DatabaseName, UserName = summary.UserName }); }
public ServerNode(ConnectionCompleteParams connInfo, IMultiServiceProvider serviceProvider, ServerConnection serverConnection) : base() { Validate.IsNotNull(nameof(connInfo), connInfo); Validate.IsNotNull("connInfo.ConnectionSummary", connInfo.ConnectionSummary); Validate.IsNotNull(nameof(serviceProvider), serviceProvider); this.connectionSummary = connInfo.ConnectionSummary; this.serverInfo = connInfo.ServerInfo; this.sqlServerType = ServerVersionHelper.CalculateServerType(this.serverInfo); this.context = new Lazy <SmoQueryContext>(() => CreateContext(serviceProvider)); this.serverConnection = serverConnection; NodeValue = connectionSummary.ServerName; IsAlwaysLeaf = false; NodeType = NodeTypes.Server.ToString(); NodeTypeId = NodeTypes.Server; Label = GetConnectionLabel(); }
public void ServerNodeLabelShouldIgnoreUserNameIfEmptyOrNull() { // Given no username set ConnectionSummary integratedAuthSummary = new ConnectionSummary() { DatabaseName = defaultConnectionDetails.DatabaseName, ServerName = defaultConnectionDetails.ServerName, UserName = null }; ConnectionCompleteParams connParams = new ConnectionCompleteParams() { ConnectionSummary = integratedAuthSummary, ServerInfo = defaultServerInfo, OwnerUri = defaultOwnerUri }; // When querying label string label = new ServerNode(connParams, ServiceProvider, serverConnection).Label; // Then only server name and version shown string expectedLabel = defaultConnectionDetails.ServerName + " (SQL Server " + defaultServerInfo.ServerVersion + ")"; Assert.Equal(expectedLabel, label); }