public void AllPublicConfigurationMethodsShouldThrowOnNullInput()
        {
            var pipeline = new DataServiceClientResponsePipelineConfiguration("foo");

            foreach (var publicMethodWithConfigurationArg in pipeline.GetType().GetMethods().Where(mi => mi.ReturnType == typeof(DataServiceClientResponsePipelineConfiguration)))
            {
                MethodInfo methodUnderTest = publicMethodWithConfigurationArg;
                var        parameter       = publicMethodWithConfigurationArg.GetParameters()[0];
                Action     test            = () => methodUnderTest.Invoke(pipeline, BindingFlags.Instance | BindingFlags.Public, null, new object[] { null }, CultureInfo.InvariantCulture);
                var        fluentException = test.ShouldThrow <TargetInvocationException>().WithInnerException <ArgumentNullException>();
                fluentException.And.As <TargetInvocationException>().InnerException.As <ArgumentNullException>().ParamName.Should().Be(parameter.Name);
            }
        }
Ejemplo n.º 2
0
        public void TestConfigureAction <T>(Func <DataServiceClientResponsePipelineConfiguration, ODataReaderState> setup, Action <T> verify) where T : ODataItem, new()
        {
            var item             = new T();
            var responsePipeline = new DataServiceClientResponsePipelineConfiguration(new DataServiceContext(new Uri("http://www.foo.com")));
            var readerState      = setup(responsePipeline);
            var reader           = new TestODataReader()
            {
                new TestODataReaderItem(readerState, item)
            };
            var odataReaderWrapper = ODataReaderWrapper.CreateForTest(reader, responsePipeline);

            odataReaderWrapper.Read();
            verify(item);
        }
Ejemplo n.º 3
0
        public void NoEventShouldBeFiredWhenReadIsFalse()
        {
            bool            eventFiredIncorrectly = false;
            TestODataReader reader = new TestODataReader()
            {
                new TestODataReaderItem(ODataReaderState.ResourceStart, new ODataResource())
            };

            reader.ReadFunc = () => false;
            var responsePipeline = new DataServiceClientResponsePipelineConfiguration(new DataServiceContext(new Uri("http://www.foo.com")));

            responsePipeline.OnEntryStarted((ReadingEntryArgs args) => eventFiredIncorrectly = true);
            var odataReaderWrapper = ODataReaderWrapper.CreateForTest(reader, responsePipeline);

            odataReaderWrapper.Read();

            Assert.IsFalse(eventFiredIncorrectly);
        }
Ejemplo n.º 4
0
        internal List <KeyValuePair <string, object> > TestValidReadWithAllHooked(Func <ODataReader> createOdataReader)
        {
            List <KeyValuePair <string, object> > results = new List <KeyValuePair <string, object> >();
            var odataReader            = createOdataReader();
            DataServiceContext context = new DataServiceContext(new Uri("http://www.foo.com"));
            // context.EnableAtom = true;
            var responsePipeline = new DataServiceClientResponsePipelineConfiguration(context);

            responsePipeline.OnEntryEnded(args => results.Add(new KeyValuePair <string, object>("OnEntryEnded", args)));
            responsePipeline.OnEntryStarted(args => results.Add(new KeyValuePair <string, object>("OnEntryStarted", args)));
            responsePipeline.OnFeedStarted(args => results.Add(new KeyValuePair <string, object>("OnFeedStarted", args)));
            responsePipeline.OnFeedEnded(args => results.Add(new KeyValuePair <string, object>("OnFeedEnded", args)));
            responsePipeline.OnNestedResourceInfoEnded(args => results.Add(new KeyValuePair <string, object>("OnNestedResourceInfoEnded", args)));
            responsePipeline.OnNestedResourceInfoStarted(args => results.Add(new KeyValuePair <string, object>("OnNestedResourceInfoStarted", args)));
            var odataReaderTracker = ODataReaderWrapper.CreateForTest(odataReader, responsePipeline);

            while (odataReaderTracker.Read())
            {
            }

            return(results);
        }
