public void ANSINonASCII()
        {
            string file = FileUtilities.GetTemporaryFile();
            try
            {
                // Start with a missing file.
                File.Delete(file);

                // Append one line to the file.
                WriteLinesToFile a = new WriteLinesToFile();
                a.File = new TaskItem(file);
                a.Lines = new ITaskItem[] { new TaskItem("My special character is \u00C3") };
                Assert.True(a.Execute());

                // Read the line from the file.
                ReadLinesFromFile r = new ReadLinesFromFile();
                r.File = new TaskItem(file);
                Assert.True(r.Execute());

                Assert.Equal(1, r.Lines.Length);
                Assert.Equal("My special character is \u00C3", r.Lines[0].ItemSpec);
            }
            finally
            {
                File.Delete(file);
            }
        }
        public void Basic()
        {
            string file = FileUtilities.GetTemporaryFile();
            try
            {
                // Start with a missing file.
                File.Delete(file);

                // Append one line to the file.
                WriteLinesToFile a = new WriteLinesToFile();
                a.File = new TaskItem(file);
                a.Lines = new ITaskItem[] { new TaskItem("Line1") };
                Assert.IsTrue(a.Execute());

                // Read the line from the file.
                ReadLinesFromFile r = new ReadLinesFromFile();
                r.File = new TaskItem(file);
                Assert.IsTrue(r.Execute());

                Assert.AreEqual(1, r.Lines.Length);
                Assert.AreEqual("Line1", r.Lines[0].ItemSpec);

                // Write two more lines to the file.
                a.Lines = new ITaskItem[] { new TaskItem("Line2"), new TaskItem("Line3") };
                Assert.IsTrue(a.Execute());

                // Read all of the lines and verify them.
                Assert.IsTrue(r.Execute());
                Assert.AreEqual(3, r.Lines.Length);
                Assert.AreEqual("Line1", r.Lines[0].ItemSpec);
                Assert.AreEqual("Line2", r.Lines[1].ItemSpec);
                Assert.AreEqual("Line3", r.Lines[2].ItemSpec);
            }
            finally
            {
                File.Delete(file);
            }
        }
        public void ReadNoAccess()
        {
            string file = FileUtilities.GetTemporaryFile();
            try
            {
                // Start with a missing file.
                File.Delete(file);

                // Append one line to the file.
                WriteLinesToFile a = new WriteLinesToFile();
                a.File = new TaskItem(file);
                a.Lines = new ITaskItem[] { new TaskItem("This is a new line") };
                Assert.True(a.Execute());

                // Remove all File access to the file to current user
                FileSecurity fSecurity = File.GetAccessControl(file);
                string userAccount = string.Format(@"{0}\{1}", System.Environment.UserDomainName, System.Environment.UserName);
                fSecurity.AddAccessRule(new FileSystemAccessRule(userAccount, FileSystemRights.ReadData, AccessControlType.Deny));
                File.SetAccessControl(file, fSecurity);

                // Attempt to Read lines from the file.
                ReadLinesFromFile r = new ReadLinesFromFile();
                MockEngine mEngine = new MockEngine();
                r.BuildEngine = mEngine;
                r.File = new TaskItem(file);
                Assert.False(r.Execute());
            }
            finally
            {
                FileSecurity fSecurity = File.GetAccessControl(file);
                string userAccount = string.Format(@"{0}\{1}", System.Environment.UserDomainName, System.Environment.UserName);
                fSecurity.AddAccessRule(new FileSystemAccessRule(userAccount, FileSystemRights.ReadData, AccessControlType.Allow));
                File.SetAccessControl(file, fSecurity);

                // Delete file
                File.Delete(file);
            }
        }
        public void ReadMissing()
        {
            string file = FileUtilities.GetTemporaryFile();
            File.Delete(file);

            // Read the line from the file.
            ReadLinesFromFile r = new ReadLinesFromFile();
            r.File = new TaskItem(file);
            Assert.True(r.Execute());

            Assert.Equal(0, r.Lines.Length);
        }
        public void IgnoreBlankLines()
        {
            string file = FileUtilities.GetTemporaryFile();
            try
            {
                // Start with a missing file.
                File.Delete(file);

                // Append one line to the file.
                WriteLinesToFile a = new WriteLinesToFile();
                a.File = new TaskItem(file);
                a.Lines = new ITaskItem[]
                {
                    new TaskItem("Line1"),
                    new TaskItem("  "),
                    new TaskItem("Line2"),
                    new TaskItem(""),
                    new TaskItem("Line3"),
                    new TaskItem("\0\0\0\0\0\0\0\0\0")
                };
                Assert.True(a.Execute());

                // Read the line from the file.
                ReadLinesFromFile r = new ReadLinesFromFile();
                r.File = new TaskItem(file);
                Assert.True(r.Execute());

                Assert.Equal(3, r.Lines.Length);
                Assert.Equal("Line1", r.Lines[0].ItemSpec);
                Assert.Equal("Line2", r.Lines[1].ItemSpec);
                Assert.Equal("Line3", r.Lines[2].ItemSpec);
            }
            finally
            {
                File.Delete(file);
            }
        }
        public void Encoding()
        {
            string file = FileUtilities.GetTemporaryFile();
            try
            {
                // Write default encoding: UTF8
                WriteLinesToFile a = new WriteLinesToFile();
                a.BuildEngine = new MockEngine();
                a.File = new TaskItem(file);
                a.Lines = new ITaskItem[] { new TaskItem("\uBDEA") };
                Assert.True(a.Execute());

                ReadLinesFromFile r = new ReadLinesFromFile();
                r.File = new TaskItem(file);
                Assert.True(r.Execute());

                Assert.Equal("\uBDEA", r.Lines[0].ItemSpec);

                File.Delete(file);

                // Write ANSI .. that won't work!
                a = new WriteLinesToFile();
                a.BuildEngine = new MockEngine();
                a.File = new TaskItem(file);
                a.Lines = new ITaskItem[] { new TaskItem("\uBDEA") };
                a.Encoding = "ASCII";
                Assert.True(a.Execute());

                // Read the line from the file.
                r = new ReadLinesFromFile();
                r.File = new TaskItem(file);
                Assert.True(r.Execute());

                Assert.NotEqual("\uBDEA", r.Lines[0].ItemSpec);
            }
            finally
            {
                File.Delete(file);
            }
        }