protected void AssertHasCorrectParamName(ArgumentException e, string expectedParameterName) { e.ThrowIfNull(nameof(e)); Assert.IsNotNull(e.ParamName, TestBaseStringResources.ExpectedPropertyToBeSet(nameof(e.ParamName))); Assert.AreEqual(e.ParamName, expectedParameterName, TestBaseStringResources.ExpectedPropertyToMatch(nameof(e.ParamName), e.ParamName, expectedParameterName)); }
protected void AssertHasCorrectInnerException(Exception e, Exception expectedInnerException) { e.ThrowIfNull(nameof(e)); Assert.IsNotNull(e.InnerException, TestBaseStringResources.ExpectedPropertyToBeSet(nameof(e.InnerException))); AssertExceptionsEqual(e.InnerException, expectedInnerException); }
protected void AssertHasCorrectMessage(Exception e, string expectedMessage) { e.ThrowIfNull(nameof(e)); Assert.IsNotNull(e.Message, TestBaseStringResources.ExpectedPropertyToBeSet(nameof(e.Message))); Assert.IsTrue(e.Message.Contains(expectedMessage, StringComparison.InvariantCulture), TestBaseStringResources.ExpectedPropertyToMatch(nameof(e.Message), e.Message, expectedMessage)); }
protected void AssertArgumentExceptionSerializesCorrectly <TException>(TException exception, Action <TException> assertExceptionState) where TException : ArgumentException { exception.ThrowIfNull(nameof(exception)); assertExceptionState.ThrowIfNull(nameof(assertExceptionState)); assertExceptionState(exception); string exceptionToString = exception.ToString(); exception = SerializeAndDeserializeException(exception); assertExceptionState(exception); Assert.AreEqual(exceptionToString, exception.ToString(), TestBaseStringResources.ExpectedExceptionOfTypeXToBeSerializedAndDeserializedCorrectly(typeof(ArgumentEmptyException))); }
protected void AssertExceptionsEqual([CanBeNull, ValidatedNotNull] Exception e, [CanBeNull, ValidatedNotNull] Exception expectedException) { if (e is null && expectedException is null) { return; } Assert.IsFalse(e is null && !(expectedException is null)); Assert.IsFalse(!(e is null) && expectedException is null); Assert.AreEqual(e.StackTrace, expectedException.StackTrace, TestBaseStringResources.ExpectedPropertyToMatch(nameof(e.StackTrace), e.StackTrace, expectedException.StackTrace)); Assert.AreEqual(e.Message, expectedException.Message, TestBaseStringResources.ExpectedPropertyToMatch(nameof(e), e.Message, expectedException.Message)); Assert.AreEqual(e.Source, expectedException.Source, TestBaseStringResources.ExpectedPropertyToMatch(nameof(e), e.Source, expectedException.Source)); Assert.AreEqual(e.InnerException, expectedException.InnerException, TestBaseStringResources.ExpectedPropertyToMatch(nameof(e), e.InnerException, expectedException.InnerException)); Assert.AreEqual(e.Data, expectedException.Data, TestBaseStringResources.ExpectedPropertyToMatch(nameof(e), e.Data, expectedException.Data)); Assert.AreEqual(e.HResult, expectedException.HResult, TestBaseStringResources.ExpectedPropertyToMatch(nameof(e), e.HResult, expectedException.HResult)); }
protected void AssertHasNoInnerException(Exception e) { e.ThrowIfNull(nameof(e)); Assert.IsNull(e.InnerException, TestBaseStringResources.ExpectedPropertyToBeNotSet(nameof(e.InnerException))); }
protected void AssertHasNoParamName(ArgumentException e) { e.ThrowIfNull(nameof(e)); Assert.IsNull(e.ParamName, TestBaseStringResources.ExpectedPropertyToBeNotSet(nameof(e.ParamName))); }
protected void AssertHasSomeMessage(Exception e) { e.ThrowIfNull(nameof(e)); Assert.IsNotNull(e.Message, TestBaseStringResources.ExpectedPropertyToBeSet(nameof(e.Message))); }
public void All_exception_types_must_follow_exception_naming_conventions(Type exceptionTestType) { exceptionTestType.ThrowIfNull(nameof(exceptionTestType)); const string exceptionSuffix = "Exception"; Assert.IsTrue(exceptionTestType.Name.EndsWith(exceptionSuffix, StringComparison.Ordinal), TestBaseStringResources.ExpectedCustomExceptionsToFollowNamingConvention(exceptionSuffix)); }
public void All_exception_types_must_be_marked_with_SerializableAttribute(Type exceptionTestType) { exceptionTestType.ThrowIfNull(nameof(exceptionTestType)); var serializableAttributeType = typeof(SerializableAttribute); Assert.IsTrue(TypeIsMarkedWithAttribute(exceptionTestType, serializableAttributeType), TestBaseStringResources.ExpectedTypeToBeMarkedWithAttributeOfType(exceptionTestType, serializableAttributeType)); }