@@ -29,11 +29,19 @@ public void SettingsForFoundInspectionsAreAddedToDefaultSettings()
29
29
[ Test ]
30
30
public void UserSettingsAreCombinedWithDefaultSettings ( )
31
31
{
32
+ var inspectionMock = new Mock < IInspection > ( ) ;
33
+ inspectionMock . Setup ( inspection => inspection . Name ) . Returns ( "Foo" ) ;
34
+
32
35
var userSetting = new CodeInspectionSetting ( "Foo" , CodeInspectionType . CodeQualityIssues ) ;
33
- var userSettings = new CodeInspectionSettings { CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } ) } ;
36
+ var userSettings = new CodeInspectionSettings
37
+ {
38
+ CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } )
39
+ } ;
40
+
34
41
var persisterMock = new Mock < IPersistanceService < CodeInspectionSettings > > ( ) ;
35
42
persisterMock . Setup ( persister => persister . Load ( It . IsAny < CodeInspectionSettings > ( ) ) ) . Returns ( userSettings ) ;
36
- var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , Enumerable . Empty < IInspection > ( ) ) ;
43
+
44
+ var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , new [ ] { inspectionMock . Object } ) ;
37
45
38
46
var settings = configProvider . Create ( ) . CodeInspections ;
39
47
var defaultSettings = configProvider . CreateDefaults ( ) . CodeInspections ;
@@ -47,16 +55,93 @@ public void UserSettingsAreCombinedWithDefaultSettings()
47
55
public void UserSettingsAreNotDuplicatedWithDefaultSettings ( )
48
56
{
49
57
var defaultSettings = new CodeInspectionConfigProvider ( null , Enumerable . Empty < IInspection > ( ) ) . CreateDefaults ( ) . CodeInspections ;
50
- var userSetting = defaultSettings . First ( ) ;
51
- var userSettings = new CodeInspectionSettings { CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } ) } ;
58
+ var defaultSetting = defaultSettings . First ( ) ;
59
+
60
+ var userSetting = new CodeInspectionSetting ( defaultSetting . Name , defaultSetting . InspectionType ) ;
61
+ var userSettings = new CodeInspectionSettings
62
+ {
63
+ CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } )
64
+ } ;
65
+
52
66
var persisterMock = new Mock < IPersistanceService < CodeInspectionSettings > > ( ) ;
53
67
persisterMock . Setup ( persister => persister . Load ( It . IsAny < CodeInspectionSettings > ( ) ) ) . Returns ( userSettings ) ;
68
+
54
69
var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , Enumerable . Empty < IInspection > ( ) ) ;
55
70
56
71
var settings = configProvider . Create ( ) . CodeInspections ;
57
72
58
73
Assert . AreEqual ( defaultSettings . Count , settings . Count ) ;
59
74
Assert . Contains ( userSetting , settings . ToArray ( ) ) ;
60
75
}
76
+
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
+
101
+ [ Category ( "Settings" ) ]
102
+ [ Test ]
103
+ public void UserSettingForUnknownInspectionIsIgnored ( )
104
+ {
105
+ var inspectionMock = new Mock < IInspection > ( ) ;
106
+ inspectionMock . Setup ( inspection => inspection . Name ) . Returns ( "Foo" ) ;
107
+
108
+ var userSetting = new CodeInspectionSetting ( "Bar" , CodeInspectionType . CodeQualityIssues ) ;
109
+ var userSettings = new CodeInspectionSettings
110
+ {
111
+ CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } )
112
+ } ;
113
+
114
+ var persisterMock = new Mock < IPersistanceService < CodeInspectionSettings > > ( ) ;
115
+ persisterMock . Setup ( persister => persister . Load ( It . IsAny < CodeInspectionSettings > ( ) ) ) . Returns ( userSettings ) ;
116
+
117
+ var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , new [ ] { inspectionMock . Object } ) ;
118
+
119
+ var settings = configProvider . Create ( ) . CodeInspections ;
120
+
121
+ Assert . IsNull ( settings . FirstOrDefault ( setting => setting . Name == "Bar" ) ) ;
122
+ }
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
+ }
61
146
}
62
147
}
0 commit comments