Loading...
Searching...
No Matches
TestGAMSWorkspaceInfo.cs
1using System;
2using System.IO;
3using GAMS;
4using NLog;
5using NUnit.Framework;
6
7namespace GamsApiTests
8{
9 [TestFixture]
11 {
12 static readonly String PROPERTIES_FILE = "test.properties";
13 static String workingDir;
14 static GAMSWorkspaceInfo wsInfo = null;
15 static GAMSWorkspace ws = null;
16 static Logger logger = LogManager.GetCurrentClassLogger();
17
18
19 [OneTimeSetUp]
20 public static void OneTimeSetup()
21 {
22 logger.Debug("TestGAMSWorkspaceInfo | OneTimeSetup");
23 workingDir = HouseKeeper.gamsAbsoluteWorkingDir;
24 HouseKeeper.initializeTestFrom(PROPERTIES_FILE, "TestGAMSWorkspaceInfo");
25 logger.Debug("TestGAMSWorkspaceInfo | oneTimeSetup");
26 }
27
28
29 [SetUp]
30 public void setUp()
31 {
32 wsInfo = new GAMSWorkspaceInfo();
33 ws = null;
34 }
35
36 void testExpectedWorkspaceInfoResult(String workdir, String sysdir, DebugLevel debug)
37 {
38 if (workdir == null)
39 {
40 Assert.IsNull(wsInfo.WorkingDirectory, "expect a NULL working directory.");
41 }
42 else
43 {
44 Assert.IsNotNull(wsInfo.WorkingDirectory, "does not expect a NULL wsInfo.getWorkingDirectory().");
45 Assert.AreEqual(workdir, wsInfo.WorkingDirectory, "expect as [" + workdir + "] as wsInfo.getWorkingDirectory().");
46
47 }
48
49 if (sysdir == null)
50 {
51 Assert.IsNull(wsInfo.SystemDirectory, "expect a NULL system directory.");
52 }
53 else
54 {
55 Assert.IsNotNull(wsInfo.SystemDirectory, "does not expect a NULL wsInfo.getSystemDirectory().");
56 Assert.AreEqual(sysdir, wsInfo.SystemDirectory, "expect as [" + sysdir + "] as wsInfo.getWorkingDirectory().");
57 }
58
60 //if (debug == null)
61 //{
62 // Assert.IsNull("expect a NULL debug level.", ws.getDebugLevel());
63 //}
64 //else
65 //{
66 // Assert.IsNotNull("does not expect a NULL wsInfo.getDebugLevel().", wsInfo.getDebugLevel());
67 // Assert.AreEqual("expect [" + GAMSGlobals.DebugLevel.KEEP_FILES.name() + "].",
68 // debug.value(), wsInfo.getDebugLevel().value());
69 //}
70 }
71
72 [Test]
73 public void testDefaultGAMSWorkspaceInfo()
74 {
75 logger.Debug("Entering TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
76 // when
77 wsInfo = new GAMSWorkspaceInfo();
78 // then
79 testExpectedWorkspaceInfoResult(null, null, DebugLevel.Off);
80 logger.Debug("Exiting TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
81 }
82
83 [Test]
84 public void testGAMSWorkspaceInfo_systemDirectory()
85 {
86 logger.Debug("Entering TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
87 // when
88 wsInfo = new GAMSWorkspaceInfo();
89 wsInfo.SystemDirectory = HouseKeeper.gamsAbsoluteSystemDir;
90 // then
91 testExpectedWorkspaceInfoResult(null, HouseKeeper.gamsAbsoluteSystemDir, DebugLevel.Off);
92 logger.Debug("Exiting TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
93 }
94
95
96 [Test]
97 public void testGAMSWorkspaceInfo_workingDirectory()
98 {
99 logger.Debug("Entering TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
100 // when
101 wsInfo.WorkingDirectory = HouseKeeper.gamsWorkingDir;
102 // then
103 testExpectedWorkspaceInfoResult(HouseKeeper.gamsWorkingDir, null, DebugLevel.Off);
104 logger.Debug("Exiting TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
105 }
106
107
108 [Test]
109 public void testGAMSWorkspaceInfo_specifyWorkingDirectory()
110 {
111 logger.Debug("Entering TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
112 // when
113 string workingDir = Path.Combine(HouseKeeper.gamsAbsoluteWorkingDir, "testGAMSWorkspaceInfo_specifyWorkingDirectory");
114 Assert.False(Directory.Exists(workingDir), "does not expect existence of [" + Path.GetFullPath(workingDir) + "]");
115 wsInfo.WorkingDirectory = Path.GetFullPath(workingDir);
116 // then
117 testExpectedWorkspaceInfoResult(Path.GetFullPath(workingDir), null, DebugLevel.Off);
118 logger.Debug("Exiting TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
119 }
120
121 [Test]
122 public void testGAMSWorkspaceInfo_emptyStringWorkingDirectory1()
123 {
124 logger.Debug("Entering TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
125 // when
126 var workingDir = String.Empty;
127 var parentDir = Path.GetDirectoryName(HouseKeeper.gamsWorkingDir);
128
130 Assert.AreEqual(workingDir, parentDir, "expect an empty string refers to current (in this case parent) directory. ");
131 wsInfo.WorkingDirectory = workingDir;
132 // then
133 testExpectedWorkspaceInfoResult(workingDir, null, DebugLevel.Off);
134 logger.Debug("Exiting TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
135 }
136
137 [Test]
138 public void testGAMSWorkspaceInfo_emptyStringWorkingDirectory2()
139 {
140 logger.Debug("Entering TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
141 // when
142 wsInfo.WorkingDirectory = String.Empty;
143 // then
144 testExpectedWorkspaceInfoResult(String.Empty, null, DebugLevel.Off);
145 logger.Debug("Exiting TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
146 }
147
148
149 [Test]
150 public void testGAMSWorkspaceInfo_userWorkingDirectory()
151 {
152 logger.Debug("Entering TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
153 // when
154 wsInfo.WorkingDirectory = Environment.CurrentDirectory;
155 // then
156 string workingDir = Environment.CurrentDirectory;
157 testExpectedWorkspaceInfoResult(Path.GetFullPath(new DirectoryInfo(workingDir).FullName), null, DebugLevel.Off);
158 logger.Debug("Exiting TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
159 }
160
161 [Test]
162 public void testGAMSWorkspaceInfo_emptyStringSystemDirectory()
163 {
164 logger.Debug("Entering TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
165 // when
166 wsInfo.SystemDirectory = String.Empty;
167 // then
168 testExpectedWorkspaceInfoResult(null, String.Empty, DebugLevel.Off);
169 logger.Debug("Exiting TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
170 }
171
172 [Test]
173 public void testGAMSWorkspaceInfo_keepFiles()
174 {
175 logger.Debug("Entering TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
176 // when
177 wsInfo.Debug = DebugLevel.KeepFiles;
178 // then
179 testExpectedWorkspaceInfoResult(null, null, DebugLevel.KeepFiles);
180 logger.Debug("Exiting TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
181 }
182
183 [Test]
184 public void testGAMSWorkspaceInfo()
185 {
186 logger.Debug("Entering TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
187 // when
188 wsInfo = new GAMSWorkspaceInfo(HouseKeeper.gamsWorkingDir,
189 HouseKeeper.gamsAbsoluteSystemDir,
190 DebugLevel.KeepFiles);
191 // then
192 testExpectedWorkspaceInfoResult(HouseKeeper.gamsWorkingDir,
193 HouseKeeper.gamsAbsoluteSystemDir,
194 DebugLevel.KeepFiles);
195 logger.Debug("Exiting TestGAMSWorkspaceInfo | testDefaultGAMSWorkspaceInfo");
196 }
197 }
198}
static void initializeTestFrom(String filename, String subdir)
initialize class properties from fileName and prepare directory subdir
Definition: HouseKeeper.cs:114