2
2
using System . Linq ;
3
3
using Moq ;
4
4
using NUnit . Framework ;
5
+ using Rubberduck . Inspections ;
5
6
using Rubberduck . Parsing . Inspections . Abstract ;
6
7
using Rubberduck . Parsing . Inspections . Resources ;
7
8
using Rubberduck . Settings ;
@@ -18,7 +19,10 @@ public void SettingsForFoundInspectionsAreAddedToDefaultSettings()
18
19
{
19
20
var inspectionMock = new Mock < IInspection > ( ) ;
20
21
inspectionMock . Setup ( inspection => inspection . Name ) . Returns ( inspectionMock . Object . GetType ( ) . FullName ) ;
21
- var configProvider = new CodeInspectionConfigProvider ( null , new [ ] { inspectionMock . Object } ) ;
22
+ var inspectionProviderMock = new Mock < IInspectionProvider > ( ) ;
23
+ inspectionProviderMock . Setup ( provider => provider . Inspections ) . Returns ( new [ ] { inspectionMock . Object } ) ;
24
+
25
+ var configProvider = new CodeInspectionConfigProvider ( null , inspectionProviderMock . Object ) ;
22
26
23
27
var defaults = configProvider . CreateDefaults ( ) ;
24
28
@@ -31,17 +35,19 @@ public void UserSettingsAreCombinedWithDefaultSettings()
31
35
{
32
36
var inspectionMock = new Mock < IInspection > ( ) ;
33
37
inspectionMock . Setup ( inspection => inspection . Name ) . Returns ( "Foo" ) ;
38
+ var inspectionProviderMock = new Mock < IInspectionProvider > ( ) ;
39
+ inspectionProviderMock . Setup ( provider => provider . Inspections ) . Returns ( new [ ] { inspectionMock . Object } ) ;
34
40
35
41
var userSetting = new CodeInspectionSetting ( "Foo" , CodeInspectionType . CodeQualityIssues ) ;
36
42
var userSettings = new CodeInspectionSettings
37
43
{
38
- CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } )
44
+ CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } )
39
45
} ;
40
46
41
47
var persisterMock = new Mock < IPersistanceService < CodeInspectionSettings > > ( ) ;
42
48
persisterMock . Setup ( persister => persister . Load ( It . IsAny < CodeInspectionSettings > ( ) ) ) . Returns ( userSettings ) ;
43
49
44
- var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , new [ ] { inspectionMock . Object } ) ;
50
+ var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , inspectionProviderMock . Object ) ;
45
51
46
52
var settings = configProvider . Create ( ) . CodeInspections ;
47
53
var defaultSettings = configProvider . CreateDefaults ( ) . CodeInspections ;
@@ -54,56 +60,38 @@ public void UserSettingsAreCombinedWithDefaultSettings()
54
60
[ Test ]
55
61
public void UserSettingsAreNotDuplicatedWithDefaultSettings ( )
56
62
{
57
- var defaultSettings = new CodeInspectionConfigProvider ( null , Enumerable . Empty < IInspection > ( ) ) . CreateDefaults ( ) . CodeInspections ;
63
+ var inspectionProviderMock = new Mock < IInspectionProvider > ( ) ;
64
+ inspectionProviderMock . Setup ( provider => provider . Inspections ) . Returns ( Enumerable . Empty < IInspection > ( ) ) ;
65
+
66
+ var defaultSettings = new CodeInspectionConfigProvider ( null , inspectionProviderMock . Object ) . CreateDefaults ( ) . CodeInspections ;
58
67
var defaultSetting = defaultSettings . First ( ) ;
59
68
60
69
var userSetting = new CodeInspectionSetting ( defaultSetting . Name , defaultSetting . InspectionType ) ;
61
70
var userSettings = new CodeInspectionSettings
62
71
{
63
- CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } )
72
+ CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } )
64
73
} ;
65
74
66
75
var persisterMock = new Mock < IPersistanceService < CodeInspectionSettings > > ( ) ;
67
76
persisterMock . Setup ( persister => persister . Load ( It . IsAny < CodeInspectionSettings > ( ) ) ) . Returns ( userSettings ) ;
68
77
69
- var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , Enumerable . Empty < IInspection > ( ) ) ;
78
+ var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , inspectionProviderMock . Object ) ;
70
79
71
80
var settings = configProvider . Create ( ) . CodeInspections ;
72
81
73
82
Assert . AreEqual ( defaultSettings . Count , settings . Count ) ;
74
83
Assert . Contains ( userSetting , settings . ToArray ( ) ) ;
75
84
}
76
85
77
- [ Category ( "Settings" ) ]
78
- [ Test ]
79
- public void UserSettingsInspectionTypeIsAssignedFromDefaultSetting ( )
80
- {
81
- var defaultSettings = new CodeInspectionConfigProvider ( null , Enumerable . Empty < IInspection > ( ) ) . CreateDefaults ( ) . CodeInspections ;
82
- var defaultSetting = defaultSettings . First ( ) ;
83
- defaultSetting . InspectionType = CodeInspectionType . CodeQualityIssues ;
84
-
85
- var userSetting = new CodeInspectionSetting ( defaultSetting . Name , CodeInspectionType . LanguageOpportunities ) ;
86
- var userSettings = new CodeInspectionSettings
87
- {
88
- CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } )
89
- } ;
90
-
91
- var persisterMock = new Mock < IPersistanceService < CodeInspectionSettings > > ( ) ;
92
- persisterMock . Setup ( persister => persister . Load ( It . IsAny < CodeInspectionSettings > ( ) ) ) . Returns ( userSettings ) ;
93
-
94
- var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , Enumerable . Empty < IInspection > ( ) ) ;
95
-
96
- var setting = configProvider . Create ( ) . CodeInspections . First ( inspection => inspection . Equals ( userSetting ) ) ;
97
-
98
- Assert . AreEqual ( CodeInspectionType . CodeQualityIssues , setting . InspectionType ) ;
99
- }
100
86
101
87
[ Category ( "Settings" ) ]
102
88
[ Test ]
103
89
public void UserSettingForUnknownInspectionIsIgnored ( )
104
90
{
105
91
var inspectionMock = new Mock < IInspection > ( ) ;
106
92
inspectionMock . Setup ( inspection => inspection . Name ) . Returns ( "Foo" ) ;
93
+ var inspectionProviderMock = new Mock < IInspectionProvider > ( ) ;
94
+ inspectionProviderMock . Setup ( provider => provider . Inspections ) . Returns ( new [ ] { inspectionMock . Object } ) ;
107
95
108
96
var userSetting = new CodeInspectionSetting ( "Bar" , CodeInspectionType . CodeQualityIssues ) ;
109
97
var userSettings = new CodeInspectionSettings
@@ -114,34 +102,11 @@ public void UserSettingForUnknownInspectionIsIgnored()
114
102
var persisterMock = new Mock < IPersistanceService < CodeInspectionSettings > > ( ) ;
115
103
persisterMock . Setup ( persister => persister . Load ( It . IsAny < CodeInspectionSettings > ( ) ) ) . Returns ( userSettings ) ;
116
104
117
- var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , new [ ] { inspectionMock . Object } ) ;
105
+ var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , inspectionProviderMock . Object ) ;
118
106
119
107
var settings = configProvider . Create ( ) . CodeInspections ;
120
108
121
109
Assert . IsNull ( settings . FirstOrDefault ( setting => setting . Name == "Bar" ) ) ;
122
110
}
123
-
124
- [ Category ( "Settings" ) ]
125
- [ Test ]
126
- public void DuplicateUserSettingIsIgnored ( )
127
- {
128
- var inspectionMock = new Mock < IInspection > ( ) ;
129
- inspectionMock . Setup ( inspection => inspection . Name ) . Returns ( "Foo" ) ;
130
-
131
- var userSetting = new CodeInspectionSetting ( "Foo" , CodeInspectionType . CodeQualityIssues ) ;
132
- var userSettings = new CodeInspectionSettings
133
- {
134
- CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } )
135
- } ;
136
-
137
- var persisterMock = new Mock < IPersistanceService < CodeInspectionSettings > > ( ) ;
138
- persisterMock . Setup ( persister => persister . Load ( It . IsAny < CodeInspectionSettings > ( ) ) ) . Returns ( userSettings ) ;
139
-
140
- var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , new [ ] { inspectionMock . Object , inspectionMock . Object } ) ;
141
-
142
- var settings = configProvider . Create ( ) . CodeInspections ;
143
-
144
- Assert . AreEqual ( 1 , settings . Count ( setting => setting . Name == "Foo" ) ) ;
145
- }
146
111
}
147
112
}
0 commit comments