Binboo.Core.Tests.Tests.CustomFilters.CustomFilterPredicateTestCase.AssertIOIsNotAllowedForPredicates C# (CSharp) Method

AssertIOIsNotAllowedForPredicates() private method

private AssertIOIsNotAllowedForPredicates ( string trickName, string trickCode ) : void
trickName string
trickCode string
return void
        private void AssertIOIsNotAllowedForPredicates(string trickName, string trickCode)
        {
            var testFilePath = Path.Combine(Path.GetTempPath(), trickName + DateTime.Now.Ticks);

            bool ioSucceeded = false;
            var watcher = new FileSystemWatcher(Path.GetDirectoryName(testFilePath));
            watcher.Created += (send, args) => ioSucceeded = !ioSucceeded && args.FullPath == testFilePath;

            watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.LastAccess;

            trickCode = trickCode.Replace("%FILE-WRITE%",
                                           @"System.IO.File.WriteAllText(""" + testFilePath.Replace("\\", "\\\\") + @""", ""content"")");

            bool included = CompileAndRunCustomFilter(watcher, trickCode);
            if (File.Exists(testFilePath))
            {
                File.Delete(testFilePath);
                Assert.Fail("Custom filters should not be able to create files.");
            }

            Assert.False(ioSucceeded, "Custom filter code should not be able to write to files");
            Assert.False(included);
        }