1
- using Moq ;
1
+ using System . Collections . Generic ;
2
+ using System . Linq ;
3
+ using Moq ;
2
4
using NUnit . Framework ;
3
5
using Rubberduck . Parsing . Inspections . Abstract ;
6
+ using Rubberduck . Parsing . Inspections . Resources ;
4
7
using Rubberduck . Settings ;
8
+ using Rubberduck . SettingsProvider ;
5
9
6
10
namespace RubberduckTests . Settings
7
11
{
@@ -20,5 +24,39 @@ public void SettingsForFoundInspectionsAreAddedToDefaultSettings()
20
24
21
25
Assert . NotNull ( defaults . GetSetting ( inspectionMock . Object . GetType ( ) ) ) ;
22
26
}
27
+
28
+ [ Category ( "Settings" ) ]
29
+ [ Test ]
30
+ public void UserSettingsAreCombinedWithDefaultSettings ( )
31
+ {
32
+ var userSetting = new CodeInspectionSetting ( "Foo" , CodeInspectionType . CodeQualityIssues ) ;
33
+ var userSettings = new CodeInspectionSettings { CodeInspections = new HashSet < CodeInspectionSetting > ( new [ ] { userSetting } ) } ;
34
+ var persisterMock = new Mock < IPersistanceService < CodeInspectionSettings > > ( ) ;
35
+ persisterMock . Setup ( persister => persister . Load ( It . IsAny < CodeInspectionSettings > ( ) ) ) . Returns ( userSettings ) ;
36
+ var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , Enumerable . Empty < IInspection > ( ) ) ;
37
+
38
+ var settings = configProvider . Create ( ) . CodeInspections ;
39
+ var defaultSettings = configProvider . CreateDefaults ( ) . CodeInspections ;
40
+
41
+ Assert . Contains ( userSetting , settings . ToArray ( ) ) ;
42
+ Assert . IsTrue ( defaultSettings . All ( s => settings . Contains ( s ) ) ) ;
43
+ }
44
+
45
+ [ Category ( "Settings" ) ]
46
+ [ Test ]
47
+ public void UserSettingsAreNotDuplicatedWithDefaultSettings ( )
48
+ {
49
+ 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 } ) } ;
52
+ var persisterMock = new Mock < IPersistanceService < CodeInspectionSettings > > ( ) ;
53
+ persisterMock . Setup ( persister => persister . Load ( It . IsAny < CodeInspectionSettings > ( ) ) ) . Returns ( userSettings ) ;
54
+ var configProvider = new CodeInspectionConfigProvider ( persisterMock . Object , Enumerable . Empty < IInspection > ( ) ) ;
55
+
56
+ var settings = configProvider . Create ( ) . CodeInspections ;
57
+
58
+ Assert . AreEqual ( defaultSettings . Count , settings . Count ) ;
59
+ Assert . Contains ( userSetting , settings . ToArray ( ) ) ;
60
+ }
23
61
}
24
62
}
0 commit comments