示例#1
0
		public void TestWorkingDirectory()
		{
			string workingDirectory = Environment.CurrentDirectory;
			using (MockCommandLine command = new MockCommandLine())
			{
				CommandLineExternal external = new CommandLineExternal();
				external.WorkingDirectory = Path.GetPathRoot(workingDirectory);
				external.Command = command.ScriptFilename;

				Assert.IsTrue(external.IsValid, "Minimum parameters for Command Line External should be just the command itself");

				using (MockDicomPresentationImage image = new MockDicomPresentationImage())
				{
					external.Launch(image);

					Thread.Sleep(_processEndWaitDelay); // wait for the external to finish
					command.Refresh();

					Trace.WriteLine(string.Format("Command Execution Report"));
					Trace.WriteLine(command.ExecutionReport);

					AssertAreEqualIgnoreCase(external.Command, command.ExecutedCommand, "Wrong command was executed");
					AssertAreEqualIgnoreCase(external.WorkingDirectory, command.ExecutedWorkingDirectory, "Command executed in wrong working directory.");
				}
			}
		}
示例#2
0
		public void TestXmlSerialization()
		{
			var external1 = new CommandLineExternal {Name = "external1", Label = "Label1", Enabled = true, WindowStyle = WindowStyle.Normal, Command = @"C:\Temp\CommandA.cmd", WorkingDirectory = "$DIRECTORY$", Arguments = "", Username = "", Domain = "", AllowMultiValueFields = false};
			var external2 = new CommandLineExternal {Name = "external2", Label = "Label2", Enabled = false, WindowStyle = WindowStyle.Hidden, Command = @"\ComputerA\ShareB\CommandC.cmd", WorkingDirectory = "$DIRECTORY$", Arguments = "\"$FILENAMEONLY$\"", Username = "\u5305\u9752\u5929", Domain = "\u958B\u5C01\u5E9C", AllowMultiValueFields = true, MultiValueFieldSeparator = "\" \""};
			var external3 = new CommandLineExternal {Name = "external3"};
			var xmlData = ExternalCollection.Serialize(new ExternalCollection {external1, external2, external3});
			try
			{
				var xmlDoc = LoadXml(xmlData);

				AssertXmlNodeValue(typeof (CommandLineExternal).FullName, xmlDoc, "/ExternalCollection/External[1]/@Type", "Type should be namespace qualified type name");
				AssertXmlNodeValue("external1", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Name", "external1");
				AssertXmlNodeValue("Label1", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Label", "external1");
				AssertXmlNodeValue("true", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Enabled", "external1");
				AssertXmlNodeValue("Normal", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/WindowStyle", "external1");
				AssertXmlNodeValue("C:\\Temp\\CommandA.cmd", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Command", "external1");
				AssertXmlNodeValue("$DIRECTORY$", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/WorkingDirectory", "external1");
				AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Arguments", "external1");
				AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Username", "external1");
				AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/Domain", "external1");
				AssertXmlNodeValue("false", xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/AllowMultiValueFields", "external1");
				AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[1]/CommandLineExternal/MultiValueFieldSeparator", "external1");

				AssertXmlNodeValue(typeof (CommandLineExternal).FullName, xmlDoc, "/ExternalCollection/External[2]/@Type", "Type should be namespace qualified type name");
				AssertXmlNodeValue("external2", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Name", "external2");
				AssertXmlNodeValue("Label2", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Label", "external2");
				AssertXmlNodeValue("false", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Enabled", "external2");
				AssertXmlNodeValue("Hidden", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/WindowStyle", "external2");
				AssertXmlNodeValue("\\ComputerA\\ShareB\\CommandC.cmd", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Command", "external2");
				AssertXmlNodeValue("$DIRECTORY$", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/WorkingDirectory", "external2");
				AssertXmlNodeValue("\"$FILENAMEONLY$\"", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Arguments", "external2");
				AssertXmlNodeValue("\u5305\u9752\u5929", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Username", "external2");
				AssertXmlNodeValue("\u958B\u5C01\u5E9C", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/Domain", "external2");
				AssertXmlNodeValue("true", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/AllowMultiValueFields", "external2");
				AssertXmlNodeValue("\" \"", xmlDoc, "/ExternalCollection/External[2]/CommandLineExternal/MultiValueFieldSeparator", "external2");

				AssertXmlNodeValue(typeof (CommandLineExternal).FullName, xmlDoc, "/ExternalCollection/External[3]/@Type", "Type should be namespace qualified type name");
				AssertXmlNodeValue("external3", xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Name", "external3");
				AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Label", "external3");
				AssertXmlNodeValue("true", xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Enabled", "external3");
				AssertXmlNodeValue("Normal", xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/WindowStyle", "external3");
				AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Command", "external3");
				AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/WorkingDirectory", "external3");
				AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Arguments", "external3");
				AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Username", "external3");
				AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/Domain", "external3");
				AssertXmlNodeValue("true", xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/AllowMultiValueFields", "external3");
				AssertXmlNodeEmpty(xmlDoc, "/ExternalCollection/External[3]/CommandLineExternal/MultiValueFieldSeparator", "external3");
			}
			catch (Exception)
			{
				Trace.WriteLine("XML Data Dump");
				Trace.WriteLine(xmlData);
				throw;
			}
		}
		private static void AssertCommandLineExternal(CommandLineExternal expectedExternal, CommandLineExternal actualExternal, string message)
		{
			Assert.AreEqual(expectedExternal.Label, actualExternal.Label, "{0} (Wrong Label)", message);
			Assert.AreEqual(expectedExternal.Enabled, actualExternal.Enabled, "{0} (Wrong Enabled)", message);
			Assert.AreEqual(expectedExternal.WindowStyle, actualExternal.WindowStyle, "{0} (Wrong WindowStyle)", message);
			Assert.AreEqual(expectedExternal.Command, actualExternal.Command, "{0} (Wrong Command)", message);
			Assert.AreEqual(expectedExternal.WorkingDirectory, actualExternal.WorkingDirectory, "{0} (Wrong WorkingDirectory)", message);
			Assert.AreEqual(expectedExternal.Arguments, actualExternal.Arguments, "{0} (Wrong Arguments)", message);
			Assert.AreEqual(expectedExternal.Username, actualExternal.Username, "{0} (Wrong Username)", message);
			Assert.AreEqual(expectedExternal.Domain, actualExternal.Domain, "{0} (Wrong Domain)", message);
			Assert.AreEqual(expectedExternal.AllowMultiValueFields, actualExternal.AllowMultiValueFields, "{0} (Wrong AllowMultiValueFields)", message);
			Assert.AreEqual(expectedExternal.MultiValueFieldSeparator, actualExternal.MultiValueFieldSeparator, "{0} (Wrong MultiValueFieldSeparator)", message);
		}
		public void TestLegacyXmlDeserialization()
		{
			// if you encounter "unspecified errors" during compile, reformat the test data - csc has a maximum line/statement length (particularly important during pdb generation)
			const string testXml = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
			                       + "<ExternalCollection>\r\n"
			                       + "  <IExternal Concrete-Type=\"ClearCanvas.ImageViewer.Externals.General.CommandLineExternal, ClearCanvas.ImageViewer.Externals, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\"><![CDATA[<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
			                       + "<CommandLineExternal xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n"
			                       + "  <Name>external1</Name>\r\n"
			                       + "  <Label>Label1</Label>\r\n"
			                       + "  <Enabled>true</Enabled>\r\n"
			                       + "  <WindowStyle>Normal</WindowStyle>\r\n"
			                       + "  <Command>C:\\Temp\\CommandA.cmd</Command>\r\n"
			                       + "  <WorkingDirectory>$DIRECTORY$</WorkingDirectory>\r\n"
			                       + "  <Arguments />\r\n"
			                       + "  <Username />\r\n"
			                       + "  <Domain />\r\n"
			                       + "  <AllowMultiValueFields>false</AllowMultiValueFields>\r\n"
			                       + "</CommandLineExternal>]]></IExternal>\r\n"
			                       + "  <IExternal Concrete-Type=\"ClearCanvas.ImageViewer.Externals.General.CommandLineExternal, ClearCanvas.ImageViewer.Externals, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\"><![CDATA[<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
			                       + "<CommandLineExternal xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n"
			                       + "  <Name>external2</Name>\r\n"
			                       + "  <Label>Label2</Label>\r\n"
			                       + "  <Enabled>false</Enabled>\r\n"
			                       + "  <WindowStyle>Hidden</WindowStyle>\r\n"
			                       + "  <Command>\\ComputerA\\ShareB\\CommandC.cmd</Command>\r\n"
			                       + "  <WorkingDirectory>$DIRECTORY$</WorkingDirectory>"
			                       + "  <Arguments>\"$FILENAMEONLY$\"</Arguments>"
			                       + "  <Username>\u5305\u9752\u5929</Username>"
			                       + "  <Domain>\u958B\u5C01\u5E9C</Domain>"
			                       + "  <AllowMultiValueFields>true</AllowMultiValueFields>\r\n"
			                       + "  <MultiValueFieldSeparator>\" \"</MultiValueFieldSeparator>\r\n"
			                       + "</CommandLineExternal>]]></IExternal>\r\n"
			                       + "  <IExternal Concrete-Type=\"ClearCanvas.ImageViewer.Externals.General.CommandLineExternal, ClearCanvas.ImageViewer.Externals, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\"><![CDATA[<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n"
			                       + "<CommandLineExternal xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n"
			                       + "  <Name>external3</Name>\r\n"
			                       + "</CommandLineExternal>]]></IExternal>\r\n"
			                       + "</ExternalCollection>";

			var expectedExternal1 = new CommandLineExternal {Name = "external1", Label = "Label1", Enabled = true, WindowStyle = WindowStyle.Normal, Command = @"C:\Temp\CommandA.cmd", WorkingDirectory = "$DIRECTORY$", Arguments = "", Username = "", Domain = "", AllowMultiValueFields = false};
			var expectedExternal2 = new CommandLineExternal {Name = "external2", Label = "Label2", Enabled = false, WindowStyle = WindowStyle.Hidden, Command = @"\ComputerA\ShareB\CommandC.cmd", WorkingDirectory = "$DIRECTORY$", Arguments = "\"$FILENAMEONLY$\"", Username = "\u5305\u9752\u5929", Domain = "\u958B\u5C01\u5E9C", AllowMultiValueFields = true, MultiValueFieldSeparator = "\" \""};
			var expectedExternal3 = new CommandLineExternal {Name = "external3"};

			var collection = ExternalCollection.Deserialize(testXml);
			Assert.IsNotNull(collection, "Deserialization returned null");
			Assert.AreEqual(3, collection.Count, "Deserialization returned collection with wrong number of entries");

			var external1 = CollectionUtils.SelectFirst(collection, e => e.Name == "external1");
			Assert.IsNotNull(external1, "Failed to deserialize external1");
            Assert.IsInstanceOf(typeof(CommandLineExternal), external1, "external1: Wrong concrete implementation of IExternal");
			AssertCommandLineExternal(expectedExternal1, (CommandLineExternal) external1, "external1");

			var external2 = CollectionUtils.SelectFirst(collection, e => e.Name == "external2");
			Assert.IsNotNull(external2, "Failed to deserialize external2");
            Assert.IsInstanceOf(typeof(CommandLineExternal), external2, "external2: Wrong concrete implementation of IExternal");
			AssertCommandLineExternal(expectedExternal2, (CommandLineExternal) external2, "external2");

			var external3 = CollectionUtils.SelectFirst(collection, e => e.Name == "external3");
			Assert.IsNotNull(external3, "Failed to deserialize external3");
            Assert.IsInstanceOf(typeof(CommandLineExternal), external3, "external3: Wrong concrete implementation of IExternal");
			AssertCommandLineExternal(expectedExternal3, (CommandLineExternal) external3, "external3");
		}
示例#5
0
		public void TestEnvironmentVariableExpansion()
		{
			string baseDirectory = Path.Combine(Path.Combine(Path.GetTempPath(), "ClearCanvas"), this.GetType().Name);
			string commandDirectory = Path.Combine(baseDirectory, "TestEnvironmentVariableExpansion");
			string invalidDirectory = Path.Combine(baseDirectory, "TestEnvironmentVariableExpansion.April");
			string workingDirectory = Path.Combine(baseDirectory, "TestEnvironmentVariableExpansion.Archer");
			Directory.CreateDirectory(commandDirectory);
			Directory.CreateDirectory(invalidDirectory);
			Directory.CreateDirectory(workingDirectory);
			using (MockCommandLine command = new MockCommandLine(commandDirectory))
			{
				using (var processVars = new EnvironmentVariablesTestConstruct(EnvironmentVariableTarget.Process))
				{
					processVars["CMDDIR"] = "TestEnvironmentVariableExpansion";
					processVars["WRKDIR"] = "TestEnvironmentVariableExpansion.April";

					using (var userVars = new EnvironmentVariablesTestConstruct(EnvironmentVariableTarget.User))
					{
						userVars["CMDDIR"] = "TestEnvironmentVariableExpansion";
						userVars["WRKDIR"] = "TestEnvironmentVariableExpansion.Archer";
						userVars["ARGA"] = "Kirk";
						userVars["ARGB"] = "Picard";

						using (var machineVars = new EnvironmentVariablesTestConstruct(EnvironmentVariableTarget.Machine))
						{
							machineVars["CMDDIR"] = "TestEnvironmentVariableExpansion";
							machineVars["ARGA"] = "Decker";
							machineVars["ARGB"] = "Locutus";
							machineVars["ARGC"] = "Sisko";
							machineVars["ARGD"] = "Janeway";
							machineVars["ARGE"] = "$00100020$";

							CommandLineExternal external = new CommandLineExternal();
							external.WorkingDirectory = baseDirectory + Path.DirectorySeparatorChar + userVars.Format("WRKDIR");
							external.Command = baseDirectory + Path.DirectorySeparatorChar + userVars.Format("CMDDIR") + Path.DirectorySeparatorChar + Path.GetFileName(command.ScriptFilename);
							external.Arguments = string.Format("\"{0}\" \"Chateau {1} 2347\" \"{2} vs. {3}\" \"Over 9000%%\" \"%Kim%: Ensign for Life\" \"{4}\" \"$00100021$\"", userVars.Format("ARGA"), userVars.Format("ARGB"), userVars.Format("ARGC"), userVars.Format("ARGD"), userVars.Format("ARGE"));
							external.WaitForExit = true;

							using (MockDicomPresentationImage image = new MockDicomPresentationImage())
							{
								image[0x00100020].SetStringValue("Archer");
								image[0x00100021].SetStringValue(userVars.Format("ARGB"));

								external.Launch(image);

								Thread.Sleep(_processEndWaitDelay); // wait for the external to finish
								command.Refresh();

								Trace.WriteLine(string.Format("Command Execution Report"));
								Trace.WriteLine(command.ExecutionReport);

								// verify that command path is processed for environment variables
								AssertAreEqualIgnoreCase(commandDirectory + Path.DirectorySeparatorChar + Path.GetFileName(command.ScriptFilename), command.ExecutedCommand, "Wrong command was executed: ENVVARS aren't being processed correctly");

								// verify that working directory is processed for environment variables and that process-scope variables are **not** being used
								AssertAreEqualIgnoreCase(workingDirectory, command.ExecutedWorkingDirectory, "Command executed in wrong working directory: ENVVARS aren't being processed correctly (should not be using process-scope)");

								// verify that user-scope variables override machine-scope variables
								Assert.AreEqual("\"Kirk\"", command.ExecutedArguments[0], "Wrong argument passed at index {0}: ENVVARS of different scopes aren't being processed with the correct priority", 0);

								// verify that variable expansion takes place without modifying literals
								Assert.AreEqual("\"Chateau Picard 2347\"", command.ExecutedArguments[1], "Wrong argument passed at index {0}: ENVVARS aren't processing literals", 1);

								// verify that variable expansion handles more than one variable in a single argument
								Assert.AreEqual("\"Sisko vs. Janeway\"", command.ExecutedArguments[2], "Wrong argument passed at index {0}: ENVVARS aren't processing more than one variable", 2);

								// verify that variable expansion handles literal percent sign character escape sequence
								Assert.AreEqual("\"Over 9000%\"", command.ExecutedArguments[3], "Wrong argument passed at index {0}: ENVVARS aren't processing literal percent sign characters", 3);

								// verify that variable expansion treats undefined variables as a literal sequence
								Assert.AreEqual("\"%Kim%: Ensign for Life\"", command.ExecutedArguments[4], "Wrong argument passed at index {0}: ENVVARS aren't processing undefined variables", 4);

								// verify that variable expansion results are processed for special fields
								Assert.AreEqual("\"Archer\"", command.ExecutedArguments[5], "Wrong argument passed at index {0}: ENVVARS should be processed for built-in/DICOM special fields", 5);

								// verify that special field expansion results are **not** processed for environment variables
								Assert.AreEqual('"' + userVars.Format("ARGB") + '"', command.ExecutedArguments[6], "Wrong argument passed at index {0}: Built-in/DICOM special fields should not be processed for ENVVARS", 6);
							}
						}
					}
				}
			}
			Directory.Delete(commandDirectory);
			Directory.Delete(invalidDirectory);
			Directory.Delete(workingDirectory);
		}
示例#6
0
		public void TestDicomFieldsWithMultipleImages()
		{
			using (MockCommandLine command = new MockCommandLine())
			{
				CommandLineExternal external = new CommandLineExternal();
				external.Command = command.ScriptFilename;
				external.AllowMultiValueFields = true;
				external.MultiValueFieldSeparator = " ";
				external.Arguments = "\"$00100020$\" \"$00100021$\"";

				using (MockDicomPresentationImage image = new MockDicomPresentationImage())
				{
					using (MockDicomPresentationImage otherImage = new MockDicomPresentationImage())
					{
						using (MockDicomPresentationImage thirdImage = new MockDicomPresentationImage())
						{
							using (MockDicomPresentationImage fourthImage = new MockDicomPresentationImage())
							{
								using (MockDicomPresentationImage anotherImage = new MockDicomPresentationImage())
								{
									image[0x00100020].SetStringValue("The cake is a lie");
									otherImage[0x00100020].SetStringValue("The cake is a lie");
									thirdImage[0x00100020].SetStringValue("The cake is a lie");
									fourthImage[0x00100020].SetStringValue("The cake is a lie");
									anotherImage[0x00100020].SetStringValue("The cake is a lie");

									image[0x00100021].SetStringValue("Look, my liege!");
									otherImage[0x00100021].SetStringValue("Camelot!");
									thirdImage[0x00100021].SetStringValue("Camelot!");
									fourthImage[0x00100021].SetStringValue("Camelot!");
									anotherImage[0x00100021].SetStringValue("It's only a model");

									IPresentationImage[] images = new IPresentationImage[] {image, otherImage, thirdImage, fourthImage, anotherImage};
									Assert.IsTrue(external.CanLaunch(images));
									external.Launch(images);

									Thread.Sleep(_processEndWaitDelay); // wait for the external to finish
									command.Refresh();

									Trace.WriteLine(string.Format("Command Execution Report"));
									Trace.WriteLine(command.ExecutionReport);

									// these file paths may or may not have spaces in them, but we don't care either way for this test
									Assert.AreEqual("\"The cake is a lie\"", command.ExecutedArguments[0], "Wrong argument for 00100020 field of first image");
									Assert.AreEqual("\"Look, my liege!\"", command.ExecutedArguments[1], "Wrong argument for 00100021 field of first image");
								}
							}
						}
					}
				}
			}
		}
示例#7
0
		public void TestMultipleImages()
		{
			using (MockCommandLine command = new MockCommandLine())
			{
				CommandLineExternal external = new CommandLineExternal();
				external.Command = command.ScriptFilename;
				external.AllowMultiValueFields = true;
				external.MultiValueFieldSeparator = "\" \"";
				external.Arguments = "\"$FILENAME$\" \"$DIRECTORY$\" \"$EXTENSIONONLY$\" \"$FILENAMEONLY$\"";

				using (MockDicomPresentationImage image = new MockDicomPresentationImage())
				{
					using (MockDicomPresentationImage otherImage = new MockDicomPresentationImage())
					{
						using (MockDicomPresentationImage thirdImage = new MockDicomPresentationImage())
						{
							IPresentationImage[] images = new IPresentationImage[] {image, otherImage, thirdImage};
							Assert.IsTrue(external.CanLaunch(images));
							external.Launch(images);

							Thread.Sleep(_processEndWaitDelay); // wait for the external to finish
							command.Refresh();

							Trace.WriteLine(string.Format("Command Execution Report"));
							Trace.WriteLine(command.ExecutionReport);

							// these file paths may or may not have spaces in them, but we don't care either way for this test
							AssertAreEqualIgnoreCase(image.Filename, command.ExecutedArguments[0].Replace("\"", ""), "Wrong argument for 1st filename field");
							AssertAreEqualIgnoreCase(otherImage.Filename, command.ExecutedArguments[1].Replace("\"", ""), "Wrong argument for 2nd filename field");
							AssertAreEqualIgnoreCase(thirdImage.Filename, command.ExecutedArguments[2].Replace("\"", ""), "Wrong argument for 3rd filename field");
							AssertAreEqualIgnoreCase(Path.GetDirectoryName(image.Filename), command.ExecutedArguments[3].Replace("\"", ""), "Wrong argument for directory field");
							AssertAreEqualIgnoreCase(Path.GetExtension(image.Filename), command.ExecutedArguments[4].Replace("\"", ""), "Wrong argument for extension field");
							AssertAreEqualIgnoreCase(Path.GetFileName(image.Filename), command.ExecutedArguments[5].Replace("\"", ""), "Wrong argument for 1st filename only field");
							AssertAreEqualIgnoreCase(Path.GetFileName(otherImage.Filename), command.ExecutedArguments[6].Replace("\"", ""), "Wrong argument for 2nd filename only field");
							AssertAreEqualIgnoreCase(Path.GetFileName(thirdImage.Filename), command.ExecutedArguments[7].Replace("\"", ""), "Wrong argument for 3rd filename only field");
						}
					}
				}
			}
		}
示例#8
0
		public void TestSingleImage()
		{
			using (MockCommandLine command = new MockCommandLine())
			{
				CommandLineExternal external = new CommandLineExternal();
				external.Command = command.ScriptFilename;
				external.AllowMultiValueFields = false;
				external.Arguments = "\"$FILENAME$\" \"$DIRECTORY$\" \"$EXTENSIONONLY$\" \"$FILENAMEONLY$\" \"$00100020$\" \"$00100021$\"";

				using (MockDicomPresentationImage image = new MockDicomPresentationImage())
				{
					using (MockDicomPresentationImage otherImage = new MockDicomPresentationImage())
					{
						image[0x00100020].SetStringValue("I've got a lovely bunch of coconuts");
						image[0x00100021].SetStringValue("Here they are all standing in a row");
						otherImage[0x00100020].SetStringValue("Big ones, small ones, some as big as your head");

						Assert.IsFalse(external.CanLaunch(new IPresentationImage[] {image, otherImage}));
						Assert.IsTrue(external.CanLaunch(image));

						external.Launch(image);

						Thread.Sleep(_processEndWaitDelay); // wait for the external to finish
						command.Refresh();

						Trace.WriteLine(string.Format("Command Execution Report"));
						Trace.WriteLine(command.ExecutionReport);

						// these file paths may or may not have spaces in them, but we don't care either way for this test
						AssertAreEqualIgnoreCase(image.Filename, command.ExecutedArguments[0].Trim('"'), "Wrong argument for filename field");
						AssertAreEqualIgnoreCase(Path.GetDirectoryName(image.Filename), command.ExecutedArguments[1].Trim('"'), "Wrong argument for directory field");
						AssertAreEqualIgnoreCase(Path.GetExtension(image.Filename), command.ExecutedArguments[2].Trim('"'), "Wrong argument for extension field");
						AssertAreEqualIgnoreCase(Path.GetFileName(image.Filename), command.ExecutedArguments[3].Trim('"'), "Wrong argument for filename only field");
						Assert.AreEqual("I've got a lovely bunch of coconuts", command.ExecutedArguments[4].Trim('"'), "Wrong argument for 00100020 field");
						Assert.AreEqual("Here they are all standing in a row", command.ExecutedArguments[5].Trim('"'), "Wrong argument for 00100021 field");
					}
				}
			}
		}
示例#9
0
		public void TestArgumentFields()
		{
			using (MockCommandLine command = new MockCommandLine())
			{
				CommandLineExternal external = new CommandLineExternal();
				external.Command = command.ScriptFilename;
				external.Arguments = "$$ \"$filename$\"";

				using (MockDicomPresentationImage image = new MockDicomPresentationImage())
				{
					Assert.IsFalse(external.CanLaunch(image), "Fields are case sensitive - unresolved field should fail the launch");

					external.Arguments = "$$ \"$FILENAME$\"";

					Assert.IsTrue(external.CanLaunch(image), "Fields are case sensitive - unresolved field should fail the launch");

					external.Launch(image);

					Thread.Sleep(_processEndWaitDelay); // wait for the external to finish
					command.Refresh();

					Trace.WriteLine(string.Format("Command Execution Report"));
					Trace.WriteLine(command.ExecutionReport);

					AssertAreEqualIgnoreCase("$", command.ExecutedArguments[0], "Wrong argument passed at index {0}", 0);

					// these file paths may or may not have spaces in them, but we don't care either way for this test
					AssertAreEqualIgnoreCase(image.Filename, command.ExecutedArguments[1].Trim('"'), "Wrong argument passed at index {0}", 1);
				}
			}
		}
示例#10
0
		public void TestArguments()
		{
			using (MockCommandLine command = new MockCommandLine())
			{
				CommandLineExternal external = new CommandLineExternal();
				external.Command = command.ScriptFilename;
				external.Arguments = "\"USS Enterprise\" \"USS Defiant\" \"USS Voyager\" \"USS Excelsior\" \"USS Reliant\"";

				using (MockDicomPresentationImage image = new MockDicomPresentationImage())
				{
					external.Launch(image);

					Thread.Sleep(_processEndWaitDelay); // wait for the external to finish
					command.Refresh();

					Trace.WriteLine(string.Format("Command Execution Report"));
					Trace.WriteLine(command.ExecutionReport);

					Assert.AreEqual("\"USS Enterprise\"", command.ExecutedArguments[0], "Wrong argument passed at index {0}", 0);
					Assert.AreEqual("\"USS Defiant\"", command.ExecutedArguments[1], "Wrong argument passed at index {0}", 1);
					Assert.AreEqual("\"USS Voyager\"", command.ExecutedArguments[2], "Wrong argument passed at index {0}", 2);
					Assert.AreEqual("\"USS Excelsior\"", command.ExecutedArguments[3], "Wrong argument passed at index {0}", 3);
					Assert.AreEqual("\"USS Reliant\"", command.ExecutedArguments[4], "Wrong argument passed at index {0}", 4);
				}
			}
		}