public void CheckForSession_PathIsNullOrEmpty_SnapshotTestException(string path)
        {
            // arrange
            var snapshotFullName = new SnapshotFullName("filename", path);

            // act
            Func <SnapshotFullName> action = () => LiveUnitTestingDirectoryResolver
                                             .CheckForSession(snapshotFullName);

            // assert
            action.Should().Throw <SnapshotTestException>();
        }
        public void TryResolveName_NoFileMatch_ResultIsNull()
        {
            // arrange
            ArrangeLiveUnitTestDirectory("Test2.cs");
            var testName = "Test1.Foo";

            // act
            SnapshotFullName fullName = LiveUnitTestingDirectoryResolver
                                        .TryResolveName(testName);

            // assert
            fullName.Should().BeNull();
        }
        public void CheckForSession_PathSet_ReturnSame()
        {
            // arrange
            var snapshotFullName = new SnapshotFullName("filename", "dirname");

            // act
            SnapshotFullName fullNameResult = LiveUnitTestingDirectoryResolver
                                              .CheckForSession(snapshotFullName);

            // assert
            fullNameResult.Should().NotBeNull();
            fullNameResult.Filename.Should().Be(snapshotFullName.Filename);
            fullNameResult.FolderPath.Should().Be(snapshotFullName.FolderPath);
        }
        public void TryResolveName_TwoFiles_SnapshotTestException()
        {
            // arrange
            ArrangeLiveUnitTestDirectory("Test1.cs", "Test1.cs");
            var testName = "Test1.Foo";

            // act
            Func <SnapshotFullName> action =
                () => LiveUnitTestingDirectoryResolver
                .TryResolveName(testName);

            // assert
            action.Should().Throw <SnapshotTestException>();
        }
        public void TryResolveName_OneFile_FullNameCorrect()
        {
            // arrange
            var tempDir  = ArrangeLiveUnitTestDirectory("Test1.cs");
            var testName = "Test1.Foo";

            // act
            SnapshotFullName fullName = LiveUnitTestingDirectoryResolver
                                        .TryResolveName(testName);

            // assert
            fullName.Should().NotBeNull();
            fullName.FolderPath.Should().Be(Path.Combine(tempDir, "1"));
            fullName.Filename.Should().Be(testName);
        }
        /// <summary>
        /// Evaluates the snapshot full name information.
        /// </summary>
        /// <returns>The full name of the snapshot.</returns>
        public SnapshotFullName ReadSnapshotFullName()
        {
            SnapshotFullName snapshotFullName = null;

            StackFrame[] stackFrames = new StackTrace(true).GetFrames();
            foreach (StackFrame stackFrame in stackFrames)
            {
                MethodBase method = stackFrame.GetMethod();
                if (IsNUnitTestMethod(method))
                {
                    snapshotFullName = new SnapshotFullName(
                        GetCurrentSnapshotName(),
                        Path.GetDirectoryName(stackFrame.GetFileName()));

                    break;
                }

                MethodBase asyncMethod = EvaluateAsynchronMethodBase(method);
                if (IsNUnitTestMethod(asyncMethod))
                {
                    snapshotFullName = new SnapshotFullName(
                        GetCurrentSnapshotName(),
                        Path.GetDirectoryName(stackFrame.GetFileName()));

                    break;
                }
            }

            if (snapshotFullName == null)
            {
                throw new SnapshotTestException(
                          "The snapshot full name could not be evaluated. " +
                          "This error can occur, if you use the snapshot match " +
                          "within a async test helper child method. To solve this issue, " +
                          "use the Snapshot.FullName directly in the unit test to " +
                          "get the snapshot name, then reach this name to your " +
                          "Snapshot.Match method.");
            }

            snapshotFullName = LiveUnitTestingDirectoryResolver
                               .CheckForSession(snapshotFullName);

            return(snapshotFullName);
        }