Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        protected void AssertHasCorrectInnerException(Exception e, Exception expectedInnerException)
        {
            e.ThrowIfNull(nameof(e));

            Assert.IsNotNull(e.InnerException, TestBaseStringResources.ExpectedPropertyToBeSet(nameof(e.InnerException)));
            AssertExceptionsEqual(e.InnerException, expectedInnerException);
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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)));
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
        protected void AssertHasNoInnerException(Exception e)
        {
            e.ThrowIfNull(nameof(e));

            Assert.IsNull(e.InnerException, TestBaseStringResources.ExpectedPropertyToBeNotSet(nameof(e.InnerException)));
        }
Ejemplo n.º 7
0
        protected void AssertHasNoParamName(ArgumentException e)
        {
            e.ThrowIfNull(nameof(e));

            Assert.IsNull(e.ParamName, TestBaseStringResources.ExpectedPropertyToBeNotSet(nameof(e.ParamName)));
        }
Ejemplo n.º 8
0
        protected void AssertHasSomeMessage(Exception e)
        {
            e.ThrowIfNull(nameof(e));

            Assert.IsNotNull(e.Message, TestBaseStringResources.ExpectedPropertyToBeSet(nameof(e.Message)));
        }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
        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));
        }