System.IO.Abstractions.TestingHelpers.MockFileSystem.FileExists C# (CSharp) Method

FileExists() public method

public FileExists ( string path ) : bool
path string
return bool
        public bool FileExists(string path)
        {
            if (string.IsNullOrEmpty(path))
                return false;

            path = FixPath(path);

            lock (files)
                return files.ContainsKey(path);
        }

Usage Example

Example #1
0
        public void TestConfigCanMerge()
        {
            var now = DateTime.Now;
            var mockE1 = new Entry (@"c:\dir2\", 1, now, false);
            var mockE2 = new Entry(@"c:\dir2\file3",10,now,true);
            var mockE3 = new Entry(@"c:\dir3\file1",101,now,true);
            var mockContent = string.Join (Environment.NewLine,
                mockE1.ToString (),
                mockE2.ToString (),
                mockE3.ToString ());

            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> {
                {   FileSystemConfigPath, new MockFileData(mockContent) }
            });

            var db = new Database(fileSystem);
            var fsp = new Provider("FileSystem");
            db.Providers.Add ("FileSystem", fsp);
            now = now.AddSeconds (1);
            var e1 = new Entry (@"c:\dir1\", 12, now, false);
            var e2 = new Entry (@"c:\dir1\file2", 34, now, true);
            var e3 = new Entry(@"c:\dir2\file3",11,now,true);
            var e4 = new Entry(@"c:\dir3\file1",11,now,true);

            fsp.Add(e1);
            fsp.Add(e2);
            fsp.Add(e3);
            fsp.Add(e4);
            Assert.IsTrue(fsp.Remove(e4.FullPath));
            db.Save(100);

            var fsFileName = System.IO.Path.Combine (db.ConfigDir,$"{Database.ConfigFilePrefix}.FileSystem.txt");

            Assert.IsTrue(fileSystem.FileExists(FileSystemConfigPath));
            var configContent = fileSystem.File.ReadAllText (fsFileName);
            StringAssert.Contains (e1 + Environment.NewLine, configContent);
            StringAssert.Contains (e2 + Environment.NewLine, configContent);
            StringAssert.Contains (e3 + Environment.NewLine, configContent);
            StringAssert.Contains (mockE1 + Environment.NewLine, configContent);
            StringAssert.DoesNotContain (mockE2 + Environment.NewLine, configContent);
            StringAssert.DoesNotContain (mockE3 + Environment.NewLine, configContent);
            StringAssert.DoesNotContain(e4 + Environment.NewLine, configContent);
        }
All Usage Examples Of System.IO.Abstractions.TestingHelpers.MockFileSystem::FileExists