public BatchWriterTestDescriptor(Settings settings, InvocationAndOperationDescriptor[] invocationsAndOperationDescriptors, ExpectedException expectedException, Uri baseUri = null)
        {
            ExceptionUtilities.CheckArgumentNotNull(expectedException, "expectedException");

            this.TestDescriptorSettings = settings;
            this.invocationsAndOperationDescriptors = invocationsAndOperationDescriptors;
            this.expectedResultCallback = CreateExpectedErrorResultCallback(null, null, expectedException, this.TestDescriptorSettings.ExpectedResultSettings);
            this.baseUri = baseUri;
        }
        /// <summary>
        /// Creates an ExpectedException for ODataErrorException typed exceptions.
        /// </summary>
        /// <param name="expectedODataError">The expected value of the exception's Error property.</param>
        /// <param name="resourceKey">The resource key to look up the expected message.</param>
        /// <param name="messageArguments">Arguments for the expected exception message.</param>
        /// <returns>An ExpectedException for this expected ODataException.</returns>
        public static ExpectedException ODataErrorException(ODataError expectedODataError, string resourceKey, params string[] messageArguments)
        {
            var expectedException = new ExpectedException(typeof(ODataErrorException), GetResourceVerifier(DataFxAssemblyRef.OData).CreateExpectedError(resourceKey, messageArguments));
            expectedException.CustomVerification = 
                (e) =>
                {
                    if (!ODataObjectModelValidationUtils.AreEqual(expectedODataError, ((ODataErrorException)e).Error))
                    {
                        throw new DataComparisonException("Expected ODataError instances to be equal.");
                    }
                };

            return expectedException;
        }
        /// <summary>
        /// Creates an ExpectedException for ODataErrorException typed exceptions.
        /// </summary>
        /// <param name="expectedODataError">The expected value of the exception's Error property.</param>
        /// <returns>An ExpectedException for this expected ODataException.</returns>
        public static ExpectedException ODataErrorException(ODataError expectedODataError)
        {
            var expectedException = new ExpectedException(typeof(ODataErrorException));
            expectedException.CustomVerification =
                (e) =>
                {
                    if (!ODataObjectModelValidationUtils.AreEqual(expectedODataError, ((ODataErrorException)e).Error))
                    {
                        throw new DataComparisonException("Expected ODataError instances to be equal.");
                    }
                };

            return expectedException;
        }
示例#4
0
        /// <summary>
        /// Verifies that the actual exception matches expectations including type, message (from resources) and parameters.
        /// </summary>
        /// <param name="expected">The expected exception details.</param>
        /// <param name="actual">The actual exception to verify.</param>
        public void VerifyExceptionResult(ExpectedException expected, Exception actual)
        {
            ExceptionUtilities.CheckArgumentNotNull(expected, "expected");
            ExceptionUtilities.CheckArgumentNotNull(actual, "actual");

            this.AssertionHandler.AreEqual(expected.ExpectedExceptionType, actual.GetType(), "Unexpected exception type caught");

            // Resource lookup not supported on Silverlight or Phone platforms.
#if !SILVERLIGHT && !WINDOWS_PHONE
            if (expected.ExpectedMessage != null)
            {
                expected.ExpectedMessage.VerifyMatch(null, actual.Message, expected.ExactMatch);
            }
#endif

            if (expected.CustomVerification != null)
            {
                expected.CustomVerification(actual);
            }
        }
 public CollectionWriterTestDescriptor(Settings settings, string collectionName, object[] payloadItems, ExpectedException expectedException, IEdmModel model)
 {
     this.TestDescriptorSettings = settings;
     this.collectionName = collectionName;
     this.payloadItems = payloadItems;
     bool errorOnly;
     this.invocations = CreateInvocations(payloadItems, out errorOnly);
     this.expectedResultCallback = CollectionWriterUtils.CreateExpectedErrorResultCallback(collectionName, tc => expectedException, this.TestDescriptorSettings.ExpectedResultSettings);
     this.Model = model;
 }
示例#6
0
        /// <summary>
        /// Asserts that the given action throws the specified exception type.
        /// </summary>
        /// <param name="action">Action to try.</param>
        /// <param name="expectedException">The expected exception.</param>
        /// <param name="exceptionVerifier">The exception verifier.</param>
        public static void ExpectedException(this AssertionHandler assert, Action action, ExpectedException expectedException, IExceptionVerifier exceptionVerifier)
        {
            ExceptionUtilities.CheckArgumentNotNull(assert, "assert");
            ExceptionUtilities.CheckArgumentNotNull(action, "action");
            ExceptionUtilities.CheckArgumentNotNull(exceptionVerifier, "exceptionVerifier");

            Exception exception = RunCatching(action);

            if (exception == null && expectedException == null)
            {
                return;
            }
            else if (exception == null)
            {
                assert.IsNotNull(exception,
                                 "Expected exception of type '{0}' with message resource ID '{1}' but none was thrown.",
                                 expectedException.ExpectedExceptionType.ToString(),
                                 expectedException.ExpectedMessage == null ? "<null>" : expectedException.ExpectedMessage.ResourceIdentifier);
            }
            else if (expectedException == null)
            {
                assert.IsNotNull(expectedException,
                                 "Did not expect an exception but an exception of type '{0}' with message '{1}' was thrown.",
                                 exception.GetType().ToString(),
                                 exception.Message);
            }

            exception = TestExceptionUtils.UnwrapAggregateException(exception, assert);
            exceptionVerifier.VerifyExceptionResult(expectedException, exception);
        }
        public BatchWriterTestDescriptor(Settings settings, InvocationAndOperationDescriptor[] invocationsAndOperationDescriptors, int? maxPartsPerBatch, int? maxOperationsPerChangeset, ExpectedException expectedException)
        {
            ExceptionUtilities.CheckArgumentNotNull(expectedException, "expectedExceptionMessage");

            this.TestDescriptorSettings = settings;
            this.invocationsAndOperationDescriptors = invocationsAndOperationDescriptors;
            this.expectedResultCallback = CreateExpectedErrorResultCallback(null, null, expectedException, this.TestDescriptorSettings.ExpectedResultSettings);
            this.maxPartsPerBatch = maxPartsPerBatch;
            this.maxOperationsPerChangeset = maxOperationsPerChangeset;
        }
        private static PayloadWriterTestDescriptor.WriterTestExpectedResultCallback CreateExpectedErrorResultCallback(
            string expectedExceptionMessage,
            Exception exception,
            ExpectedException expectedException,
            WriterTestExpectedResults.Settings settings)
        {
            return (testConfiguration) =>
            {
                string errorMessage = expectedExceptionMessage;
                Exception error = exception;

                return new BatchWriterTestExpectedResults(settings)
                {
                    ExpectedODataExceptionMessage = errorMessage,
                    ExpectedException = error,
                    ExpectedException2 = expectedException,
                };
            };
        }