Example #1
0
 public void TryGetLastMatch_returns_false_after_no_invocations()
 {
     using (var observer = MatcherObserver.Activate())
     {
         Assert.False(observer.TryGetLastMatch(out _));
     }
 }
Example #2
0
        public void TryGetLastMatch_returns_false_after_a_mock_invocation()
        {
            var mock = Mock.Of <IMockable>();

            using (var observer = MatcherObserver.Activate())
            {
                mock.Method(default, default);
Example #3
0
 public void IsActive_returns_true_when_MatcherObserver_instantiated()
 {
     using (var observer = MatcherObserver.Activate())
     {
         Assert.True(MatcherObserver.IsActive(out _));
     }
 }
Example #4
0
 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);
     }
 }
Example #5
0
 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);
     }
 }
Example #6
0
 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));
     }
 }
Example #7
0
 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));
 }
Example #8
0
 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);
     }
 }
Example #9
0
        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));
        }