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; }
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); }
protected override void Because() { _method = delegate { _concern.AddContextFor(_testFixtureType); }; _exception = _method.GetException(); }
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); }
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)); }
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.")); }
// Methods public static Exception GetException(this MethodThatThrows method) { Exception exception = null; try { method(); } catch (Exception exception2) { exception = exception2; } return(exception); }
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); }
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); }
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); }
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 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, "")); }
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; }
protected override void Because() { exception = () => _fileSystem.Save(_pathStream, _path, false); }