public async Task TextFileRamDiskDirectory_FileExists_False()
        {
            // ILogger will only print to Output when tests are run in Debug mode.
            ILogger logger = new Logger();

            logger.SetWorker(
                (type, loggingLevel, logAction, message) =>
                {
                    Debug.WriteLine("ILogger: {0}, {1}, {2}, {3}", type, loggingLevel, logAction, message);
                }
                );

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestStart, "TextFileRamDiskDirectory_FileExists_False");

            var directory = new TextFileRamDiskDirectory("testName", logger: logger);

            Assert.IsFalse(directory.FileExists("something.txt"));

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestEnd, "TextFileRamDiskDirectory_FileExists_False");
        }
        public async Task SaveToDevice_Throws_SaveToDeviceException()
        {
            ILogger logger = new Logger();

            logger.SetWorker(
                (type, loggingLevel, logAction, message) =>
                {
                    // The Logger will only print to Output when tests are run in Debug mode.
                    Debug.WriteLine("ILogger: {0}, {1}, {2}, {3}", type, loggingLevel, logAction, message);
                }
                );

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestStart, "SaveToDevice_Throws_SaveToDeviceException");

            var directory = new TextFileRamDiskDirectory("testDirectoryName", null, logger);
            Assert.IsFalse(directory.CanSaveToDevice);

            var file = directory.OpenWriter("TestFileName.txt", false);
            await file.WriteAsync(
                  "Text that wont be saved to device because ISaveToDeviceManager object not passed into directory when instantiated");
            file.Close();

            var isExceptionThrown = false;
            try
            {
                await directory.SaveFilesToDevice();
            }
            catch (SaveToDeviceException ex)
            {
                Assert.IsTrue(
                    ex.Message.Equals(
                        "SaveToDeviceException: Device Storage Manager implementing ISaveToDevice interface was not passed into TextFileRamDiskDirectory with directory name testDirectoryName. [Com.Xamtastic.Patterns.TextFileRamDisk.Exceptions]"));
                isExceptionThrown = true;
            }

            Assert.IsTrue(isExceptionThrown);

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestEnd, "SaveToDevice_Throws_SaveToDeviceException");
        }
        public async Task TextFileRamDisk_Tests_GetDirectories_DiskName_UnknownDirectory()
        {
            // ILogger will only print to Output when tests are run in Debug mode.
            ILogger logger = new Logger();

            logger.SetWorker(
                (type, loggingLevel, logAction, message) =>
                {
                    Debug.WriteLine("ILogger: {0}, {1}, {2}, {3}", type, loggingLevel, logAction, message);
                }
                );

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestStart, "TextFileRamDisk_Tests_GetDirectories_DiskName_UnknownDirectory");

            const string name = "C";
            var disk = new TextFileRamDisk.TextFileRamDisk(name, logger);

            Assert.IsFalse(disk.DiskName.Equals(name.ToUpper()));
            Assert.IsTrue(disk.DiskName.Equals(name.ToLower()));

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestEnd, "TextFileRamDisk_Tests_GetDirectories_DiskName_UnknownDirectory");
        }
        public async Task TextFileRamDiskArray_Tests_GetDiskNames_IsOfType_List_String()
        {
            // ILogger will only print to Output when tests are run in Debug mode.
            ILogger logger = new Logger();

            logger.SetWorker(
                (type, loggingLevel, logAction, message) =>
                {
                    Debug.WriteLine("ILogger: {0}, {1}, {2}, {3}", type, loggingLevel, logAction, message);
                }
                );

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestStart, "TextFileRamDiskArray_Tests_GetDiskNames_IsOfType_List_String");

            var diskArray = new TextFileRamDiskArray(logger: logger);

            var disknames = diskArray.GetDiskNames();

            Assert.IsTrue(disknames.Count.Equals(0));
            Assert.IsInstanceOfType(disknames, typeof (List<string>));

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestEnd, "TextFileRamDiskArray_Tests_GetDiskNames_IsOfType_List_String");
        }
        public async Task TextFileRamDiskArray_Tests_Write_Read_Alternate_DiskContent()
        {
            // ILogger will only print to Output when tests are run in Debug mode.
            ILogger logger = new Logger();

            logger.SetWorker(
                (type, loggingLevel, logAction, message) =>
                {
                    Debug.WriteLine("ILogger: {0}, {1}, {2}, {3}", type, loggingLevel, logAction, message);
                }
                );

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestStart, "TextFileRamDiskArray_Tests_Write_Read_Alternate_DiskContent");

            var diskArray = new TextFileRamDiskArray(logger: logger);

            var disknames = diskArray.GetDiskNames();

            Assert.IsTrue(disknames.Count.Equals(0));
            Assert.IsInstanceOfType(disknames, typeof (List<string>));

            Assert.IsFalse(diskArray.DiskExists("C"));
            diskArray.AddDisk("C");
            Assert.IsFalse(diskArray.DiskExists("C"));
            Assert.IsTrue(diskArray.DiskExists("c"));
            var diskC = diskArray.GetDisk("c");
            Assert.IsTrue(diskArray.GetDiskNames().Count.Equals(1));

            Assert.IsFalse(diskArray.DiskExists("D"));
            diskArray.AddDisk("D");
            Assert.IsFalse(diskArray.DiskExists("D"));
            Assert.IsTrue(diskArray.DiskExists("d"));
            var diskD = diskArray.GetDisk("d");
            Assert.IsTrue(diskArray.GetDiskNames().Count.Equals(2));

            diskC.AddDirectory("testDirectoryName");
            diskD.AddDirectory("testDirectoryName");

            var cdirectory = diskC.GetDirectory("testDirectoryName");
            var ddirectory = diskD.GetDirectory("testDirectoryName");

            var cFile = cdirectory.OpenWriter("testFileName.txt", false);
            await cFile.WriteAsync("The quick brown fox ");
            cFile.Close();

            var dFile = ddirectory.OpenWriter("testFileName.txt", false);
            await dFile.WriteAsync("jumped over the lazy dog");
            dFile.Close();

            Assert.IsTrue(cdirectory.FileExists("testFileName.txt"));
            Assert.IsTrue(ddirectory.FileExists("testFileName.txt"));

            var newCfileObj = cdirectory.OpenReader("testFileName.txt");
            var newDfileObj = ddirectory.OpenReader("testFileName.txt");

            Assert.IsTrue(
                string.Format("{0}{1}", await newCfileObj.ReadToEndAsync(), await newDfileObj.ReadToEndAsync())
                    .Equals("The quick brown fox jumped over the lazy dog"));

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestEnd, "TextFileRamDiskArray_Tests_Write_Read_Alternate_DiskContent");
        }
        public async Task TextFileRamDiskDirectory_GetFileSize_GreaterThan0()
        {
            // ILogger will only print to Output when tests are run in Debug mode.
            ILogger logger = new Logger();

            logger.SetWorker(
                (type, loggingLevel, logAction, message) =>
                {
                    Debug.WriteLine("ILogger: {0}, {1}, {2}, {3}", type, loggingLevel, logAction, message);
                }
                );

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestStart, "TextFileRamDiskDirectory_GetFileSize_GreaterThan0");

            var directory = new TextFileRamDiskDirectory("testName", logger: logger);

            using (var write = directory.OpenWriter("something.txt", true))
            {
                Assert.IsTrue(directory.FileExists("something.txt"));

                await write.WriteAsync("Test text");
            }

            var size = directory.GetFileSize("something.txt");

            Assert.IsTrue(directory.GetFileSize("something.txt") > 0);

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestEnd, "TextFileRamDiskDirectory_GetFileSize_GreaterThan0");
        }
        public async Task TextFileRamDisk_Tests_GetDirectory()
        {
            // ILogger will only print to Output when tests are run in Debug mode.
            ILogger logger = new Logger();

            logger.SetWorker(
                (type, loggingLevel, logAction, message) =>
                {
                    Debug.WriteLine("ILogger: {0}, {1}, {2}, {3}", type, loggingLevel, logAction, message);
                }
                );

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestStart, "TextFileRamDisk_Tests_GetDirectory");

            var diskName = "C";

            var disk = new TextFileRamDisk.TextFileRamDisk(diskName, logger);

            ITextFileRamDiskDirectory dir = null;

            try
            {
                dir = disk.GetDirectory("TestName");
            }
            catch (DirectoryNotFoundException ex)
            {
                Assert.IsTrue(
                    ex.Message.Equals(
                        "DirectoryNotFoundException: The directory 'TestName' was not found. [Com.Xamtastic.Patterns.TextFileRamDisk.Exceptions]"));
            }

            disk.AddDirectory("something");

            Assert.IsTrue(disk.DirectoryCount.Equals(1));

            dir = disk.GetDirectory("something");

            Assert.IsNotNull(dir);

            Assert.IsTrue(dir.DirectoryName.Equals("something"));

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestEnd, "TextFileRamDisk_Tests_GetDirectory");
        }
        public async Task TextFileRamDisk_Tests_GetDirectory_Write_Read_File()
        {
            // ILogger will only print to Output when tests are run in Debug mode.
            ILogger logger = new Logger();

            logger.SetWorker(
                (type, loggingLevel, logAction, message) =>
                {
                    Debug.WriteLine("ILogger: {0}, {1}, {2}, {3}", type, loggingLevel, logAction, message);
                }
                );

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestStart, "TextFileRamDisk_Tests_GetDirectory_Write_Read_File");

            var diskName = "C";

            var disk = new TextFileRamDisk.TextFileRamDisk(diskName, logger);

            ITextFileRamDiskDirectory dir = null;

            try
            {
                dir = disk.GetDirectory("TestName");
            }
            catch (DirectoryNotFoundException ex)
            {
                Assert.IsTrue(
                    ex.Message.Equals(
                        "DirectoryNotFoundException: The directory 'TestName' was not found. [Com.Xamtastic.Patterns.TextFileRamDisk.Exceptions]"));
            }

            disk.AddDirectory("something");

            Assert.IsTrue(disk.DirectoryCount.Equals(1));

            dir = disk.GetDirectory("something");

            Assert.IsNotNull(dir);

            Assert.IsTrue(dir.DirectoryName.Equals("something"));

            Assert.IsFalse(dir.FileExists("something.txt"));

            var file = dir.OpenWriter("something.txt", false);

            Assert.IsNotNull(file);
            Assert.IsInstanceOfType(file, typeof (TextWriter));
            Assert.IsInstanceOfType(file, typeof (StreamWriter));

            Assert.IsTrue(dir.FileExists("something.txt"));

            await file.WriteAsync("The quick brown fox");

            file.Close(); // Remember to close the file to flush the text

            var letUsFindIt = disk.GetDirectory("something");

            Assert.IsTrue(letUsFindIt.FileExists("something.txt"));

            var thefoundfile = letUsFindIt.OpenReader("something.txt");

            var thefoundtextTask = await thefoundfile.ReadToEndAsync();

            Assert.IsTrue(thefoundtextTask.Equals("The quick brown fox"));

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestEnd, "TextFileRamDisk_Tests_GetDirectory_Write_Read_File");
        }
        public async Task TextFileRamDisk_Tests_GetDirectories()
        {
            // ILogger will only print to Output when tests are run in Debug mode.
            ILogger logger = new Logger();

            logger.SetWorker(
                (type, loggingLevel, logAction, message) =>
                {
                    Debug.WriteLine("ILogger: {0}, {1}, {2}, {3}", type, loggingLevel, logAction, message);
                }
                );

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestStart, "TextFileRamDisk_Tests_GetDirectories");

            var diskName = "C";

            var disk = new TextFileRamDisk.TextFileRamDisk(diskName, logger);

            disk.AddDirectory("a");
            disk.AddDirectory("b");

            var directories = disk.GetDirectoryNames();

            Assert.IsTrue(directories[0].Equals("a"));
            Assert.IsTrue(directories[1].Equals("b"));

            logger.Log(this.GetType(), LoggingLevel.System, LogAction.UnitTestEnd, "TextFileRamDisk_Tests_GetDirectory");
        }