Ejemplo n.º 5
0
        public void ValidateShortIntegrationFeedReading()
        {
            var initialFeed = new ODataResourceSet()
            {
                Id = new Uri("http://services.odata.org/OData/OData.svc/Products")
            };

            var productItem = new ODataResource()
            {
                Id = new Uri("http://services.odata.org/OData/OData.svc/Products(0)")
            };

            productItem.Properties = new ODataProperty[] { new ODataProperty()
                                                           {
                                                               Name = "Id", Value = 0
                                                           } };

            var categoryNavigationLink = new ODataNestedResourceInfo()
            {
                Name = "Category"
            };

            var categoryItem = new ODataResource()
            {
                Id = new Uri("http://services.odata.org/OData/OData.svc/Categories(0)")
            };

            categoryItem.Properties = new ODataProperty[] { new ODataProperty()
                                                            {
                                                                Name = "Id", Value = 0
                                                            } };

            var productsNavigationLink = new ODataNestedResourceInfo()
            {
                Name = "Products"
            };

            var supplierNavigationLink = new ODataNestedResourceInfo()
            {
                Name = "Supplier"
            };

            var testODataReader = new TestODataReader()
            {
                new TestODataReaderItem(ODataReaderState.ResourceSetStart, initialFeed),
                new TestODataReaderItem(ODataReaderState.ResourceStart, productItem),
                new TestODataReaderItem(ODataReaderState.NestedResourceInfoStart, categoryNavigationLink),
                new TestODataReaderItem(ODataReaderState.ResourceStart, categoryItem),
                new TestODataReaderItem(ODataReaderState.NestedResourceInfoStart, productsNavigationLink),
                new TestODataReaderItem(ODataReaderState.NestedResourceInfoEnd, productsNavigationLink),
                new TestODataReaderItem(ODataReaderState.ResourceEnd, categoryItem),
                new TestODataReaderItem(ODataReaderState.NestedResourceInfoEnd, categoryNavigationLink),
                new TestODataReaderItem(ODataReaderState.NestedResourceInfoStart, supplierNavigationLink),
                new TestODataReaderItem(ODataReaderState.NestedResourceInfoEnd, supplierNavigationLink),
                new TestODataReaderItem(ODataReaderState.ResourceEnd, productItem),
                new TestODataReaderItem(ODataReaderState.ResourceSetEnd, initialFeed),
            };

            ClientEdmModel clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4);

            var responsePipeline   = new DataServiceClientResponsePipelineConfiguration(new DataServiceContext());
            var odataReaderWrapper = ODataReaderWrapper.CreateForTest(testODataReader, responsePipeline);
            FeedAndEntryMaterializerAdapter reader = new FeedAndEntryMaterializerAdapter(ODataFormat.Json, odataReaderWrapper, clientEdmModel, MergeOption.OverwriteChanges);

            int readCounter = 0;

            while (reader.Read())
            {
                readCounter++;
            }

            readCounter.Should().Be(1);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Prevents a default instance of the <see cref="ODataReaderWrapper" /> class from being created.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="responsePipeline">The data service response pipeling configuration object.</param>
 private ODataReaderWrapper(ODataReader reader, DataServiceClientResponsePipelineConfiguration responsePipeline)
 {
     Debug.Assert(reader != null, "reader!=null");
     this.reader           = reader;
     this.responsePipeline = responsePipeline;
 }
Ejemplo n.º 7
0
 internal static ODataReaderWrapper CreateForTest(ODataReader reader, DataServiceClientResponsePipelineConfiguration responsePipeline)
 {
     return(new ODataReaderWrapper(reader, responsePipeline));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates and Wraps an ODataReader for feeds or entries.
        /// </summary>
        /// <param name="messageReader">The message reader.</param>
        /// <param name="messageType">The message type.</param>
        /// <param name="expectedType">The expected EDM type.</param>
        /// <param name="responsePipeline">The data service response pipeling configuration object.</param>
        /// <returns>A reader.</returns>
        internal static ODataReaderWrapper Create(ODataMessageReader messageReader, ODataPayloadKind messageType, IEdmType expectedType, DataServiceClientResponsePipelineConfiguration responsePipeline)
        {
            IEdmEntityType entityType = expectedType as IEdmEntityType;

            if (messageType == ODataPayloadKind.Entry)
            {
                return(new ODataReaderWrapper(messageReader.CreateODataEntryReader(entityType), responsePipeline));
            }

            return(new ODataReaderWrapper(messageReader.CreateODataFeedReader(entityType), responsePipeline));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Prevents a default instance of the <see cref="ODataReaderWrapper" /> class from being created.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="responsePipeline">The data service response pipeling configuration object.</param>
 private ODataReaderWrapper(ODataReader reader, DataServiceClientResponsePipelineConfiguration responsePipeline)
 {
     Debug.Assert(reader != null, "reader!=null");
     this.reader = reader;
     this.responsePipeline = responsePipeline;
 }
Ejemplo n.º 10
0
 internal static ODataReaderWrapper CreateForTest(ODataReader reader, DataServiceClientResponsePipelineConfiguration responsePipeline)
 {
     return new ODataReaderWrapper(reader, responsePipeline);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates and Wraps an ODataReader for feeds or entries.
        /// </summary>
        /// <param name="messageReader">The message reader.</param>
        /// <param name="messageType">The message type.</param>
        /// <param name="expectedType">The expected EDM type.</param>
        /// <param name="responsePipeline">The data service response pipeling configuration object.</param>
        /// <returns>A reader.</returns>
        internal static ODataReaderWrapper Create(ODataMessageReader messageReader, ODataPayloadKind messageType, IEdmType expectedType, DataServiceClientResponsePipelineConfiguration responsePipeline)
        {
            IEdmEntityType entityType = expectedType as IEdmEntityType;
            if (messageType == ODataPayloadKind.Entry)
            {
                return new ODataReaderWrapper(messageReader.CreateODataEntryReader(entityType), responsePipeline);
            }

            return new ODataReaderWrapper(messageReader.CreateODataFeedReader(entityType), responsePipeline);
        }