public void FullRefresh() { _systemIcons.Clear(); _imageList.Images.Clear(); Nodes.Clear(); _imageList.Images.Add(Properties.Resources.FolderOpenIcon); _systemIcons.Add(FolderOpenIcon, 0); _imageList.Images.Add(Properties.Resources.FolderCloseIcon); _systemIcons.Add(FolderCloseIcon, 0); _imageList.Images.Add(Properties.Resources.LocalIcon); _systemIcons.Add(LocalServerIcon, 0); _imageList.Images.Add(Properties.Resources.RemoteIcon); _systemIcons.Add(RemoteServerIcon, 0); _imageList.Images.Add(Properties.Resources.ConsoleIcon); _systemIcons.Add(ConsoleIcon, 0); _imageList.Images.Add(Properties.Resources.MenuSettings); foreach (string server in Directory.GetDirectories(Utils.Main.ServersDirectory)) { if (File.Exists(server + Path.DirectorySeparatorChar + "ServerCreatorData.xml")) //old file name { File.Move(server + Path.DirectorySeparatorChar + "ServerCreatorData.xml", server + Path.DirectorySeparatorChar + "ServerManagerData.xml"); } if (File.Exists(server + Path.DirectorySeparatorChar + "ServerManagerData.xml")) { Data.Server serverData = Data.Server.Deserialize(server + Path.DirectorySeparatorChar + "ServerManagerData.xml"); ServerNode node = new ServerNode(this, new DirectoryInfo(server), serverData); node.Expand(); } } foreach (string importedServer in Directory.GetFiles(Utils.Main.ImportDirectory)) { Data.Server serverData = Data.Server.Deserialize(importedServer); ServerNode node = new ServerNode(this, new DirectoryInfo(serverData.path), serverData); node.Expand(); } foreach (string remoteServer in Directory.GetDirectories(Utils.Main.RemoteDirectory)) { if (File.Exists(remoteServer + Path.DirectorySeparatorChar + "MainData.xml")) { Data.RemoteServer serverData = Data.RemoteServer.Deserialize(remoteServer + Path.DirectorySeparatorChar + "MainData.xml"); RemoteServerNode node = new RemoteServerNode(this, serverData); } } }
public void ServerNodeChildrenShouldIncludeFoldersAndDatabases() { // Given a server with 1 database SetupAndRegisterTestConnectionService(); ServiceProvider.RegisterSingleService(new ObjectExplorerService()); string dbName = "DB1"; Mock <NamedSmoObject> smoObjectMock = new Mock <NamedSmoObject>(); smoObjectMock.SetupGet(s => s.Name).Returns(dbName); Mock <SqlDatabaseQuerier> querierMock = new Mock <SqlDatabaseQuerier>(); querierMock.Setup(q => q.Query(It.IsAny <SmoQueryContext>(), It.IsAny <string>(), false, It.IsAny <IEnumerable <string> >())) .Returns(smoObjectMock.Object.SingleItemAsEnumerable()); ServiceProvider.Register <SmoQuerier>(() => new[] { querierMock.Object }); Server smoServer = new Server(new ServerConnection(new SqlConnection(fakeConnectionString))); ServerNode node = SetupServerNodeWithServer(smoServer); // When I populate its children IList <TreeNode> children = node.Expand(); // Then I expect it to contain server-level folders Assert.Equal(3, children.Count); VerifyTreeNode <FolderNode>(children[0], "Folder", SR.SchemaHierarchy_Databases); VerifyTreeNode <FolderNode>(children[1], "Folder", SR.SchemaHierarchy_Security); VerifyTreeNode <FolderNode>(children[2], "Folder", SR.SchemaHierarchy_ServerObjects); // And the database is contained under it TreeNode databases = children[0]; IList <TreeNode> dbChildren = databases.Expand(); Assert.Equal(2, dbChildren.Count); Assert.Equal(SR.SchemaHierarchy_SystemDatabases, dbChildren[0].NodeValue); TreeNode dbNode = dbChildren[1]; Assert.Equal(dbName, dbNode.NodeValue); Assert.Equal(dbName, dbNode.Label); Assert.False(dbNode.IsAlwaysLeaf); // Note: would like to verify Database in the context, but cannot since it's a Sealed class and isn't easily mockable }