public void UnmetExpectationStackTraces_ShouldOmitTraversalThroughNExpect()
            {
                // Arrange
                // Pre-assert
                // Act
                UnmetExpectationException captured = null;

                try
                {
                    Expect(1)
                    .To.Be.Falsey();
                }
                catch (UnmetExpectationException ex)
                {
                    captured = ex;
                }

                // Assert
                Expect(captured)
                .Not.To.Be.Null();
                var lines = captured.StackTrace.Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

                Expect(lines)
                .To.Contain.Only(1)
                .Item();
                Expect(lines[0])
                .To.Contain(nameof(UnmetExpectationStackTraces_ShouldOmitTraversalThroughNExpect));
            }
示例#2
0
        public void MatcherWhichThrowsUnmetExpectationException_ShouldGetThatExactException()
        {
            // Arrange
            // UnmetExpectationException can only be instatiated within NExpect; however, a little
            //  reflection can get to the internal Throw method
            var method = typeof(Assertions).GetMethods(BindingFlags.Static | BindingFlags.NonPublic)
                         .FirstOrDefault(mi => mi.Name == "Throw" && mi.GetParameters().Length == 1);

            Expect(method).Not.To.Be.Null();
            UnmetExpectationException expected = null;

            try
            {
                method.Invoke(null, new object[] { GetRandomString(10) });
            }
            catch (TargetInvocationException tex)
            {
                expected = tex.InnerException as UnmetExpectationException;
            }

            // Pre-assert
            // Act
            try
            {
                Expect("moo").To.Moo(expected);
            }
            catch (Exception ex)
            {
                Expect(ex).To.Be(expected);
            }

            // Assert
        }
 public static void Moo(
     this ITo <string> to,
     UnmetExpectationException ex)
 {
     to.AddMatcher(actual => throw ex);
 }