public void RecursiveFindByNameIgnoreCase() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); MockVSHierarchy project1 = new MockVSHierarchy("Project1.project"); hierarchy.AddProject(project1); string child1 = "Child1"; project1.AddChild(child1); MockVSHierarchy project2 = new MockVSHierarchy("Project2.project"); hierarchy.AddProject(project2); string child2 = "ChIlD2.cd"; project2.AddChild(child2); string child3 = "ChildThree3"; project2.AddChild(child3); string child4 = "Child4NotAdded"; HierarchyNode node = new HierarchyNode(solution); Assert.IsNull(node.FindByName(child1)); Assert.IsNull(node.FindByName(child2)); Assert.IsNull(node.FindByName(child3)); Assert.IsNull(node.FindByName(child4)); Assert.IsNotNull(node.RecursiveFindByName(child1.ToLowerInvariant())); Assert.IsNotNull(node.RecursiveFindByName(child2.ToUpperInvariant())); Assert.IsNotNull(node.RecursiveFindByName(CodeIdentifier.MakeCamel(child3))); Assert.IsNull(node.RecursiveFindByName(child4)); }
public void CreateVsSolution() { root = new MockVSHierarchy(); vsSolution = new MockVsSolution(root); project = new MockVSHierarchy("Project.project"); root.AddProject(project); }
public void RecursiveFindByName() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); MockVSHierarchy project1 = new MockVSHierarchy("Project1.project"); hierarchy.AddProject(project1); string child1 = "Child1"; project1.AddChild(child1); MockVSHierarchy project2 = new MockVSHierarchy("Project2.project"); hierarchy.AddProject(project2); string child2 = "Child2"; project2.AddChild(child2); string child3 = "Child3"; project2.AddChild(child3); string child4 = "Child4"; HierarchyNode node = new HierarchyNode(solution); Assert.IsNull(node.FindByName(child1)); Assert.IsNull(node.FindByName(child2)); Assert.IsNull(node.FindByName(child3)); Assert.IsNull(node.FindByName(child4)); Assert.IsNotNull(node.RecursiveFindByName(child1)); Assert.IsNotNull(node.RecursiveFindByName(child2)); Assert.IsNotNull(node.RecursiveFindByName(child3)); Assert.IsNull(node.RecursiveFindByName(child4)); }
public void TestHasProperty() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); HierarchyNode slnNode = new HierarchyNode(solution); Assert.IsFalse(slnNode.HasIconIndex); }
public void TestGetObject() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); HierarchyNode slnNode = new HierarchyNode(solution); Assert.AreSame(hierarchy, slnNode.GetObject <MockVSHierarchy>()); }
public void NamePropertySetCorrectly() { string name = "MyName"; MockVSHierarchy hierarchy = new MockVSHierarchy(name, Guid.NewGuid()); MockVsSolution solution = new MockVsSolution(hierarchy); HierarchyNode node = new HierarchyNode(solution); Assert.AreEqual <string>(name, node.Name); }
public void FindOrCreateSolutionFolder() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); HierarchyNode node = new HierarchyNode(solution); string folderName = "SlnItems"; HierarchyNode folder = node.FindOrCreateSolutionFolder(folderName); Assert.IsNotNull(folder); Assert.AreEqual <string>(folderName, folder.Name); }
public void TestFileHasIcon() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); string docName = "Doc1.doc"; hierarchy.AddChild(docName); HierarchyNode slnNode = new HierarchyNode(solution); HierarchyNode node = slnNode.FindByName(docName); Assert.IsNotNull(node.Icon); }
public void TestHasChildrenChanges() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); HierarchyNode slnNode = new HierarchyNode(solution); Assert.IsFalse(slnNode.HasChildren); string docName = "Doc1.doc"; hierarchy.AddChild(docName); Assert.IsTrue(slnNode.HasChildren); }
public void ForEachWalksAllChildren() { int children = 3; MockVSHierarchy hierarchy = new MockVSHierarchy(children); MockVsSolution solution = new MockVsSolution(hierarchy); HierarchyNode node = new HierarchyNode(solution); int i = 0; node.ForEach(delegate(HierarchyNode child) { i++; }); Assert.AreEqual(children, i, "Incorrect number of nodes walked"); }
public void ShouldReturnTypeGuidForSolutionFile() { MockVSHierarchy root = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(root); string childName = "Child1.txt"; root.AddChild(childName); HierarchyNode slnNode = new HierarchyNode(solution); HierarchyNode childNode = slnNode.FindByName(childName); Assert.AreEqual <Guid>(VSConstants.GUID_ItemType_PhysicalFile, childNode.TypeGuid); }
public void ShouldReturnTypeGuidForSolutionFolder() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); MockVSHierarchy project = new MockVSHierarchy("Project4.project"); project.TypeGuid = VSConstants.GUID_ItemType_VirtualFolder; hierarchy.AddProject(project); HierarchyNode slnNode = new HierarchyNode(solution); HierarchyNode prjNode = slnNode.FindByName("Project4.project"); Assert.AreEqual <Guid>(VSConstants.GUID_ItemType_VirtualFolder, prjNode.TypeGuid); }
public void EnumerationWalking() { int children = 3; MockVSHierarchy hierarchy = new MockVSHierarchy(children); MockVsSolution solution = new MockVsSolution(hierarchy); HierarchyNode node = new HierarchyNode(solution); int i = 0; foreach (HierarchyNode child in node.Children) { ++i; } Assert.AreEqual <int>(children, i, "Invalid number of children"); }
public void RemoveItem() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); MockVSHierarchy project = new MockVSHierarchy("Project3.project"); hierarchy.AddProject(project); ProjectNode projectNode = new ProjectNode(solution, project.GUID); string itemName = "item1"; HierarchyNode node = projectNode.AddItem(itemName); Assert.IsNotNull(projectNode.FindByName(itemName)); node.Remove(); Assert.IsNull(projectNode.FindByName(itemName)); }
public void TestArtifactIsGenerated() { MockServiceProvider serviceProvider = new MockServiceProvider(); MockVSHierarchy root = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(root); MockVSHierarchy project = new MockVSHierarchy("Project1.project"); root.AddProject(project); serviceProvider.AddService(typeof(SVsSolution), solution); CodeGenerationService target = new CodeGenerationService(serviceProvider); MyArtifactLink validLink = new MyArtifactLink(project.GUID, "item1.cs"); Assert.IsFalse(target.IsArtifactAlreadyGenerated(validLink)); project.AddChild("item1.cs"); Assert.IsTrue(target.IsArtifactAlreadyGenerated(validLink)); }
public void EditValueWithNoFormsServiceThrows() { MockVSHierarchy root = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(root); MockServiceProvider serviceProvider = new MockServiceProvider(); serviceProvider.AddService(typeof(IVsSolution), solution); MockTypeDescriptorContext context = new MockTypeDescriptorContext(serviceProvider); string value = "Project1.txt"; MockVSHierarchy project = new MockVSHierarchy(value); root.AddProject(project); SolutionPickerEditor target = new SolutionPickerEditor(); target.EditValue(serviceProvider, null); }
public void ShouldAddProjectReferencestoVSProject() { MockVSHierarchy refProjHier = new MockVSHierarchy("refedproj.proj"); root.AddProject(refProjHier); Project projToRef = refProjHier.ExtObject as Project; Assert.IsNotNull(projToRef); ProjectNode projectNode = new ProjectNode(vsSolution, project.GUID); projectNode.AddProjectReference(refProjHier.GUID); Project projectFromMock = ((VSLangProj.VSProject)((MockEnvDTEProject)project.ExtObject).Object).References.Item(0).SourceProject; Assert.AreSame(projToRef, projectFromMock); }
public void RecursiveForEachWalksAllChildrenAndParent() { int children = 3; MockVSHierarchy hierarchy = new MockVSHierarchy(children); MockVsSolution solution = new MockVsSolution(hierarchy); HierarchyNode node = new HierarchyNode(solution); int i = 0; node.RecursiveForEach(delegate(HierarchyNode child) { Trace.WriteLine(child.Name); i++; }); Assert.AreEqual((children + 1), i, "Incorrect number of nodes walked"); }
public void TestRelativePath() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); MockVSHierarchy folder1 = new MockVSHierarchy("folder1"); hierarchy.AddProject(folder1); string child1 = "subFolder1"; folder1.AddChild(child1); HierarchyNode rootNode = new HierarchyNode(solution); HierarchyNode folder1Node = rootNode.FindByName("folder1"); HierarchyNode child1Node = folder1Node.FindByName(child1); Assert.IsNotNull(child1Node.RelativePath); Assert.AreEqual <string>(Path.Combine(Directory.GetCurrentDirectory(), child1), child1Node.RelativePath); }
private static ProjectNode GetTestProjectNode(string language) { MockVSHierarchy root = new MockVSHierarchy(); MockVsSolution vsSolution = new MockVsSolution(root); MockVSHierarchy project = new MockVSHierarchy("Project.project"); MockEnvDTEProject mockEnvDteProject = project.ExtObject as MockEnvDTEProject; if (mockEnvDteProject != null) { mockEnvDteProject.SetCodeModel(new MockCodeModel(language)); } root.AddProject(project); ProjectNode projectNode = new ProjectNode(vsSolution, project.GUID); return(projectNode); }
public void ShouldReturnProjectExtension() { MockVSHierarchy root = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(root); MockVSHierarchy project = new MockVSHierarchy("Project1.project"); root.AddProject(project); Assert.IsInstanceOfType(project.ExtObject, typeof(EnvDTE.Project)); TestableArtifactLink artifactLink = new TestableArtifactLink(); artifactLink.Container = project.GUID; artifactLink.ItemName = "TestItem"; artifactLink.Project = project.ExtObject as EnvDTE.Project; Assert.AreEqual <string>(".cs", artifactLink.DefaultExtension); }
private static CodeGenerationService CreateCodeGenerator(string itemPath, out MockVsRDT rdt) { string fullItemPath = Path.Combine(Directory.GetCurrentDirectory(), itemPath); string fullProjectPath = Path.Combine(Directory.GetCurrentDirectory(), "Project.project"); MockServiceProvider serviceProvider = new MockServiceProvider(); MockVSHierarchy vsHierarchy = new MockVSHierarchy(fullProjectPath); MockVsSolution vsSolution = new MockVsSolution(vsHierarchy); rdt = new MockVsRDT(fullItemPath, vsHierarchy, 0); MockVsTextManager textManager = new MockVsTextManager(); MockVsUIShellOpenDocument shellOpenDocument = new MockVsUIShellOpenDocument(); serviceProvider.AddService(typeof(SVsSolution), vsSolution); serviceProvider.AddService(typeof(IVsRunningDocumentTable), rdt); serviceProvider.AddService(typeof(VsTextManagerClass), textManager); serviceProvider.AddService(typeof(SVsUIShellOpenDocument), shellOpenDocument); return(new TestableCodeGenerationService(serviceProvider)); }
public void FindByName() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); string child1 = "Child1"; string child2 = "Child2"; string child3 = "Child3"; string child4 = "Child4"; hierarchy.AddChild(child1); hierarchy.AddChild(child2); hierarchy.AddChild(child3); HierarchyNode node = new HierarchyNode(solution); Assert.IsNotNull(node.FindByName(child1)); Assert.IsNotNull(node.FindByName(child2)); Assert.IsNotNull(node.FindByName(child3)); Assert.IsNull(node.FindByName(child4)); }
public void TestValidateDelete() { MockServiceProvider serviceProvider = new MockServiceProvider(); MockVSHierarchy root = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(root); MockVSHierarchy project = new MockVSHierarchy("Project1.project"); root.AddProject(project); serviceProvider.AddService(typeof(SVsSolution), solution); TestableCodeGenerationService target = new TestableCodeGenerationService(serviceProvider); MyArtifactLink validLink = new MyArtifactLink(project.GUID, "item1.cs"); HierarchyNode node = target.ValidateDelete(validLink); Assert.IsNull(node); Assert.AreEqual <int>(0, target.LogEntries.Count); project.AddChild("item1.cs"); node = target.ValidateDelete(validLink); Assert.IsNotNull(node); Assert.AreEqual <int>(1, target.LogEntries.Count); }
public MockMappingServiceProvider() { MockVSHierarchy root = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(root); root.AddProject(new MockVSHierarchy("Project1.project", guid1)); root.AddProject(new MockVSHierarchy("Project2.project", guid2)); root.AddProject(new MockVSHierarchy("Project3.project", guid3)); root.AddProject(new MockVSHierarchy("Project4.project", guid4)); AddService(typeof(SVsSolution), solution); string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ProjectMapping.xml"); MockVSHierarchy mappingFileHier = new MockVSHierarchy(filePath, guid5); AddService(typeof(IVsRunningDocumentTable), new MockVsRDT(filePath, mappingFileHier, VSConstants.VSITEMID_ROOT)); AddService(typeof(VsTextManagerClass), new MockVsTextManager()); AddService(typeof(IVsUIShellOpenDocument), new MockVsUIShellOpenDocument()); AddService(typeof(ILocalRegistry), new MockLocalRegistry()); AddService(typeof(IVsFileChangeEx), new MockFileChangeEx()); AddService(typeof(SVsFileChangeEx), new MockFileChangeEx()); }
public void ShouldFilterOutChildren() { MockVSHierarchy root = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(root); string childName = "Child1.txt"; root.AddChild(childName); string projectName = "Project1.project"; MockVSHierarchy project = new MockVSHierarchy(projectName); root.AddProject(project); HierarchyNode slnNode = new HierarchyNode(solution); HierarchyNode projectNode = new HierarchyNode(solution, project.GUID); HierarchyNode childNode = slnNode.FindByName(childName); OnlyProjectsFilter target = new OnlyProjectsFilter(); Assert.IsFalse(target.Filter(slnNode)); Assert.IsTrue(target.Filter(childNode)); Assert.IsFalse(target.Filter(projectNode)); }
public void TestValidate() { MockServiceProvider serviceProvider = new MockServiceProvider(); MockVSHierarchy root = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(root); MockVSHierarchy project = new MockVSHierarchy("Project1.project"); root.AddProject(project); serviceProvider.AddService(typeof(SVsSolution), solution); CodeGenerationService target = new CodeGenerationService(serviceProvider); MyArtifactLink validLink = new MyArtifactLink(project.GUID, "item1.cs"); Assert.IsTrue(target.IsValid(validLink)); MyArtifactLink invalidLink1 = new MyArtifactLink(Guid.NewGuid(), "item2.cs"); Assert.IsFalse(target.IsValid(invalidLink1)); MyArtifactLink invalidLink2 = new MyArtifactLink(project.GUID, "it:em3.cs"); Assert.IsFalse(target.IsValid(invalidLink2)); MyArtifactLink invalidLink3 = new MyArtifactLink(Guid.NewGuid(), "<item3.cs>"); Assert.IsFalse(target.IsValid(invalidLink3)); }
public void DeleteVsSolution() { project = null; vsSolution = null; root = null; }