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 Equals_OtherHasSameFileAndId_ReturnsTrue()
        {
            const string fileName1 = @"c:\xyz\abc";
            const string fileName2 = @"c:\xyz\abc";
            const int    id1       = 24680;
            const int    id2       = 24680;

            using (ShimsContext.Create())
            {
                ShimFile.ExistsString = (f) =>
                {
                    return((f == fileName1 || f == fileName2) ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f)));
                };

                A11yElement element1 = new ShimA11yElement
                {
                    UniqueIdGet = () => id1,
                };
                A11yElement element2 = new ShimA11yElement
                {
                    UniqueIdGet = () => id2,
                };

                ILocation location1 = new OutputFileLocation(fileName1, element1);
                ILocation location2 = new OutputFileLocation(fileName2, element2);

                Assert.IsTrue(location1.Equals(location2));
                Assert.IsTrue(location2.Equals(location1));
            }
        }
        public void Equals_OtherIsDifferentClass_ReturnsFalse()
        {
            const string fileName = @"c:\xyz\abc";

            using (ShimsContext.Create())
            {
                ShimFile.ExistsString = (f) =>
                {
                    return(f == fileName ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f)));
                };

                A11yElement element = new ShimA11yElement
                {
                    UniqueIdGet = () => 24680,
                };

                ILocation location = new OutputFileLocation(fileName, element);

                Assert.IsFalse(location.Equals(new StubILocation()));
            }
        }
        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 UserDisplayInfo_SimpleCase_OutputIsContainsLocationProperties()
        {
            const string fileName = "c:\\abc\\xyz";

            using (ShimsContext.Create())
            {
                ShimFile.ExistsString = (f) =>
                {
                    return(f == fileName ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f)));
                };

                A11yElement element = new ShimA11yElement
                {
                    UniqueIdGet = () => 13579,
                };

                ILocation location    = new OutputFileLocation(fileName, element);
                string    displayInfo = location.UserDisplayInfo;
                Assert.IsTrue(displayInfo.Contains(location.Source));
                Assert.IsTrue(displayInfo.Contains(location.Id));
            }
        }
        public void Ctor_SimpleCase_PropertiesAreSetCorrectly()
        {
            const string fileName = @"c:\xyz\abc";

            using (ShimsContext.Create())
            {
                ShimFile.ExistsString = (f) =>
                {
                    return(f == fileName ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f)));
                };

                A11yElement element = new ShimA11yElement
                {
                    UniqueIdGet = () => 24680,
                };

                ILocation location = new OutputFileLocation(fileName, element);

                Assert.AreEqual(fileName, location.Source);
                Assert.AreEqual("24680", location.Id);
            }
        }
        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);
            }
        }