public void Open_ProcessStartReturnsNonNull_ReturnsTrue() { const string fileName = @"c:\xyz\abc"; const int id = 24680; using (ShimsContext.Create()) { ShimFile.ExistsString = (f) => { return((f == fileName) ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f))); }; A11yElement element = new ShimA11yElement { UniqueIdGet = () => id, }; ProcessStartInfo actualStartInfo = null; ILocation location = new OutputFileLocation(fileName, element, (startInfo) => { actualStartInfo = startInfo; return(new Process()); }); Assert.IsNull(actualStartInfo); Assert.IsTrue(location.Open()); Assert.IsNotNull(actualStartInfo); Assert.AreEqual(fileName, actualStartInfo.FileName); Assert.AreEqual("open", actualStartInfo.Verb); } }
public void Open_FileDoesNotExist_ReturnsFalse() { const string fileName = @"c:\xyz\abc"; const int id = 24680; bool fileExists = true; using (ShimsContext.Create()) { ShimFile.ExistsString = (f) => { return((f == fileName) ? fileExists : ShimsContext.ExecuteWithoutShims(() => File.Exists(f))); }; A11yElement element = new ShimA11yElement { UniqueIdGet = () => id, }; ILocation location = new OutputFileLocation(fileName, element); fileExists = false; Assert.IsFalse(location.Open()); } }
public void Open_ProcessStartThrowsNonEnumeratedException_RethrowsException() { const string fileName = @"c:\xyz\abc"; const int id = 24680; using (ShimsContext.Create()) { ShimFile.ExistsString = (f) => { return((f == fileName) ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f))); }; A11yElement element = new ShimA11yElement { UniqueIdGet = () => id, }; ILocation location = new OutputFileLocation(fileName, element, (startInfo) => { throw new OutOfMemoryException(); }); location.Open(); } }
public void Open_ProcessStartThrowsEnumeratedException_ReturnsFalse() { const string fileName = @"c:\xyz\abc"; const int id = 24680; using (ShimsContext.Create()) { ShimFile.ExistsString = (f) => { return((f == fileName) ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f))); }; A11yElement element = new ShimA11yElement { UniqueIdGet = () => id, }; List <Exception> enumeratedExceptions = new List <Exception> { new InvalidOperationException(), new ArgumentException(), new ObjectDisposedException("blah", new Exception()), new FileNotFoundException(), new Win32Exception(), }; int exceptionsTested = 0; foreach (Exception e in enumeratedExceptions) { ILocation location = new OutputFileLocation(fileName, element, (startInfo) => { throw e; }); Assert.IsFalse(location.Open(), "Simulated Exception: " + e.ToString()); exceptionsTested++; } Assert.AreEqual(enumeratedExceptions.Count, exceptionsTested); } }