private void Directory_EnumerateAlternateDataStreams(bool isNetwork) { UnitTestConstants.PrintUnitTestHeader(isNetwork); var tempPath = Path.GetTempPath("Directory-EnumerateAlternateDataStreams-" + Path.GetRandomFileName()); if (isNetwork) { tempPath = Path.LocalToUnc(tempPath); } const int defaultStreamsDirectory = 0; // The default number of data streams for a folder. Console.WriteLine("\nInput Directory Path: [{0}]", tempPath); Console.WriteLine("\nA directory is created and {0} streams are added.", UnitTestConstants.AllStreams.Count()); try { var di = new DirectoryInfo(tempPath); di.Create(); var currentNumberofStreams = di.EnumerateAlternateDataStreams().Count(); Assert.AreEqual(defaultStreamsDirectory, currentNumberofStreams, "Total amount of default streams do not match."); Assert.AreEqual(currentNumberofStreams, Directory.EnumerateAlternateDataStreams(tempPath).Count(), "Total amount of Directory.EnumerateAlternateDataStreams() streams do not match."); Assert.AreEqual(currentNumberofStreams, di.EnumerateAlternateDataStreams().Count(), "Total amount of DirectoryInfo() streams do not match."); // Create alternate data streams. // Because of the colon, you must supply a full path and use PathFormat.FullPath or PathFormat.LongFullPath, // to prevent a: "NotSupportedException: path is in an invalid format." exception. File.WriteAllLines(tempPath + Path.StreamSeparator + UnitTestConstants.MyStream, UnitTestConstants.StreamArrayContent, PathFormat.FullPath); File.WriteAllText(tempPath + Path.StreamSeparator + UnitTestConstants.MyStream2, UnitTestConstants.StreamStringContent, PathFormat.FullPath); var newNumberofStreams = Directory.EnumerateAlternateDataStreams(tempPath).Count(); Console.WriteLine("\n\nCurrent stream Count(): [{0}]", newNumberofStreams); // Enumerate all streams from the folder. foreach (var stream in di.EnumerateAlternateDataStreams()) { Assert.IsTrue(UnitTestConstants.Dump(stream, -10)); } // Show the contents of our streams. Console.WriteLine(); foreach (var streamName in UnitTestConstants.AllStreams) { Console.WriteLine("\n\tStream name: [{0}]", streamName); // Because of the colon, you must supply a full path and use PathFormat.FullPath or PathFormat.LongFullPath, // to prevent a: "NotSupportedException: path is in an invalid format." exception. foreach (var line in File.ReadAllLines(tempPath + Path.StreamSeparator + streamName, PathFormat.FullPath)) { Console.WriteLine("\t\t{0}", line); } } } catch (Exception ex) { Console.WriteLine("\n\tCaught (unexpected) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); Assert.IsTrue(false); } finally { Directory.Delete(tempPath); Assert.IsFalse(Directory.Exists(tempPath), "Cleanup failed: Directory should have been removed."); } Console.WriteLine(); }