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 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); }
/// <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); }