Ejemplo n.º 1
0
        public void ODataBatchWriterUserExceptionInResponseTests()
        {
            var testCases = new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[][]
            {
                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[]
                { 
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[]
                { 
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[]
                { 
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.QueryOperationResponse(200, string.Empty),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[]
                { 
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.QueryOperationResponse(200, string.Empty),
                    BatchWriterUtils.EndBatch(),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.StartChangeSet(),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.StartChangeSet(),
                    BatchWriterUtils.ChangeSetResponse(200, "Sample payload"),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.StartChangeSet(),
                    BatchWriterUtils.ChangeSetResponse(200, "Sample payload"),
                    BatchWriterUtils.EndChangeSet(),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.StartChangeSet(),
                    BatchWriterUtils.ChangeSetResponse(200, "Sample payload"),
                    BatchWriterUtils.EndChangeSet(),
                    BatchWriterUtils.EndBatch(),
                    BatchWriterUtils.UserException(),
                },
            };

            Exception expectedException = new Exception("User code triggered an exception.");

            var testDescriptors = testCases.Select(tc => new BatchWriterTestDescriptor(this.Settings, tc, expectedException));

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent.Where(tc => !tc.IsRequest),
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent.Where(tc => !tc.IsRequest),
                (testDescriptor, testConfig, payloadTestConfig) =>
                {
                    testConfig = ModifyBatchTestConfig(testConfig, testDescriptor);
                    payloadTestConfig = ModifyPayloadTestConfig(payloadTestConfig, testDescriptor.BaseUri);
                    BatchWriterUtils.WriteAndVerifyBatchPayload(testDescriptor, testConfig, payloadTestConfig, this.Assert);
                });
        }
Ejemplo n.º 2
0
        public void ODataBatchWriterHttpMethodTests()
        {
            Func<string, string, BatchWriterTestDescriptor> createQueryOperation = (method, expectedError) =>
            {
                var invocations = new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                    { 
                        BatchWriterUtils.StartBatch(),
                        BatchWriterUtils.QueryOperation(method, new Uri("http://www.odata.org/")),
                        BatchWriterUtils.EndBatch(),
                    };

                return expectedError == null
                    ? new BatchWriterTestDescriptor(this.Settings, invocations, (Dictionary<string, string>)null)
                    : new BatchWriterTestDescriptor(this.Settings, invocations, expectedError);
            };

            Func<string, string, BatchWriterTestDescriptor> createChangeSetRequest = (method, expectedError) =>
            {
                var invocations = new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.StartChangeSet(),
                    BatchWriterUtils.ChangeSetRequest(method, new Uri("http://www.odata.org/OData/OData.svc/Products"), "1", null, "First sample payload."),
                    BatchWriterUtils.EndChangeSet(),
                    BatchWriterUtils.EndBatch(),
                };

                return expectedError == null
                    ? new BatchWriterTestDescriptor(this.Settings, invocations, (Dictionary<string, string>)null)
                    : new BatchWriterTestDescriptor(this.Settings, invocations, expectedError);
            };

            Func<string, string, BatchWriterTestDescriptor> createChangeSetRequestWithNullContentId = (method, expectedError) =>
            {
                var invocations = new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.StartChangeSet(),
                    BatchWriterUtils.ChangeSetRequest(method, new Uri("http://www.odata.org/OData/OData.svc/Products"), string.Empty, null, "First sample payload."),
                    BatchWriterUtils.EndChangeSet(),
                    BatchWriterUtils.EndBatch(),
                };

                return expectedError == null
                    ? new BatchWriterTestDescriptor(this.Settings, invocations, (Dictionary<string, string>)null)
                    : new BatchWriterTestDescriptor(this.Settings, invocations, expectedError);
            };

            IEnumerable<string> httpMethodValues = new string[]
            {
                Microsoft.OData.Core.ODataConstants.MethodGet,
                Microsoft.OData.Core.ODataConstants.MethodPatch,
                Microsoft.OData.Core.ODataConstants.MethodPost,
                Microsoft.OData.Core.ODataConstants.MethodPut,
            };

            // Now we allow non-query outside of changeset.
            var queryTestCases = httpMethodValues.Select(
                method => new { Method = method, ExpectedErrorMessage = (string)null });

            var changeSetOpTestCases = httpMethodValues.Select(
                method => method == "GET"
                    ? new { Method = "GET", ExpectedErrorMessage = "An invalid HTTP method 'GET' was detected for a request in a change set. Requests in change sets only support the HTTP methods 'POST', 'PUT', 'DELETE', and 'PATCH'." }
                    : new { Method = method, ExpectedErrorMessage = (string)null });

            var changeSetOpWithNoContentIdTestCases = httpMethodValues.Select(
                method => method == "GET"
                    ? new { Method = "GET", ExpectedErrorMessage = "An invalid HTTP method 'GET' was detected for a request in a change set. Requests in change sets only support the HTTP methods 'POST', 'PUT', 'DELETE', and 'PATCH'." }
                    : new { Method = method, ExpectedErrorMessage = "The header with name 'Content-ID' was not present in the header collection of the batch operation." });

            var testDescriptors = queryTestCases.Select(tc => createQueryOperation(tc.Method, tc.ExpectedErrorMessage))
                .Concat(changeSetOpTestCases.Select(tc => createChangeSetRequest(tc.Method, tc.ExpectedErrorMessage)))
                .Concat(changeSetOpWithNoContentIdTestCases.Select(tc => createChangeSetRequestWithNullContentId(tc.Method, tc.ExpectedErrorMessage)));
            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent.Where(tc => tc.IsRequest),
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent.Where(tc => tc.IsRequest),
                (testDescriptor, testConfig, payloadTestConfig) =>
                {
                    testConfig = ModifyBatchTestConfig(testConfig, testDescriptor);
                    payloadTestConfig = ModifyPayloadTestConfig(payloadTestConfig, testDescriptor.BaseUri);
                    BatchWriterUtils.WriteAndVerifyBatchPayload(testDescriptor, testConfig, payloadTestConfig, this.Assert);
                });
        }
