public void DetectsFileNotLocatable() { using (var gel = new GlobalLock()) { var env = new Ex.Env(); var runtime = Java.Lang.Runtime.GetRuntime(); Java.Lang.Process process = null; runtime.MockExec = (p) => { if (p.Count() == 2 && p[0] == "which" && p[1] == "file") { process = new Java.Lang.Process(); process.MockExecArgs = p; process.MockStdOutput = new[] { "" }; return(process); } throw new Exception($"Could not execute: {p}"); }; var i = new ShouldNotBeAbleToLocateFile().Init(env, "TEST", "file"); Assert.True(i.Ok); } }
public void IsRobust() { var env = new Ex.Env(); string message = null; Exception exception = null; env.Reporter.OnExceptionReported = (msg, ex) => { message = msg; exception = ex; }; env.System.IO.File.Open = (path, mode, access, share) => { throw new Exception("fubar"); }; var deleted = false; env.System.IO.File.Delete = (path) => { deleted = true; }; var i = new FileNotDestructivelyWritable().Init(env, "TEST", "file"); Assert.True(i.Ok); Assert.Equal("IsFileDestructivelyWritable bombed for file", message); Assert.Equal("fubar", exception.Message); Assert.True(deleted); }
public void IsRobust() { using (var gel = new GlobalLock()) { var env = new Ex.Env(); string message = null; Exception exception = null; env.Reporter.OnExceptionReported = (msg, ex) => { message = msg; exception = ex; }; var runtime = Java.Lang.Runtime.GetRuntime(); runtime.MockExec = (p) => { throw new Exception("BOOM!"); }; var i = new ShouldNotBeAbleToLocateFile().Init(env, "TEST", "file"); Assert.True(i.Ok); Assert.Equal("CanLocateFile bombed for file", message); Assert.Equal("BOOM!", exception.Message); } }
/// <inheritdoc/> public IInspector Init(Ex.Env env, string id, string path) { this.Env = env; this.id = id; this.path = path; return(this); }
public void HasCorrectId() { var env = new Ex.Env(); var i = new UrlNotOpenable().Init(env, "TEST", "url"); Assert.Equal("URL_TEST_SHOULD_NOT_BE_OPENABLE", i.Id); }
public void HasCorrectId() { var env = new Ex.Env(); var i = new PathNotSymbolicLink().Init(env, "TEST", "file"); Assert.Equal("PATH_TEST_SHOULD_NOT_REFER_TO_SYMBOLIC_LINK", i.Id); }
public void HasCorrectId() { var env = new Ex.Env(); var i = new FileNotDestructivelyWritable().Init(env, "TEST", "file"); Assert.Equal("FILE_TEST_SHOULD_NOT_BE_DESTRUCTIVELY_WRITABLE", i.Id); }
public void HasCorrectId() { var env = new Ex.Env(); var i = new FileNotPresent().Init(env, "TEST", "file"); Assert.Equal("FILE_TEST_SHOULD_NOT_BE_PRESENT", i.Id); }
public void HasCorrectId() { var env = new Ex.Env(); var i = new FileNotAccessible().Init(env, "TEST", "file"); Assert.Equal("FILE_TEST_SHOULD_NOT_BE_ACCESSIBLE", i.Id); }
public void HasCorrectId() { var env = new Ex.Env(); var i = new DirectoryNotPresent().Init(env, "TEST", "directory"); Assert.Equal("DIRECTORY_TEST_SHOULD_NOT_BE_PRESENT", i.Id); }
public void InitiallyEmpty() { var env = new Ex.Env(); var checks = new Checks(env); Assert.Empty(checks.GetInspectors <Mocks.Inspector>()); }
/// <inheritdoc/> public IInspector Init(Ex.Env env, string checkId, string val) { this.Env = env; this.checkId = checkId; this.id = string.Format(this.idFormat, checkId); this.val = val; return(this); }
public void AddRootsIsRobust(params string[] roots) { var env = new Ex.Env(); var checks = new Checks(env).AddRoots(roots); var inspectors = checks.GetInspectors <Mocks.Inspector>().ToList(); Assert.Empty(inspectors); }
public void DetectsSymbolicLink() { var env = new Ex.Env(); var i = new PathNotSymbolicLink { SymbolicLink = true }.Init(env, "TEST", "file"); Assert.False(i.Ok); }
public void DetectsNotOpenableUrl() { var env = new Ex.Env(); var i = new UrlNotOpenable { CanOpen = false }.Init(env, "TEST", "url"); Assert.True(i.Ok); }
public void HasCorrectId() { using (var gel = new GlobalLock()) { var env = new Ex.Env(); var i = new ShouldNotHaveSpecificBuildTags().Init(env, "TEST", "fu=bar"); Assert.Equal("SHOULD_NOT_HAVE_BUILD_TAG_TEST", i.Id); } }
public void DetectsPackagetNotInstalled() { using (var gel = new GlobalLock()) { var env = new Ex.Env(); var i = new ShouldNotHavePackageInstalled().Init(env, "TEST", "package"); Assert.True(i.Ok); } }
public void HasCorrectId() { using (var gel = new GlobalLock()) { var env = new Ex.Env(); var i = new ShouldNotHavePackageInstalled().Init(env, "TEST", "file"); Assert.Equal("SHOULD_NOT_HAVE_PACKAGE_INSTALLED_TEST", i.Id); } }
public void HasCorrectId() { using (var gel = new GlobalLock()) { var env = new Ex.Env(); var i = new ShouldNotBeAbleToLocateFile().Init(env, "TEST", "file"); Assert.Equal("SHOULD_NOT_LOCATE_TEST", i.Id); } }
public void HasCorrectId() { using (var gel = new GlobalLock()) { var env = new Ex.Env(); var i = new ShouldNotHavePropValues().Init(env, "TEST", "fu=bar"); Assert.Equal("SHOULD_NOT_HAVE_PROP_VALUES_TEST", i.Id); } }
public void CanCheckForOk(string checkId, string val, string id, bool ok) { var env = new Ex.Env(); var checks = new Checks(env).Add(checkId, val); var inspectors = checks.GetInspectors <Mocks.Inspector>(); var check = inspectors.First(); Assert.Equal(ok, check.Ok); }
public void DetectsFileNotReadable() { var env = new Ex.Env(); env.System.IO.File.Open = (path, mode, access, share) => { throw new System.UnauthorizedAccessException("Cannot open in read mode"); }; var i = new FileNotAccessible().Init(env, "TEST", "file"); Assert.True(i.Ok); }
public void DetectsFileNotFound() { var env = new Ex.Env(); env.System.IO.File.Open = (path, mode, access, share) => { throw new FileNotFoundException(); }; var i = new FileNotAccessible().Init(env, "TEST", "file"); Assert.True(i.Ok); }
public void DetectsFileAccessible() { var env = new Ex.Env(); env.System.IO.File.Open = (path, mode, access, share) => { return(new MemoryStream()); }; var i = new FileNotAccessible().Init(env, "TEST", "file"); Assert.False(i.Ok); }
public void UppercasesIds(string checkId, string id) { var env = new Ex.Env(); var checks = new Checks(env).Add(checkId, "asdf"); var inspectors = checks.GetInspectors <Mocks.Inspector>(); var check = inspectors.First(); Assert.Equal(id, check.Id); }
public IInspector Init(Ex.Env env, string checkId, string val) { if (this.bombDuringInit && checkId == "FUBAR") { throw new Exception("bomb during init"); } this.env = env; this.checkId = checkId; this.val = val; return(this); }
public void DetectsDirectoryNotPresent() { var env = new Ex.Env(); env.System.IO.File.Exists = (path) => { throw new DirectoryNotFoundException(); }; var i = new FileNotPresent().Init(env, "TEST", "file"); Assert.True(i.Ok); }
public void DetectsDirectoryNotPresent() { var env = new Ex.Env(); env.System.IO.Directory.Exists = (path) => { return(false); }; var i = new DirectoryNotPresent().Init(env, "TEST", "directory"); Assert.True(i.Ok); }
public void DetectsFileNotPresent() { var env = new Ex.Env(); env.System.IO.File.Exists = (path) => { return(false); }; var i = new FileNotPresent().Init(env, "TEST", "file"); Assert.True(i.Ok); }
public void DetectsMissingPropValue() { using (var gel = new GlobalLock()) { var env = new Ex.Env(); A.OS.Build.Tags = "f00bar;asdf"; var i = new ShouldNotHaveSpecificBuildTags().Init(env, "TEST", "fubar"); Assert.True(i.Ok); } }