Exemple #1
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);
        }
        public void ValidateShortIntegrationFeedReading()
        {
            var initialFeed = new ODataFeed() {Id = new Uri("http://services.odata.org/OData/OData.svc/Products")};
            
            var productItem = new ODataEntry() {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 ODataNavigationLink() {Name = "Category"};

            var categoryItem = new ODataEntry() { 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 ODataNavigationLink() { Name = "Products" };

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

            var testODataReader = new TestODataReader()
            {
               new TestODataReaderItem(ODataReaderState.FeedStart, initialFeed),
               new TestODataReaderItem(ODataReaderState.EntryStart, productItem),
               new TestODataReaderItem(ODataReaderState.NavigationLinkStart, categoryNavigationLink),
               new TestODataReaderItem(ODataReaderState.EntryStart, categoryItem),
               new TestODataReaderItem(ODataReaderState.NavigationLinkStart, productsNavigationLink),
               new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, productsNavigationLink),
               new TestODataReaderItem(ODataReaderState.EntryEnd, categoryItem),
               new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, categoryNavigationLink),
               new TestODataReaderItem(ODataReaderState.NavigationLinkStart, supplierNavigationLink),
               new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, supplierNavigationLink),
               new TestODataReaderItem(ODataReaderState.EntryEnd, productItem),
               new TestODataReaderItem(ODataReaderState.FeedEnd, initialFeed),
            };

            ClientEdmModel clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4);

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

            int readCounter = 0;

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

            readCounter.Should().Be(2);
        }
Exemple #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);
        }
Exemple #4
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);
        }