Skip to content

Commit 62de30a

Browse files
committed
More tests for declarations types and for AccessibilityCheck
1 parent a2580e1 commit 62de30a

File tree

5 files changed

+295
-4
lines changed

5 files changed

+295
-4
lines changed

RubberduckTests/RubberduckTests.csproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,19 @@
8989
<Compile Include="Commands\RefactorCommandTests.cs" />
9090
<Compile Include="Commands\IndentCommandTests.cs" />
9191
<Compile Include="Commands\UnitTestCommandTests.cs" />
92-
<Compile Include="ComponentTypeExtensionTests.cs" />
92+
<Compile Include="Symbols\AccessibilityCheckTests.cs" />
93+
<Compile Include="Symbols\ClassModuleDeclarationTests.cs" />
94+
<Compile Include="Symbols\ProjectDeclarationTests.cs" />
95+
<Compile Include="Symbols\ConstantDeclarationTests.cs" />
96+
<Compile Include="Symbols\ProceduralModuleDeclarationTests.cs" />
97+
<Compile Include="Symbols\ParameterDeclarationTests.cs" />
98+
<Compile Include="Symbols\ExternalProcedureDeclarationTests.cs" />
99+
<Compile Include="Symbols\SubroutineDeclarationTests.cs" />
100+
<Compile Include="Symbols\FunctionDeclarationTests.cs" />
101+
<Compile Include="Symbols\PropertyGetDeclarationTests.cs" />
102+
<Compile Include="Symbols\PropertyLetDeclarationTests.cs" />
103+
<Compile Include="Symbols\PropertySetDeclarationTests.cs" />
104+
<Compile Include="UnitTesting\ComponentTypeExtensionTests.cs" />
93105
<Compile Include="ConfigurationTests.cs" />
94106
<Compile Include="Commands\FindAllImplementationsTests.cs" />
95107
<Compile Include="Commands\FindAllReferencesTests.cs" />

RubberduckTests/Symbols/AccessibilityCheckTests.cs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ public void PrivateEnumsAreNotAccessibleFromOtherModules()
462462

463463