Ejemplo n.º 3
0
        public void ODataBatchWriterUserExceptionInRequestTests()
        {
            var testCases = new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[][]
            {
                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[]
                { 
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[]
                { 
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[]
                { 
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.QueryOperation("GET", new Uri("http://www.odata.org/")),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[]
                { 
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.QueryOperation("GET", new Uri("http://www.odata.org/")),
                    BatchWriterUtils.EndBatch(),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.StartChangeSet(),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.StartChangeSet(),
                    BatchWriterUtils.ChangeSetRequest("POST", new Uri("http://www.odata.org/OData/OData.svc/Products"), "1", null, "First sample payload."),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.StartChangeSet(),
                    BatchWriterUtils.ChangeSetRequest("POST", new Uri("http://www.odata.org/OData/OData.svc/Products"), "1", null, "First sample payload."),
                    BatchWriterUtils.EndChangeSet(),
                    BatchWriterUtils.UserException(),
                },

                new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                {
                    BatchWriterUtils.StartBatch(),
                    BatchWriterUtils.StartChangeSet(),
                    BatchWriterUtils.ChangeSetRequest("POST", new Uri("http://www.odata.org/OData/OData.svc/Products"), "1", null, "First sample payload."),
                    BatchWriterUtils.EndChangeSet(),
                    BatchWriterUtils.EndBatch(),
                    BatchWriterUtils.UserException(),
                },
            };

            Exception expectedException = new Exception("User code triggered an exception.");

            var testDescriptors = testCases.Select(tc => new BatchWriterTestDescriptor(this.Settings, tc, expectedException));

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent.Where(tc => tc.IsRequest),
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent.Where(tc => tc.IsRequest),
                (testDescriptor, testConfig, payloadTestConfig) =>
                {
                    testConfig = ModifyBatchTestConfig(testConfig, testDescriptor);
                    payloadTestConfig = ModifyPayloadTestConfig(payloadTestConfig, testDescriptor.BaseUri);
                    BatchWriterUtils.WriteAndVerifyBatchPayload(testDescriptor, testConfig, payloadTestConfig, this.Assert);
                });
        }
Ejemplo n.º 4
0
        public void ODataBatchWriterBaseUriTests()
        {
            Func<Uri, Uri, ExpectedException, BatchWriterTestDescriptor> createInvokation = (uri, baseUri, expectedException) =>
                {
                    var invocations = new BatchWriterTestDescriptor.InvocationAndOperationDescriptor[] 
                    { 
                        BatchWriterUtils.StartBatch(),
                        BatchWriterUtils.QueryOperation("GET", uri),
                        BatchWriterUtils.EndBatch(),
                    };
                    return expectedException == null
                        ? new BatchWriterTestDescriptor(this.Settings, invocations, (Dictionary<string, string>)null, baseUri)
                        : new BatchWriterTestDescriptor(this.Settings, invocations, expectedException, baseUri);
                };

            var testCases = new[]
                {
                    new
                    {
                        Uri = new Uri("http://odata.services.org/OData/OData.svc"),
                        BaseUri = (Uri) null,
                        ExpectedException = (ExpectedException)null
                    },
                    new
                    {
                        Uri = new Uri("http://odata.services.org/OData/OData.svc"),
                        BaseUri = new Uri("http://odata.services.org"),
                        ExpectedException = (ExpectedException)null
                    },
                    new
                    {
                        Uri = new Uri("/OData/OData.svc", UriKind.Relative),
                        BaseUri = new Uri("http://odata.services.org"),
                        ExpectedException = (ExpectedException)null
                    },
                    new
                    {
                        Uri = new Uri("/OData/OData.svc", UriKind.Relative),
                        BaseUri = new Uri("http://odata.services.org"),
                        ExpectedException = (ExpectedException)null
                    },
                    new
                    {
                        Uri = new Uri("/OData/OData.svc", UriKind.Relative),
                        BaseUri = (Uri) null,
                        ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchUtils_RelativeUriUsedWithoutBaseUriSpecified", "/OData/OData.svc")
                    },
                };

            var testDescriptors = testCases.Select(tc => createInvokation(tc.Uri, tc.BaseUri, tc.ExpectedException));

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent.Where(tc => tc.IsRequest),
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent.Where(tc => tc.IsRequest),
                (testDescriptor, testConfig, payloadTestConfig) =>
                {
                    testConfig = ModifyBatchTestConfig(testConfig, testDescriptor);
                    payloadTestConfig = ModifyPayloadTestConfig(payloadTestConfig, testDescriptor.BaseUri);
                    BatchWriterUtils.WriteAndVerifyBatchPayload(testDescriptor, testConfig, payloadTestConfig, this.Assert);
                });
        }