@@ -44,22 +44,22 @@ private void CacheElement(UnitTestElementId id, IUnitTestElement element)
4444
4545 #region Classes
4646
47- public XunitTestClassElement GetOrCreateTestClass ( PersistentProjectId projectId , IClrTypeName typeName ,
47+ public XunitTestClassElement GetOrCreateTestClass ( IProject project , IClrTypeName typeName ,
4848 string assemblyLocation ,
4949 OneToSetMap < string , string > traits )
5050 {
5151 var id = typeName . FullName ;
52- return GetOrCreateTestClass ( id , projectId , typeName , assemblyLocation , traits ) ;
52+ return GetOrCreateTestClass ( id , project , typeName , assemblyLocation , traits ) ;
5353 }
5454
55- public XunitTestClassElement GetOrCreateTestClass ( string id , PersistentProjectId projectId ,
55+ public XunitTestClassElement GetOrCreateTestClass ( string id , IProject project ,
5656 IClrTypeName typeName ,
5757 string assemblyLocation ,
5858 OneToSetMap < string , string > traits )
5959 {
6060 lock ( lockObject )
6161 {
62- var elementId = services . CreateId ( projectId , id ) ;
62+ var elementId = services . CreateId ( project , id ) ;
6363 var element = GetElementById < XunitTestClassElement > ( elementId ) ;
6464 if ( element == null )
6565 {
@@ -84,7 +84,7 @@ public XunitTestClassElement GetOrCreateTestClass(string id, PersistentProjectId
8484
8585 #region Methods
8686
87- public XunitTestMethodElement GetOrCreateTestMethod ( PersistentProjectId projectId ,
87+ public XunitTestMethodElement GetOrCreateTestMethod ( IProject project ,
8888 XunitTestClassElement testClassElement ,
8989 IClrTypeName typeName , string methodName , string skipReason ,
9090 OneToSetMap < string , string > traits , bool isDynamic )
@@ -95,19 +95,19 @@ public XunitTestMethodElement GetOrCreateTestMethod(PersistentProjectId projectI
9595
9696 var id = string . Format ( "{0}.{1}{2}" , testClassElement . Id . Id , baseTypeName , methodName ) ;
9797
98- return GetOrCreateTestMethod ( id , projectId , testClassElement , typeName , methodName , skipReason , traits ,
98+ return GetOrCreateTestMethod ( id , project , testClassElement , typeName , methodName , skipReason , traits ,
9999 isDynamic ) ;
100100 }
101101
102- public XunitTestMethodElement GetOrCreateTestMethod ( string id , PersistentProjectId projectId ,
102+ public XunitTestMethodElement GetOrCreateTestMethod ( string id , IProject project ,
103103 XunitTestClassElement testClassElement ,
104104 IClrTypeName typeName , string methodName ,
105105 string skipReason , OneToSetMap < string , string > traits ,
106106 bool isDynamic )
107107 {
108108 lock ( lockObject )
109109 {
110- var elementId = services . CreateId ( projectId , id ) ;
110+ var elementId = services . CreateId ( project , id ) ;
111111 var element = GetElementById < XunitTestMethodElement > ( elementId ) ;
112112 if ( element == null )
113113 {
@@ -129,11 +129,11 @@ public XunitTestMethodElement GetOrCreateTestMethod(string id, PersistentProject
129129
130130 #region Theories
131131
132- public XunitTestTheoryElement GetOrCreateTestTheory ( PersistentProjectId projectId , XunitTestMethodElement methodElement ,
132+ public XunitTestTheoryElement GetOrCreateTestTheory ( IProject project , XunitTestMethodElement methodElement ,
133133 string name )
134134 {
135135 var id = string . Format ( "{0}.{1}" , methodElement . Id . Id , GetTestTheoryShortName ( name , methodElement ) ) ;
136- return GetOrCreateTestTheory ( id , projectId , methodElement , name ) ;
136+ return GetOrCreateTestTheory ( id , project , methodElement , name ) ;
137137 }
138138
139139 private static string GetTestTheoryShortName ( string theoryName , XunitTestMethodElement methodElement )
@@ -144,12 +144,12 @@ private static string GetTestTheoryShortName(string theoryName, XunitTestMethodE
144144 return DisplayNameUtil . Escape ( name ) ;
145145 }
146146
147- public XunitTestTheoryElement GetOrCreateTestTheory ( string id , PersistentProjectId projectId ,
147+ public XunitTestTheoryElement GetOrCreateTestTheory ( string id , IProject project ,
148148 XunitTestMethodElement methodElement , string name )
149149 {
150150 lock ( lockObject )
151151 {
152- var elementId = services . CreateId ( projectId , id ) ;
152+ var elementId = services . CreateId ( project , id ) ;
153153 var element = GetElementById < XunitTestTheoryElement > ( elementId ) ;
154154 if ( element == null )
155155 {
@@ -162,20 +162,20 @@ public XunitTestTheoryElement GetOrCreateTestTheory(string id, PersistentProject
162162 element . State = UnitTestElementState . Valid ;
163163
164164 // Traits don't have their own categories, but can inherit from method and class
165- UpdateCategories ( element , new JetHashSet < string > ( ) ) ;
165+ UpdateCategories ( element , EmptyArray < UnitTestElementCategory > . Instance ) ;
166166
167167 return element ;
168168 }
169169 }
170170
171171 #endregion
172172
173- public XunitInheritedTestMethodContainerElement GetOrCreateInheritedTestMethodContainer ( PersistentProjectId projectId , IClrTypeName typeName , string methodName )
173+ public XunitInheritedTestMethodContainerElement GetOrCreateInheritedTestMethodContainer ( IProject project , IClrTypeName typeName , string methodName )
174174 {
175175 lock ( lockObject )
176176 {
177177 var id = typeName . FullName + "." + methodName ;
178- var elementId = services . CreateId ( projectId , id ) ;
178+ var elementId = services . CreateId ( project , id ) ;
179179
180180 var element = GetElementById < XunitInheritedTestMethodContainerElement > ( elementId ) ;
181181 if ( element == null )
@@ -194,30 +194,21 @@ private void UpdateCategories(XunitBaseElement element, OneToSetMap<string, stri
194194 UpdateCategories ( element , GetCategories ( traits ) ) ;
195195 }
196196
197- private void UpdateCategories ( XunitBaseElement element , JetHashSet < string > newCategories )
197+ private void UpdateCategories ( XunitBaseElement element , IEnumerable < UnitTestElementCategory > categories )
198198 {
199199 using ( UT . WriteLock ( ) )
200200 {
201201 lock ( lockObject )
202202 {
203- var existingCategories = element . Categories
204- . Where ( c => ! ReferenceEquals ( c , UnitTestElementCategory . UncategorizedCategory ) )
205- . ToHashSet ( c => c . Name ) ;
206- if ( element . Parent != null &&
207- ! ReferenceEquals ( element . Parent . Categories , UnitTestElementCategory . Uncategorized ) )
208- {
209- newCategories . AddRange ( element . Parent . Categories . Select ( c => c . Name ) ) ;
210- }
203+ var newCategories = categories . ToSet ( ) ;
204+ if ( element . Parent != null )
205+ newCategories . AddRange ( element . Parent . Categories ) ;
211206
212- var removedCategories = existingCategories . Where ( c => ! newCategories . Contains ( c ) ) . ToList ( ) ;
213-
214- if ( removedCategories . Any ( ) )
215- services . CategoryFactory . UnuseCategories ( removedCategories ) ;
216-
217- if ( newCategories . All ( c => existingCategories . Contains ( c ) ) && ! removedCategories . Any ( ) )
207+ var existingCategories = element . Categories . ToSet ( ) ;
208+ if ( newCategories . All ( c => existingCategories . Contains ( c ) ) && existingCategories . All ( c => newCategories . Contains ( c ) ) )
218209 return ;
219210
220- element . Categories = services . CategoryFactory . Create ( newCategories ) ;
211+ element . Categories = newCategories ;
221212
222213 // Notify ReSharper that the element has changed. We only need to do this for
223214 // categories, and not private data, as ReSharper caches categories
@@ -227,16 +218,16 @@ private void UpdateCategories(XunitBaseElement element, JetHashSet<string> newCa
227218 }
228219 }
229220
230- private JetHashSet < string > GetCategories ( OneToSetMap < string , string > traits )
221+ private IEnumerable < UnitTestElementCategory > GetCategories ( OneToSetMap < string , string > traits )
231222 {
232223 var categories = from key in traits . Keys
233- where ! key . IsNullOrEmpty ( ) && ! key . IsWhitespace ( )
234- from value in traits [ key ]
235- where ! value . IsNullOrEmpty ( ) && ! value . IsWhitespace ( )
236- select string . Compare ( key , "category" , StringComparison . InvariantCultureIgnoreCase ) != 0
237- ? string . Format ( "{0}[{1}]" , key . Trim ( ) , value . Trim ( ) )
238- : value ;
239- return categories . ToHashSet ( ) ;
224+ where ! key . IsNullOrEmpty ( ) && ! key . IsWhitespace ( )
225+ from value in traits [ key ]
226+ where ! value . IsNullOrEmpty ( ) && ! value . IsWhitespace ( )
227+ select string . Compare ( key , "category" , StringComparison . InvariantCultureIgnoreCase ) != 0
228+ ? string . Format ( "{0}[{1}]" , key . Trim ( ) , value . Trim ( ) )
229+ : value ;
230+ return services . CategoryFactory . Create ( categories ) ;
240231 }
241232 }
242233}
0 commit comments