464464
[TestMethod]
465-
public void PublicEnumsInNonPrivateProceduralModulesAreNotAcessibleFromOtherProjects()
465+
public void PublicEnumsInNonPrivateProceduralModulesAreAccessibleFromOtherProjects()
466466
{
467467
var calleeProjectDeclatation = GetTestProject("callee_test_project");
468468
var calleeModuleDeclatation = GetTestProceduralModule(calleeProjectDeclatation, "callee_test_Module");
@@ -476,7 +476,7 @@ public void PublicEnumsInNonPrivateProceduralModulesAreNotAcessibleFromOtherProj
476476

477477

478478
[TestMethod]
479-
public void GlobalEnumsInNonPrivateProceduralModulesAreNotAcessibleFromOtherProjects()
479+
public void GlobalEnumsInNonPrivateProceduralModulesAreAccessibleFromOtherProjects()
480480
{
481481
var calleeProjectDeclatation = GetTestProject("callee_test_project");
482482
var calleeModuleDeclatation = GetTestProceduralModule(calleeProjectDeclatation, "callee_test_Module");
@@ -490,7 +490,7 @@ public void GlobalEnumsInNonPrivateProceduralModulesAreNotAcessibleFromOtherProj
490490

491491

492492
[TestMethod]
493-
public void ImplicitelyScopedEnumsInNonPrivateProceduralModulesAreNotAcessibleFromOtherProjects()
493+
public void ImplicitelyScopedEnumsInNonPrivateProceduralModulesAreAccessibleFromOtherProjects()
494494
{
495495
var calleeProjectDeclatation = GetTestProject("callee_test_project");
496496
var calleeModuleDeclatation = GetTestProceduralModule(calleeProjectDeclatation, "callee_test_Module");
@@ -503,6 +503,48 @@ public void ImplicitelyScopedEnumsInNonPrivateProceduralModulesAreNotAcessibleFr
503503
}
504504

505505

506+
[TestMethod]
507+
public void PublicEnumsInExposedClassesAreNotAccessibleFromOtherProjects()
508+
{
509+
var calleeProjectDeclatation = GetTestProject("callee_test_project");
510+
var calleeModuleDeclaration = GetTestClassModule(calleeProjectDeclatation, "callee_test_Module", true);
511+
var enumDeclarartion = GetTestEnum(calleeModuleDeclaration, "x", Accessibility.Public);
512+
var callingProjectDeclatation = GetTestProject("calling_test_project");
513+
var callingModuleDeclatation = GetTestClassModule(callingProjectDeclatation, "calling_test_Module");
514+
var functionDeclaration = GetTestFunction(callingModuleDeclatation, "callingFoo", Accessibility.Private);
515+
516+
Assert.IsTrue(AccessibilityCheck.IsAccessible(callingProjectDeclatation, callingModuleDeclatation, functionDeclaration, enumDeclarartion));
517+
}
518+
519+
520+
[TestMethod]
521+
public void GlobalEnumsInExposedClassesAreAccessibleFromOtherProjects()
522+
{
523+
var calleeProjectDeclatation = GetTestProject("callee_test_project");
524+
var calleeModuleDeclaration = GetTestClassModule(calleeProjectDeclatation, "callee_test_Module", true);
525+
var enumDeclarartion = GetTestEnum(calleeModuleDeclaration, "x", Accessibility.Global);
526+
var callingProjectDeclatation = GetTestProject("calling_test_project");
527+
var callingModuleDeclatation = GetTestClassModule(callingProjectDeclatation, "calling_test_Module");
528+
var functionDeclaration = GetTestFunction(callingModuleDeclatation, "callingFoo", Accessibility.Private);
529+
530+
Assert.IsTrue(AccessibilityCheck.IsAccessible(callingProjectDeclatation, callingModuleDeclatation, functionDeclaration, enumDeclarartion));
531+
}
532+
533+
534+
[TestMethod]
535+
public void ImplicitelyScopedEnumsInExposedClassesAreAcessibleFromOtherProjects()
536+
{
537+
var calleeProjectDeclatation = GetTestProject("callee_test_project");
538+
var calleeModuleDeclaration = GetTestClassModule(calleeProjectDeclatation, "callee_test_Module", true);
539+
var enumDeclarartion = GetTestEnum(calleeModuleDeclaration, "x", Accessibility.Implicit);
540+
var callingProjectDeclatation = GetTestProject("calling_test_project");
541+
var callingModuleDeclatation = GetTestClassModule(callingProjectDeclatation, "calling_test_Module");
542+
var functionDeclaration = GetTestFunction(callingModuleDeclatation, "callingFoo", Accessibility.Private);
543+
544+
Assert.IsTrue(AccessibilityCheck.IsAccessible(callingProjectDeclatation, callingModuleDeclatation, functionDeclaration, enumDeclarartion));
545+
}
546+
547+
506548

507549
//user type tests
508550

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using System.Linq;
4+
using Rubberduck.Parsing.Symbols;
5+
using Rubberduck.VBEditor;
6+
using Rubberduck.Parsing.VBA;
7+
8+
namespace RubberduckTests.Symbols
9+
{
10+
[TestClass]
11+
public class PropertyGetDeclarationTests
12+
{
13+
[TestMethod]
14+
public void PropertyGetsHaveDeclarationTypePropertyGet()
15+
{
16+
var propertyGet = GetTestPropertyGet("test", null);
17+
18+
Assert.IsTrue(propertyGet.DeclarationType.HasFlag(DeclarationType.PropertyGet));
19+
}
20+
21+
private static PropertyGetDeclaration GetTestPropertyGet(string name, Attributes attributes)
22+
{
23+
var qualifiedName = new QualifiedMemberName(StubQualifiedModuleName(), name);
24+
return new PropertyGetDeclaration(qualifiedName, null, null, "test", null, "test", Accessibility.Implicit, null, Selection.Home, false, false, null, attributes);
25+
}
26+
27+
private static QualifiedModuleName StubQualifiedModuleName()
28+
{
29+
return new QualifiedModuleName("dummy", "dummy", "dummy");
30+
}
31+
32+
33+
[TestMethod]
34+
public void ByDefaultPropertyGetsDoNotHaveParameters()
35+
{
36+
var propertyGet = GetTestPropertyGet("test", null);
37+
38+
Assert.IsFalse(propertyGet.Parameters.Any());
39+
}
40+
41+
42+
[TestMethod]
43+
public void ParametersReturnsTheParametersAddedViaAddParameters()
44+
{
45+
var propertyGet = GetTestPropertyGet("test", null);
46+
var inputParameter = GetTestParameter("testParameter", false, false, false);
47+
propertyGet.AddParameter(inputParameter);
48+
var returnedParameter = propertyGet.Parameters.SingleOrDefault();
49+
50+
Assert.AreEqual(returnedParameter, inputParameter);
51+
}
52+
53+
private static ParameterDeclaration GetTestParameter(string name, bool isOptional, bool isByRef, bool isParamArray)
54+
{
55+
var qualifiedParameterName = new QualifiedMemberName(StubQualifiedModuleName(), name);
56+
return new ParameterDeclaration(qualifiedParameterName, null, "test", null, "test", isOptional, isByRef, false, isParamArray);
57+
}
58+
59+
60+
[TestMethod]
61+
public void ByDefaultPropertyGetsAreNotDefaultMembers()
62+
{
63+
var propertyGet = GetTestPropertyGet("test", null);
64+
65+
Assert.IsFalse(propertyGet.IsDefaultMember);
66+
}
67+
68+
69+
[TestMethod]
70+
public void PropertyGetsAreDefaultMembersIfTheyHaveTheDefaultMemberAttribute()
71+
{
72+
var attributes = new Attributes();
73+
attributes.AddDefaultMemberAttribute("test");
74+
var propertyGet = GetTestPropertyGet("test", attributes);
75+
76+
Assert.IsTrue(propertyGet.IsDefaultMember);
77+
}
78+
}
79+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using System.Linq;
4+
using Rubberduck.Parsing.Symbols;
5+
using Rubberduck.VBEditor;
6+
using Rubberduck.Parsing.VBA;
7+
8+
namespace RubberduckTests.Symbols
9+
{
10+
[TestClass]
11+
public class PropertyLetDeclarationTests
12+
{
13+
[TestMethod]
14+
public void PropertyLetsHaveDeclarationTypePropertyLet()
15+
{
16+
var propertyLet = GetTestPropertyLet("test", null);
17+
18+
Assert.IsTrue(propertyLet.DeclarationType.HasFlag(DeclarationType.PropertyLet));
19+
}
20+
21+
private static PropertyLetDeclaration GetTestPropertyLet(string name, Attributes attributes)
22+
{
23+
var qualifiedName = new QualifiedMemberName(StubQualifiedModuleName(), name);
24+
return new PropertyLetDeclaration(qualifiedName, null, null, "test", Accessibility.Implicit, null, Selection.Home, false, null, attributes);
25+
}
26+
27+
private static QualifiedModuleName StubQualifiedModuleName()
28+
{
29+
return new QualifiedModuleName("dummy", "dummy", "dummy");
30+
}
31+
32+
33+
[TestMethod]
34+
public void ByDefaultPropertyLetsDoNotHaveParameters()
35+
{
36+
var propertyLet = GetTestPropertyLet("test", null);
37+
38+
Assert.IsFalse(propertyLet.Parameters.Any());
39+
}
40+
41+
42+
[TestMethod]
43+
public void ParametersReturnsTheParametersAddedViaAddParameters()
44+
{
45+
var propertyLet = GetTestPropertyLet("test", null);
46+
var inputParameter = GetTestParameter("testParameter", false, false, false);
47+
propertyLet.AddParameter(inputParameter);
48+
var returnedParameter = propertyLet.Parameters.SingleOrDefault();
49+
50+
Assert.AreEqual(returnedParameter, inputParameter);
51+
}
52+
53+
private static ParameterDeclaration GetTestParameter(string name, bool isOptional, bool isByRef, bool isParamArray)
54+
{
55+
var qualifiedParameterName = new QualifiedMemberName(StubQualifiedModuleName(), name);
56+
return new ParameterDeclaration(qualifiedParameterName, null, "test", null, "test", isOptional, isByRef, false, isParamArray);
57+
}
58+
59+
60+
[TestMethod]
61+
public void ByDefaultPropertyLetsAreNotDefaultMembers()
62+
{
63+
var propertyLet = GetTestPropertyLet("test", null);
64+
65+
Assert.IsFalse(propertyLet.IsDefaultMember);
66+
}
67+
68+
69+
[TestMethod]
70+
public void PropertyLetsAreDefaultMembersIfTheyHaveTheDefaultMemberAttribute()
71+
{
72+
var attributes = new Attributes();
73+
attributes.AddDefaultMemberAttribute("test");
74+
var propertyLet = GetTestPropertyLet("test", attributes);
75+
76+
Assert.IsTrue(propertyLet.IsDefaultMember);
77+
}
78+
}
79+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using System.Linq;
4+
using Rubberduck.Parsing.Symbols;
5+
using Rubberduck.VBEditor;
6+
using Rubberduck.Parsing.VBA;
7+
8+
namespace RubberduckTests.Symbols
9+
{
10+
[TestClass]
11+
public class PropertySetDeclarationTests
12+
{
13+
[TestMethod]
14+
public void PropertySetsHaveDeclarationTypePropertySet()
15+
{
16+
var propertySet = GetTestPropertySet("test", null);
17+
18+
Assert.IsTrue(propertySet.DeclarationType.HasFlag(DeclarationType.PropertySet));
19+
}
20+
21+
private static PropertySetDeclaration GetTestPropertySet(string name, Attributes attributes)
22+
{
23+
var qualifiedName = new QualifiedMemberName(StubQualifiedModuleName(), name);
24+
return new PropertySetDeclaration(qualifiedName, null, null, "test", Accessibility.Implicit, null, Selection.Home, false, null, attributes);
25+
}
26+
27+
private static QualifiedModuleName StubQualifiedModuleName()
28+
{
29+
return new QualifiedModuleName("dummy", "dummy", "dummy");
30+
}
31+
32+
33+
[TestMethod]
34+
public void ByDefaultPropertySetsDoNotHaveParameters()
35+
{
36+
var propertySet = GetTestPropertySet("test", null);
37+
38+
Assert.IsFalse(propertySet.Parameters.Any());
39+
}
40+
41+
42+
[TestMethod]
43+
public void ParametersReturnsTheParametersAddedViaAddParameters()
44+
{
45+
var propertySet = GetTestPropertySet("test", null);
46+
var inputParameter = GetTestParameter("testParameter", false, false, false);
47+
propertySet.AddParameter(inputParameter);
48+
var returnedParameter = propertySet.Parameters.SingleOrDefault();
49+
50+
Assert.AreEqual(returnedParameter, inputParameter);
51+
}
52+
53+
private static ParameterDeclaration GetTestParameter(string name, bool isOptional, bool isByRef, bool isParamArray)
54+
{
55+
var qualifiedParameterName = new QualifiedMemberName(StubQualifiedModuleName(), name);
56+
return new ParameterDeclaration(qualifiedParameterName, null, "test", null, "test", isOptional, isByRef, false, isParamArray);
57+
}
58+
59+
60+
[TestMethod]
61+
public void ByDefaultPropertySetsAreNotDefaultMembers()
62+
{
63+
var propertySet = GetTestPropertySet("test", null);
64+
65+
Assert.IsFalse(propertySet.IsDefaultMember);
66+
}
67+
68+
69+
[TestMethod]
70+
public void PropertySetsAreDefaultMembersIfTheyHaveTheDefaultMemberAttribute()
71+
{
72+
var attributes = new Attributes();
73+
attributes.AddDefaultMemberAttribute("test");
74+
var propertySet = GetTestPropertySet("test", attributes);
75+
76+
Assert.IsTrue(propertySet.IsDefaultMember);
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)