Example #1
0
        public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method)
        {
            Exception anObject = method.GetException();

            Assert.IsNotNull(anObject);
            Assert.AreEqual(exceptionType, anObject.GetType());
            return(anObject);
        }
        public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method)
        {
            Exception exception = method.GetException();

                Assert.IsNotNull(exception);
                Assert.AreEqual(exceptionType, exception.GetType());

                return exception;
        }
Example #3
0
        public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method)
        {
            Exception exception = method.GetException();

            Assert.IsNotNull(exception, $"{exceptionType.Name} was not thrown");
            Assert.AreEqual(exceptionType, exception.GetType());

            return(exception);
        }
Example #4
0
        protected override void Because()
        {
            _method = delegate
            {
                _concern.AddContextFor(_testFixtureType);
            };

            _exception = _method.GetException();
        }
Example #5
0
        public void ShouldThrowExceptionWhenNoMatchingConstructorCanBeFoundForStrictMock()
        {
            MethodThatThrows mtt = delegate()
            {
                Interaction  i       = new Interaction();
                MockableBase fooBase = i.CreateStrictMock <MockableBase>(1, 2, 3);
            };

            Specify.ThrownBy(mtt).ShouldBeOfType(typeof(NoMatchingConstructorException));
        }
        public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method)
        {
            Exception exception = method.GetException();

            if (exception == null)
            {
                Assert.Fail("Method " + method.Method.Name + " failed to throw expected exception [" + exceptionType.Name + "].");
            }
            Assert.AreEqual(exceptionType, exception.GetType());

            return(exception);
        }
Example #7
0
        public void When_a_resolutionException_has_an_inner_should_return_the_innerException()
        {
            var tinyIoCContainer = new TinyIoC.TinyIoCContainer();

            tinyIoCContainer.Register <IFoo, Foo2>();

            MethodThatThrows m = () => tinyIoCContainer.Resolve <IFoo>().ShouldNotBeNull();

            Exception exception = StatLight.Console.Program.ResolveNonTinyIocException(m.GetException());

            exception.ShouldNotBeNull()
            .ShouldBeOfType(typeof(StatLightException));
        }
Example #8
0
        public static Exception Exception(MethodThatThrows method)
        {
            try
            {
                method();
            }
            catch (Exception e)
            {
                return e;
            }

            return
                new DidNotThrowAnExceptionException(string.Format("Expected call to throw an exception, but it did not."));
        }
Example #9
0
        // Methods
        public static Exception GetException(this MethodThatThrows method)
        {
            Exception exception = null;

            try
            {
                method();
            }
            catch (Exception exception2)
            {
                exception = exception2;
            }
            return(exception);
        }
Example #10
0
        public static Exception Exception(MethodThatThrows method)
        {
            try
            {
                method();
            }
            catch (Exception e)
            {
                return(e);
            }

            return
                (new DidNotThrowAnExceptionException(string.Format("Expected call to throw an exception, but it did not.")));
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var method = new MethodThatThrows();

            try
            {
                var result = method.Run();
                ShowDialog("Result", $"Result = {result}");
            }
            catch (SEHException ex)
            {
                ShowDialog("Error", ex.Message);
            }
            ShowDialog("Log", method.Log);
        }
Example #12
0
        static void Main(string[] args)
        {
            var method = new MethodThatThrows();

            try
            {
                var result = method.Run();
                Console.WriteLine($"Result = {result}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.GetType()} {ex.Message}");
            }

            Console.WriteLine(method.Log);
        }
Example #13
0
        public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method)
        {
            Exception exception = null;

            try
            {
                method();
            }
            catch (Exception e)
            {
                e.GetType().ShouldBe(exceptionType);
                exception = e;
            }

            exception.ShouldNotBeNull("Expected {0} to be thrown.".ToFormat(exceptionType.FullName));

            return(exception);
        }
Example #14
0
        public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method)
        {
            Exception exception = null;

            try {
                method();
            }
            catch (Exception e) {
                Assert.AreEqual(exceptionType, e.GetType());
                exception = e;
            }

            if (exception == null) {
                Assert.Fail(String.Format("Expected {0} to be thrown.", exceptionType.FullName));
            }

            return exception;
        }
Example #15
0
        public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method)
        {
            Exception exception = null;

            try
            {
                method();
            }
            catch (Exception e)
            {
                e.GetType().ShouldBe(exceptionType);
                exception = e;
            }

            Assert.False(exception == null, String.Format("Expected {0} to be thrown.", exceptionType.FullName));

            return(exception);
        }
        public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method)
        {
            Exception exception = null;

            try {
                method();
            } catch (Exception e) {
                Assert.AreEqual(exceptionType, e.GetType());
                exception = e;
            }

            if (exception == null)
            {
                Assert.Fail(string.Format("Expected {0} to be thrown", exceptionType.FullName));
            }

            return(exception);
        }
        public static Exception ShouldNotBeThrownBy(this Type exceptionType, MethodThatThrows method)
        {
            Exception exception = null;

            try
            {
                method();
            }

            catch (Exception e)
            {
                Assert.AreNotEqual(exceptionType, e.GetType(), e.ToString());
                exception = e;
            }

            if (exception != null)
            {
                Assert.Fail("Expected {0} to not be thrown.", exceptionType.FullName);
            }

            return(exception);
        }
        public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method, string description)
        {
            Exception exception = null;

            try
            {
                method();
            }
            catch (Exception e)
            {
                e = (e is TargetInvocationException) ? e.InnerException : e;

                Assert.AreEqual(exceptionType, e.GetType(), e.ToString());
                exception = e;
            }

            if (exception == null)
            {
                Assert.Fail(String.Format("Expected {0} to be thrown{1}.", exceptionType.FullName, description == null ? "" : "by " + description));
            }

            return(exception);
        }
 public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method)
 {
     return(ShouldBeThrownBy(exceptionType, method, ""));
 }
Example #20
0
        public void Context()
        {
            _method = delegate { throw new ApplicationException(); };

            _exception = _method.GetException();
        }
        public static Exception Ignore(this Type exceptionType, MethodThatThrows method)
        {
            Exception exception = method.GetException();

            return(exception);
        }
 public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method)
 {
     Exception anObject = method.GetException();
     Assert.IsNotNull(anObject);
     Assert.AreEqual(exceptionType, anObject.GetType());
     return anObject;
 }
Example #23
0
 protected override void Because()
 {
     exception = () => _fileSystem.Save(_pathStream, _path, false);
 }