1
+ // Copyright © 2011 - Present RealDimensions Software, LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ //
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ namespace chocolatey . tests . integration
17
+ {
18
+ using System . Collections . Generic ;
19
+ using System . IO ;
20
+ using System . Reflection ;
21
+ using NuGet ;
22
+ using SimpleInjector ;
23
+ using chocolatey . infrastructure . app . builders ;
24
+ using chocolatey . infrastructure . app . configuration ;
25
+ using chocolatey . infrastructure . app . domain ;
26
+ using chocolatey . infrastructure . filesystem ;
27
+ using chocolatey . infrastructure . services ;
28
+
29
+ public class Scenario
30
+ {
31
+ private static readonly DotNetFileSystem _fileSystem = new DotNetFileSystem ( ) ;
32
+
33
+ public static string get_top_level ( )
34
+ {
35
+ return _fileSystem . get_directory_name ( Assembly . GetExecutingAssembly ( ) . Location ) ;
36
+ }
37
+
38
+ private static ChocolateyConfiguration baseline_configuration ( )
39
+ {
40
+ var config = NUnitSetup . Container . GetInstance < ChocolateyConfiguration > ( ) ;
41
+
42
+ config . AcceptLicense = true ;
43
+ config . AllowMultipleVersions = false ;
44
+ config . AllowUnofficialBuild = true ;
45
+ config . CacheLocation = _fileSystem . get_full_path ( _fileSystem . combine_paths ( get_top_level ( ) , "cache" ) ) ;
46
+ config . CommandExecutionTimeoutSeconds = 2700 ;
47
+ config . ContainsLegacyPackageInstalls = false ;
48
+ config . Force = false ;
49
+ config . ForceDependencies = false ;
50
+ config . ForceX86 = false ;
51
+ config . HelpRequested = false ;
52
+ config . IgnoreDependencies = false ;
53
+ config . InstallArguments = string . Empty ;
54
+ config . Noop = false ;
55
+ config . OverrideArguments = false ;
56
+ config . Prerelease = false ;
57
+ config . PromptForConfirmation = false ;
58
+ config . RegularOuptut = true ;
59
+ config . SkipPackageInstallProvider = false ;
60
+ config . Sources = _fileSystem . get_full_path ( _fileSystem . combine_paths ( get_top_level ( ) , "packages" ) ) ;
61
+ config . Version = null ;
62
+
63
+ return config ;
64
+ }
65
+
66
+ private static ChocolateyConfiguration set_baseline ( )
67
+ {
68
+ var config = baseline_configuration ( ) ;
69
+
70
+ string packagesInstallPath = _fileSystem . combine_paths ( get_top_level ( ) , "lib" ) ;
71
+
72
+ _fileSystem . delete_directory_if_exists ( config . CacheLocation , recursive : true ) ;
73
+ _fileSystem . delete_directory_if_exists ( config . Sources , recursive : true ) ;
74
+ _fileSystem . delete_directory_if_exists ( packagesInstallPath , recursive : true ) ;
75
+
76
+ _fileSystem . create_directory ( config . CacheLocation ) ;
77
+ _fileSystem . create_directory ( config . Sources ) ;
78
+ _fileSystem . create_directory ( packagesInstallPath ) ;
79
+
80
+ return config ;
81
+ }
82
+
83
+ private static void set_files_in_source ( ChocolateyConfiguration config , string pattern )
84
+ {
85
+ var contextDir = _fileSystem . combine_paths ( get_top_level ( ) , "context" ) ;
86
+ var files = _fileSystem . get_files ( contextDir , pattern , SearchOption . AllDirectories ) ;
87
+
88
+ foreach ( var file in files . or_empty_list_if_null ( ) )
89
+ {
90
+ _fileSystem . copy_file ( _fileSystem . get_full_path ( file ) , _fileSystem . combine_paths ( config . Sources , _fileSystem . get_file_name ( file ) ) , overwriteExisting : true ) ;
91
+ }
92
+ }
93
+
94
+ public static ChocolateyConfiguration install ( )
95
+ {
96
+ var config = set_baseline ( ) ;
97
+ config . CommandName = CommandNameType . install . to_string ( ) ;
98
+ config . PackageNames = config . Input = "installpackage" ;
99
+
100
+ set_files_in_source ( config , config . Input + "*" + Constants . PackageExtension ) ;
101
+ set_files_in_source ( config , "badpackage*" + Constants . PackageExtension ) ;
102
+
103
+ return config ;
104
+ }
105
+
106
+ public static ChocolateyConfiguration upgrade ( )
107
+ {
108
+ var config = set_baseline ( ) ;
109
+ config . CommandName = CommandNameType . install . to_string ( ) ;
110
+ config . PackageNames = config . Input = "upgradepackage" ;
111
+
112
+ //arrange for upgrade
113
+
114
+
115
+ return config ;
116
+ }
117
+ }
118
+ }
0 commit comments