public void TryGetLastMatch_returns_false_after_no_invocations() { using (var observer = MatcherObserver.Activate()) { Assert.False(observer.TryGetLastMatch(out _)); } }
public void TryGetLastMatch_returns_false_after_a_mock_invocation() { var mock = Mock.Of <IMockable>(); using (var observer = MatcherObserver.Activate()) { mock.Method(default, default);
public void IsActive_returns_true_when_MatcherObserver_instantiated() { using (var observer = MatcherObserver.Activate()) { Assert.True(MatcherObserver.IsActive(out _)); } }
private static Match GetMatch <T>(Func <T> func) { using (var observer = MatcherObserver.Activate()) { _ = func(); return(observer.TryGetLastMatch(out var match) ? match as Match <T> : null); } }
public void IsActive_returns_right_MatcherObserver_when_MatcherObserver_instantiated() { using (var observer = MatcherObserver.Activate()) { Assert.True(MatcherObserver.IsActive(out var active)); Assert.Same(observer, active); } }
public void Nested_observers_when_disposed_dont_interrupt_outer_observers() { using (var outer = MatcherObserver.Activate()) { using (var inner = MatcherObserver.Activate()) { } _ = CreateMatch(); Assert.True(outer.TryGetLastMatch(out var match)); } }
public void Activations_can_be_nested() { Assert.False(MatcherObserver.IsActive(out var active)); using (var outer = MatcherObserver.Activate()) { Assert.True(MatcherObserver.IsActive(out active)); Assert.Same(outer, active); using (var inner = MatcherObserver.Activate()) { Assert.True(MatcherObserver.IsActive(out active)); Assert.Same(inner, active); } Assert.True(MatcherObserver.IsActive(out active)); Assert.Same(outer, active); } Assert.False(MatcherObserver.IsActive(out active)); }
public void Nested_observers_do_not_share_their_observations() { using (var outer = MatcherObserver.Activate()) { _ = CreateMatch(); Assert.True(outer.TryGetLastMatch(out var outerLastMatchBeforeInner)); using (var inner = MatcherObserver.Activate()) { // The inner observer should not see the outer observer's match: Assert.False(inner.TryGetLastMatch(out _)); _ = CreateMatch(); } // And the outer observer should not see the (disposed) inner observer's match. // Instead, it should still see the same match as the last one as before `inner`: Assert.True(outer.TryGetLastMatch(out var outerLastMatchAfterInnerDisposed)); Assert.Same(outerLastMatchBeforeInner, outerLastMatchAfterInnerDisposed); } }
private Expression <Action <IX> > GetItIsAnyMatchExpression() { Match itIsAnyMatch; using (var observer = MatcherObserver.Activate()) { _ = It.IsAny <int>(); _ = observer.TryGetLastMatch(out itIsAnyMatch); } var x = Expression.Parameter(typeof(IX), "x"); return(Expression.Lambda <Action <IX> >( Expression.Call( x, typeof(IX).GetMethod(nameof(IX.M)), new MatchExpression(itIsAnyMatch)), x)); }