コード例 #1
0
        public void ETagValidationTest()
        {
            string[] etagValues = new string[]
            {
                "\"",
                "W/\"",
                "W/",
                "etagValue",
                "etagValue\"",
                "\"etagValue",
                "etag\"Value",
                "\"etagV\"alue\"",
                "W/etagValue",
                "W/etagValue\"",
                "W/\"etagValue",
                "W/etag\"Value",
                "W/\"etagV\"alue\""
            };

            var testDescriptors = etagValues.SelectMany(etagValue =>
            {
                var stream1 = new ODataStreamReferenceValue()
                {
                    ReadLink = new Uri("http://foo/", UriKind.RelativeOrAbsolute), EditLink = new Uri("http://foo/", UriKind.RelativeOrAbsolute), ContentType = "customType/customSubtype", ETag = etagValue
                };

                WriterTestDescriptor.WriterTestExpectedResultCallback formatSelector =
                    testConfiguration => (WriterTestExpectedResults) new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings);

                return(new[]
                {
                    // entity etag
                    new PayloadWriterTestDescriptor <ODataItem>(
                        this.Settings,
                        new ODataResource()
                    {
                        ETag = etagValue, Properties = ObjectModelUtils.CreateDefaultPrimitiveProperties(), SerializationInfo = SerializationInfo
                    },
                        formatSelector),
                    // default stream etag
                    new PayloadWriterTestDescriptor <ODataItem>(
                        this.Settings,
                        new ODataResource()
                    {
                        MediaResource = stream1, Properties = ObjectModelUtils.CreateDefaultPrimitiveProperties(), SerializationInfo = SerializationInfo
                    },
                        formatSelector),
                    // named stream etag
                    new PayloadWriterTestDescriptor <ODataItem>(
                        this.Settings,
                        new ODataResource()
                    {
                        Properties = new ODataProperty[] { new ODataProperty()
                                                           {
                                                               Name = "Stream1", Value = stream1
                                                           } }, SerializationInfo = SerializationInfo
                    },
                        formatSelector)
                    {
                        // No stream properties in requests
                        SkipTestConfiguration = tc => tc.IsRequest
                    },
                });
            });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.WriterTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                testConfiguration = testConfiguration.Clone();
                testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri);

                TestWriterUtils.WriteAndVerifyODataPayload(testDescriptor, testConfiguration, this.Assert, this.Logger);
            });
        }