public static IDisposable Enable(string productBinaryPath) { if (!File.Exists(productBinaryPath)) { throw new Exception($"Could not find product binary {productBinaryPath} to enable test only behavior on."); } if (FileUtils.SearchInFile(productBinaryPath, OriginalTestOnlyMarker) == -1) { // The marker is already enabled (probably by another call to TestOnlyProductBehavior) // We allow this to be able to nest the enable calls seamlessly - so that tests don't have to track // which helper does what. return(null); } TestFileBackup backup = new TestFileBackup(Path.GetDirectoryName(productBinaryPath), Path.GetFileNameWithoutExtension(productBinaryPath)); backup.Backup(productBinaryPath); IDisposable returnDisposable = null; try { FileUtils.SearchAndReplace( productBinaryPath, OriginalTestOnlyMarker, EnabledTestOnlyMarker, terminateWithNul: false); returnDisposable = backup; backup = null; } finally { if (backup != null) { backup.Dispose(); } } return(returnDisposable); }
public void Dispose() { _backup.Dispose(); }