Esempio n. 1
0
		public void TestAssignment ()
		{
			MakeDir md = new MakeDir ();

			md.Directories = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };

			Assert.AreEqual (2, md.Directories.Length, "A1");
		}
Esempio n. 2
0
        public void SomeInputsFailToCreate()
        {
            string temp = Path.GetTempPath();
            string file = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A38e");
            string dir = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A38f");
            string invalid = "!@#$%^&*()|";
            string dir2 = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A390");

            try
            {
                FileStream fs = File.Create(file);
                fs.Close(); //we're gonna try to delete it

                MakeDir t = new MakeDir();
                MockEngine engine = new MockEngine();
                t.BuildEngine = engine;

                t.Directories = new ITaskItem[]
                {
                    new TaskItem(dir),
                    new TaskItem(file),
                    new TaskItem(invalid),
                    new TaskItem(dir2)
                };

                bool success = t.Execute();

                Assert.IsTrue(!success);
                Assert.AreEqual(2, t.DirectoriesCreated.Length);
                Assert.AreEqual(dir, t.DirectoriesCreated[0].ItemSpec);
                Assert.AreEqual(dir2, t.DirectoriesCreated[1].ItemSpec);
                Assert.IsTrue
                (
                    engine.Log.Contains
                    (
                        String.Format(AssemblyResources.GetString("MakeDir.Comment"), dir)
                    )
                );
            }
            finally
            {
                Directory.Delete(dir);
                File.Delete(file);
                Directory.Delete(dir2);
            }
        }
Esempio n. 3
0
		public override bool Execute()
		{
			XslCompiledTransform transform = new XslCompiledTransform();
			transform.Load(_xslFile.ItemSpec);

			if (_sourceFiles.Length != _destinationFiles.Length)
			{
				Log.LogError("Source files has an item count of {0} while destination files has an item count of {1}. Both must have same count.", _sourceFiles.Length, _destinationFiles.Length);
			}
			else
			{
				string tranformName = Path.GetFileNameWithoutExtension(_xslFile.ItemSpec);

				for (int i = 0; i < _sourceFiles.Length; i++)
				{
					ITaskItem sourceFile = _sourceFiles[i];
					ITaskItem destinationFile = _destinationFiles[i];

					string directory = Path.GetDirectoryName(destinationFile.ItemSpec);
					if (!Directory.Exists(directory))
					{
						MakeDir makeDir = new MakeDir();
						makeDir.BuildEngine = BuildEngine;
						makeDir.Directories = new ITaskItem[] {new TaskItem(directory)};
						makeDir.Execute();
					}

					try
					{
						using (FileStream outputStream = new FileStream(destinationFile.ItemSpec, FileMode.Create, FileAccess.Write))
						{
							XPathDocument xPathDocument = new XPathDocument(sourceFile.ItemSpec);
							transform.Transform(xPathDocument, null, outputStream);
							Log.LogMessage(MessageImportance.Normal, "Applied transform {0} and stored result as {1}", tranformName, destinationFile.ItemSpec);
						}
					}
					catch (Exception ex)
					{
						Log.LogError("Cannot apply transformation on file {0}: {1}", sourceFile.ItemSpec, ex.Message);
					}
				}
			}

			return !Log.HasLoggedErrors;
		}
Esempio n. 4
0
        public void AttributeForwarding()
        {
            string temp = Path.GetTempPath();
            string dir = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A391");

            try
            {
                MakeDir t = new MakeDir();
                MockEngine engine = new MockEngine();
                t.BuildEngine = engine;

                t.Directories = new ITaskItem[]
                {
                    new TaskItem(dir)
                };
                t.Directories[0].SetMetadata("Locale", "en-GB");

                bool success = t.Execute();

                Assert.IsTrue(success);
                Assert.AreEqual(1, t.DirectoriesCreated.Length);
                Assert.AreEqual(dir, t.DirectoriesCreated[0].ItemSpec);
                Assert.IsTrue
                (
                    engine.Log.Contains
                    (
                        String.Format(AssemblyResources.GetString("MakeDir.Comment"), dir)
                    )
                );
                Assert.AreEqual("en-GB", t.DirectoriesCreated[0].GetMetadata("Locale"));

                // Output ItemSpec should not be overwritten.
                Assert.AreEqual(dir, t.DirectoriesCreated[0].ItemSpec);
            }
            finally
            {
                Directory.Delete(dir);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Create the directory <see cref="TestDirectory"/>.
 /// </summary>
 /// <param name="buildEngine">The build engine to use for the <see cref="MakeDir"/> task.</param>
 /// <returns>Returns the path name of the created directory.</returns>
 public static string makeTestDirectory(IBuildEngine buildEngine)
 {
     MakeDir makeDirTask = new MakeDir();
     makeDirTask.BuildEngine = buildEngine;
     string testDirectory = TaskUtility.TestDirectory;
     makeDirTask.Directories = StringArrayToItemArray(testDirectory);
     makeDirTask.Execute();
     return testDirectory;
 }
Esempio n. 6
0
        public void FileAlreadyExists()
        {
            string temp = Path.GetTempPath();
            string file = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A38d");

            try
            {
                FileStream fs = File.Create(file);
                fs.Close(); //we're gonna try to delete it

                MakeDir t = new MakeDir();
                MockEngine engine = new MockEngine();
                t.BuildEngine = engine;

                t.Directories = new ITaskItem[]
                {
                    new TaskItem(file)
                };

                bool success = t.Execute();

                Assert.IsTrue(!success);
                Assert.AreEqual(0, t.DirectoriesCreated.Length);
                Assert.IsTrue(engine.Log.Contains("MSB3191"));
                Assert.IsTrue(engine.Log.Contains(file));
            }
            finally
            {
                File.Delete(file);
            }
        }
Esempio n. 7
0
        public void CreateNewDirectory()
        {
            string temp = Path.GetTempPath();
            string dir = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A38C");

            try
            {
                MakeDir t = new MakeDir();
                MockEngine engine = new MockEngine();
                t.BuildEngine = engine;

                t.Directories = new ITaskItem[]
                {
                    new TaskItem(dir)
                };

                bool success = t.Execute();

                Assert.IsTrue(success);
                Assert.AreEqual(1, t.DirectoriesCreated.Length);
                Assert.AreEqual(dir, t.DirectoriesCreated[0].ItemSpec);
                Assert.IsTrue
                (
                    engine.Log.Contains
                    (
                        String.Format(AssemblyResources.GetString("MakeDir.Comment"), dir)
                    )
                );

                engine.Log = "";
                success = t.Execute();

                Assert.IsTrue(success);
                // should still return directory even though it didn't need to be created
                Assert.AreEqual(1, t.DirectoriesCreated.Length);
                Assert.AreEqual(dir, t.DirectoriesCreated[0].ItemSpec);
                Assert.IsTrue
                (
                    !engine.Log.Contains
                    (
                        String.Format(AssemblyResources.GetString("MakeDir.Comment"), dir)
                    )
                );
            }
            finally
            {
                Directory.Delete(dir);
            }
        }