|
| 1 | +using System; |
| 2 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 3 | +using System.Linq; |
| 4 | +using Rubberduck.Parsing.Symbols; |
| 5 | +using Rubberduck.VBEditor; |
| 6 | + |
| 7 | +namespace RubberduckTests.Symbols |
| 8 | +{ |
| 9 | + [TestClass] |
| 10 | + public class ProjectDeclarationTests |
| 11 | + { |
| 12 | + [TestMethod] |
| 13 | + public void ProjectsHaveDeclarationTypeProject() |
| 14 | + { |
| 15 | + var projectDeclaration = GetTestProject("testProject"); |
| 16 | + |
| 17 | + Assert.IsTrue(projectDeclaration.DeclarationType.HasFlag(DeclarationType.Project)); |
| 18 | + } |
| 19 | + |
| 20 | + private static ProjectDeclaration GetTestProject(string name) |
| 21 | + { |
| 22 | + var qualifiedProjectName = new QualifiedMemberName(StubQualifiedModuleName(), name); |
| 23 | + return new ProjectDeclaration(qualifiedProjectName, name, false); |
| 24 | + } |
| 25 | + |
| 26 | + private static QualifiedModuleName StubQualifiedModuleName() |
| 27 | + { |
| 28 | + return new QualifiedModuleName("dummy", "dummy", "dummy"); |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | + [TestMethod] |
| 33 | + public void ByDefaultProjectsReferenceNoOtherProjects() |
| 34 | + { |
| 35 | + var projectDeclaration = GetTestProject("testProject"); |
| 36 | + |
| 37 | + Assert.IsFalse(projectDeclaration.ProjectReferences.Any()); |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + [TestMethod] |
| 42 | + public void ProjectsReferencesReturnsTheReferencesAddedViaAddProjectReference() |
| 43 | + { |
| 44 | + var projectDeclaration = GetTestProject("testProject"); |
| 45 | + var projectId = "test"; |
| 46 | + var priority = 12; |
| 47 | + projectDeclaration.AddProjectReference(projectId, priority); |
| 48 | + var projectReference = projectDeclaration.ProjectReferences.Single(); |
| 49 | + |
| 50 | + Assert.IsTrue(projectReference.ReferencedProjectId == projectId && projectReference.Priority == priority); |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + [TestMethod] |
| 55 | + public void ProjectsReferencesIgnoresReferencesWithTheSameIDAsOneAlreadyPresent() |
| 56 | + { |
| 57 | + var projectDeclaration = GetTestProject("testProject"); |
| 58 | + var projectId = "test"; |
| 59 | + var priority = 12; |
| 60 | + var otherPriority = 1; |
| 61 | + projectDeclaration.AddProjectReference(projectId, priority); |
| 62 | + projectDeclaration.AddProjectReference(projectId, otherPriority); |
| 63 | + var projectReference = projectDeclaration.ProjectReferences.Single(); |
| 64 | + |
| 65 | + Assert.IsTrue(projectReference.ReferencedProjectId == projectId && projectReference.Priority == priority); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + [TestMethod] |
| 70 | + public void ProjectsReferencesReturnsTheReferencesInOrderOfAscendingPriority() |
| 71 | + { |
| 72 | + var projectDeclaration = GetTestProject("testProject"); |
| 73 | + var projectId = "test"; |
| 74 | + var priority = 12; |
| 75 | + var otherProjectId = "testtest"; |
| 76 | + var otherPriority = 1; |
| 77 | + var yetAnotherProjectId = "testtesttest"; |
| 78 | + var yetAnotherPriority = 5; |
| 79 | + projectDeclaration.AddProjectReference(projectId, priority); |
| 80 | + projectDeclaration.AddProjectReference(otherProjectId, otherPriority); |
| 81 | + projectDeclaration.AddProjectReference(yetAnotherProjectId, yetAnotherPriority); |
| 82 | + var lowerPriorityProjectReference = projectDeclaration.ProjectReferences.First(); |
| 83 | + |
| 84 | + Assert.IsTrue(lowerPriorityProjectReference.ReferencedProjectId == otherProjectId && lowerPriorityProjectReference.Priority == otherPriority); |
| 85 | + } |
| 86 | + |
| 87 | + } |
| 88 | +} |
0 commit comments