public void GetCreationTime_ArgumentNull()
        {
            var mockFileSystem = new MockFileSystem();
            var realFileSystem = new FileSystem();

            Func <IFileSystem, FileSystemType, FileInfoBase, DateTime> execute = (fs, _, file) => fs.File.GetCreationTime(null);

            Actor.CustomResultComparer <DateTime> ignoreComparison = (_, __) => { };
            execute.OnFileSystemsWithParameter(realFileSystem, mockFileSystem, null, null, null, ignoreComparison);
        }
        public void WriteWithEncodingAndAppendAllLinesWithDifferentEncoding_ThenReadAllLinesWithEncoding(Encoding encoding)
        {
            var faker        = new Bogus.Faker("ko");
            var linesToWrite = new List <string>
            {
                faker.Lorem.Lines(20, Environment.NewLine),
                faker.Lorem.Lines(20, Environment.NewLine)
            };
            var linesToAppend = new List <string>
            {
                faker.Random.Words(344),
                faker.Lorem.Lines(20, Environment.NewLine)
            };

            var subFolder = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
            Func <IFileSystem, FileSystemType, FileInfoBase> prepare = (system, type) =>
            {
                var tempPath       = system.Path.Combine(_fileSystemFixture.BaseDirectory, subFolder);
                var tempDirectory2 = system.Directory.CreateDirectory(tempPath);
                _output.WriteLine("Temporary Directory {0} ({1})", tempDirectory2.FullName, type);
                var realFilePath = system.Path.Combine(tempDirectory2.FullName, "willbecreated.txt");
                var result       = system.FileInfo.FromFileName(realFilePath);
                return(result);
            };

            var mockFileSystem = new MockFileSystem();
            var realFileSystem = new FileSystem();

            var realFile = prepare(realFileSystem, FileSystemType.Real);
            var mockFile = prepare(mockFileSystem, FileSystemType.Mock);
            Func <IFileSystem, FileSystemType, FileInfoBase, string[]> execute = (fs, fst, file) =>
            {
                fs.File.WriteAllLines(file.FullName, linesToWrite, encoding);
                fs.File.AppendAllLines(file.FullName, linesToAppend, Encoding.UTF7);
                var l = fs.File.ReadAllLines(file.FullName, encoding);
                return(l);
            };

            Actor.CustomResultComparer <string[]> comparer = (r, m) =>
            {
                if (r == null)
                {
                    m.Should().BeNull();
                }
                else
                {
                    m.Should().ContainInOrder(r, "the content in the mock file system should be the same as in the real file system");
                }
            };
            execute.OnFileSystemsWithParameter(realFileSystem, mockFileSystem, realFile, mockFile, null, comparer, _output);
        }
        public void WriteWithEncodingAndAppendAllLinesWithDifferentEncoding2_ThenReadAllLinesWithEncoding()
        {
            var subFolder = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
            Func <IFileSystem, FileSystemType, FileInfoBase> prepare = (system, type) =>
            {
                var tempPath       = system.Path.Combine(_fileSystemFixture.BaseDirectory, subFolder);
                var tempDirectory2 = system.Directory.CreateDirectory(tempPath);
                _output.WriteLine("Temporary Directory {0} ({1})", tempDirectory2.FullName, type);
                var realFilePath = system.Path.Combine(tempDirectory2.FullName, "willbecreated.txt");
                var result       = system.FileInfo.FromFileName(realFilePath);
                return(result);
            };

            var mockFileSystem = new MockFileSystem();
            var realFileSystem = new FileSystem();

            var realFile = prepare(realFileSystem, FileSystemType.Real);
            var mockFile = prepare(mockFileSystem, FileSystemType.Mock);
            Func <IFileSystem, FileSystemType, FileInfoBase, byte[]> execute = (fs, fst, file) =>
            {
                fs.File.WriteAllText(file.FullName, "Demo text content");
                fs.File.AppendAllText(file.FullName, " some text", Encoding.Unicode);
                var b = fs.File.ReadAllBytes(file.FullName);
                return(b);
            };

            Actor.CustomResultComparer <byte[]> comparer = (r, m) =>
            {
                if (r == null)
                {
                    m.Should().BeNull();
                }
                else
                {
                    m.Should().ContainInOrder(r, "the content in the mock file system should be the same as in the real file system");
                }
            };
            execute.OnFileSystemsWithParameter(realFileSystem, mockFileSystem, realFile, mockFile, null, comparer, _output);
        }
        public void GetCreationTime_FileDoesExist()
        {
            var subFolder = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
            Func <IFileSystem, FileInfoBase> prepare = system =>
            {
                var tempPath       = system.Path.Combine(_fileSystemFixture.BaseDirectory, subFolder);
                var tempDirectory2 = system.Directory.CreateDirectory(tempPath);
                _output.WriteLine("Temporary Directory {0}", tempDirectory2.FullName);
                var realFilePath = tempPath + "\\mustexist.txt";
                var result       = system.FileInfo.FromFileName(realFilePath);
                system.File.AppendAllText(result.FullName, "foo");
                return(result);
            };

            var mockFileSystem = new MockFileSystem();
            var realFileSystem = new FileSystem();

            var realFile = prepare(realFileSystem);
            var mockFile = prepare(mockFileSystem);
            Func <IFileSystem, FileSystemType, FileInfoBase, DateTime> execute = (fs, _, file) => fs.File.GetCreationTime(file.FullName);

            Actor.CustomResultComparer <DateTime> ignoreComparison = (_, __) => { };
            execute.OnFileSystemsWithParameter(realFileSystem, mockFileSystem, realFile, mockFile, null, ignoreComparison);
        }