예제 #1
0
        protected void AssertThatThrows <TException>(TestDelegate assertThat)
            where TException : ArgumentException
        {
            assertThat.ThrowIfNull(nameof(assertThat));

            Assert.Throws <TException>(assertThat, TestBaseStringResources.ExpectedExceptionOfTypeXBecauseInvalidInput(typeof(TException)));
        }
예제 #2
0
        protected void AssertThatExceptionMessageShouldMatchCustomMessage <TException>(TestDelegate assertThat)
            where TException : Exception
        {
            assertThat.ThrowIfNull(nameof(assertThat));

            var exception = Assert.Throws <TException>(assertThat, TestBaseStringResources.ExpectedExceptionOfTypeXBecauseInvalidInput(typeof(TException)));

            Assert.That(exception.Message.Contains(TestCustomExceptionMessage, StringComparison.InvariantCultureIgnoreCase), TestBaseStringResources.ExpectedMessageToMatchExceptionMessage());
        }
예제 #3
0
        protected void AssertThatExceptionParamNameShouldMatchCustomArgumentName <TException>(TestDelegate assertThat, string customArgumentName)
            where TException : ArgumentException
        {
            assertThat.ThrowIfNull(nameof(assertThat));

            var exception = Assert.Throws <TException>(assertThat, TestBaseStringResources.ExpectedExceptionOfTypeXBecauseInvalidInput(typeof(TException)));

            Assert.AreEqual(customArgumentName, exception.ParamName, TestBaseStringResources.ExpectedInputParameterNameToMatchExceptionParameterName());
        }
예제 #4
0
        protected void AssertThatReturnsInputAsOutputForStruct <T>(Func <T> assertThat, object testValue)
            where T : struct
        {
            assertThat.ThrowIfNull(nameof(assertThat));

            var output = assertThat();

            Assert.AreEqual(testValue, output, TestBaseStringResources.ExpectedOutputIsEqualToInput());
        }
예제 #5
0
        protected void AssertThatReturnsInputAsOutput <T>(Func <T> assertThat, object testValue)
        {
            assertThat.ThrowIfNull(nameof(assertThat));

            var output = assertThat();

            Assert.AreEqual(testValue, output, TestBaseStringResources.ExpectedOutputIsEqualToInput());
            Assert.IsTrue(ReferenceEquals(testValue, output), TestBaseStringResources.ExpectedOutputIsReferenceEqualToInput());
        }
예제 #6
0
        protected void AssertThatExceptionParamNameAndMessageShouldMatch <TException>(TestDelegate assertThat, [CanBeNull] string customArgumentName, string expectedMessage)
            where TException : ArgumentException
        {
            assertThat.ThrowIfNull(nameof(assertThat));
            expectedMessage.ThrowIfNull(nameof(expectedMessage));

            var exception = Assert.Throws <TException>(assertThat, TestBaseStringResources.ExpectedExceptionOfTypeXBecauseInvalidInput(typeof(TException)));

            Assert.AreEqual(customArgumentName, exception.ParamName, TestBaseStringResources.ExpectedInputParameterNameToMatchExceptionParameterName());
            Assert.That(exception.Message.Contains(expectedMessage, StringComparison.InvariantCultureIgnoreCase), TestBaseStringResources.ExpectedMessageToMatchExceptionMessage());
        }
예제 #7
0
        protected void AssertThatExceptionParamNameAndMessageShouldMatchDefaultArgumentName <TException>(TestDelegate assertThat, string defaultMessage)
            where TException : ArgumentException
        {
            assertThat.ThrowIfNull(nameof(assertThat));
            defaultMessage.ThrowIfNull(nameof(defaultMessage));

            var exception = Assert.Throws <TException>(assertThat, TestBaseStringResources.ExpectedExceptionOfTypeXBecauseInvalidInput(typeof(TException)));

            Assert.IsTrue(exception.Message.Contains(defaultMessage, StringComparison.CurrentCulture), TestBaseStringResources.ExpectedMessageToMatchExceptionMessage());
            Assert.AreEqual(DefaultArgumentName, exception.ParamName, TestBaseStringResources.ExpectedInputParameterNameToMatchExceptionParameterName());
        }
예제 #8
0
 public void BaseTearDown()
 {
     TestBaseStringResources = null;
 }
예제 #9
0
 public void BaseSetUp()
 {
     TestBaseStringResources = new TestBaseStringResources(Thread.CurrentThread.CurrentCulture);
 }
예제 #10
0
        protected void AssertThatDoesNotThrow(TestDelegate assertThat)
        {
            assertThat.ThrowIfNull(nameof(assertThat));

            Assert.DoesNotThrow(assertThat, TestBaseStringResources.ExpectedNoExceptionBecauseValidInput());
        }