Example #1
0
        // Pattern: <class>_<function>_<scenario>_<expected result>

        #region Unit Tests

        private void Dump83Path(bool isLocal)
        {
            #region Setup

            Console.WriteLine("\n=== TEST {0} ===", isLocal ? UnitTestConstants.Local : UnitTestConstants.Network);

            var myLongPath = Path.GetTempPath("My Long Data File Or Directory");
            if (!isLocal)
            {
                myLongPath = Path.LocalToUnc(myLongPath);
            }

            Console.WriteLine("\nInput Path: [{0}]\n", myLongPath);

            #endregion // Setup

            #region File

            string short83Path;

            try
            {
                using (File.Create(myLongPath))

                    UnitTestConstants.StopWatcher(true);

                short83Path = Path.GetShort83Path(myLongPath);

                Console.WriteLine("Short 8.3 file path    : [{0}]\t\t\t{1}", short83Path, UnitTestConstants.Reporter(true));

                Assert.IsTrue(!short83Path.Equals(myLongPath));

                Assert.IsTrue(short83Path.EndsWith(@"~1"));



                UnitTestConstants.StopWatcher(true);

                var longFrom83Path = Path.GetLongFrom83ShortPath(short83Path);

                Console.WriteLine("Long path from 8.3 path: [{0}]{1}", longFrom83Path, UnitTestConstants.Reporter(true));

                Assert.IsTrue(longFrom83Path.Equals(myLongPath));

                Assert.IsFalse(longFrom83Path.EndsWith(@"~1"));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Caught (unexpected) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
            }
            finally
            {
                if (File.Exists(myLongPath))
                {
                    File.Delete(myLongPath);
                }
            }
            Console.WriteLine();

            #endregion // File

            #region Directory

            try
            {
                Directory.CreateDirectory(myLongPath);

                UnitTestConstants.StopWatcher(true);

                short83Path = Path.GetShort83Path(myLongPath);

                Console.WriteLine("Short 8.3 directory path: [{0}]\t\t\t{1}", short83Path, UnitTestConstants.Reporter(true));

                Assert.IsFalse(short83Path.Equals(myLongPath));

                Assert.IsTrue(short83Path.EndsWith(@"~1"));



                UnitTestConstants.StopWatcher(true);

                var longFrom83Path = Path.GetLongFrom83ShortPath(short83Path);

                Console.WriteLine("Long path from 8.3 path : [{0}]{1}", longFrom83Path, UnitTestConstants.Reporter(true));

                Assert.IsTrue(longFrom83Path.Equals(myLongPath));

                Assert.IsFalse(longFrom83Path.EndsWith(@"~1"));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Caught (unexpected) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
            }
            finally
            {
                if (Directory.Exists(myLongPath))
                {
                    Directory.Delete(myLongPath);
                }
            }
            Console.WriteLine();

            #endregion // Directory
        }