public void AllMethodsMustThrow() { var listener = new InvalidatedTransactionListener(); MethodInfo[] methods = typeof(InvalidatedTransactionListener).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); Assert.That(methods.Length, Is.EqualTo(38)); foreach (var method in methods) { var concreteMethod = method.Name == "FilterQueryResult" || method.Name == "FilterCustomQueryResult" ? method.MakeGenericMethod(typeof(Order)) : method; object[] arguments = Array.ConvertAll(concreteMethod.GetParameters(), p => GetDefaultValue(p.ParameterType)); ExpectException( typeof(InvalidOperationException), "The transaction can no longer be used because it has been discarded.", listener, concreteMethod, arguments); } }
public void ListenerIsSerializable() { var listener = new InvalidatedTransactionListener(); InvalidatedTransactionListener deserializedListener = Serializer.SerializeAndDeserialize(listener); Assert.That(deserializedListener, Is.Not.Null); }
private void ExpectException( Type expectedExceptionType, string expectedMessage, InvalidatedTransactionListener listener, MethodInfo method, object[] arguments) { try { method.Invoke(listener, arguments); Assert.Fail(BuildErrorMessage(expectedExceptionType, method, arguments, "the call succeeded.")); } catch (TargetInvocationException tex) { Exception ex = tex.InnerException; if (ex.GetType() == expectedExceptionType) { if (ex.Message == expectedMessage) { return; } else { Assert.Fail( BuildErrorMessage( expectedExceptionType, method, arguments, string.Format("the message was incorrect.\nExpected: {0}\nWas: {1}", expectedMessage, ex.Message))); } } else { Assert.Fail(BuildErrorMessage(expectedExceptionType, method, arguments, "the exception type was " + ex.GetType() + ".\n" + ex)); } } }