Beispiel #1
0
        public void AdvertiseLargeNumberOfActionsTests()
        {
            // Test advertising large number of actions.
            var testCases = new[]
            {
                new
                {
                    RequestUri = "/Customers(1)",
                },
            };

            using (TestWebRequest request = service.CreateForInProcessWcf())
            {
                request.StartService();
                t.TestUtil.RunCombinations(testCases, (testCase) =>
                {
                    DataServiceContext ctx = new DataServiceContext(request.ServiceRoot, ODataProtocolVersion.V4);
                    //ctx.EnableAtom = true;
                    //ctx.Format.UseAtom();
                    ctx.ResolveType = name => typeof(Customer);
                    Uri uri         = new Uri(request.ServiceRoot + testCase.RequestUri);
                    QueryOperationResponse <object> qor = (QueryOperationResponse <object>)ctx.Execute <object>(uri);
                    Assert.IsNotNull(qor);
                    IEnumerator <object> entities = qor.GetEnumerator();
                    entities.MoveNext();
                    Assert.IsNotNull(entities.Current);
                    EntityDescriptor ed = ctx.GetEntityDescriptor(entities.Current);
                    Assert.IsNotNull(ed);
                    Assert.IsNotNull(ed.OperationDescriptors);
                    Assert.AreEqual(ed.OperationDescriptors.Count(), TotalNumberOfActions, "Invalid count of total number of advertised actions.");
                });
            }
        }
Beispiel #2
0
        private void VerifyLoadProperty(object entity, string propertyName, WebDataCtxWrapper Context)
        {
            Uri entityUri = null;

            if (Context.TryGetUri(entity, out entityUri))
            {
                Uri  navigationPropertyURI = new Uri(String.Format("{0}/{1}", entityUri.OriginalString, propertyName));;
                Type navPropType           = entity.GetType().GetProperty(propertyName).PropertyType;
                if (navPropType.IsGenericType)
                {
                    navPropType = navPropType.GetGenericArguments()[0];
                }
                WebDataCtxWrapper baselineCOntext = new WebDataCtxWrapper(Context.BaseUri);
                baselineCOntext.Credentials = CredentialCache.DefaultCredentials;
                QueryOperationResponse qoResponse = baselineCOntext.ExecuteOfT(navPropType, navigationPropertyURI) as QueryOperationResponse;
                IEnumerator            enumerator = qoResponse.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    object baselineEntity   = enumerator.Current;
                    Uri    navPropEntityURI = null;
                    if (baselineCOntext.TryGetUri(baselineEntity, out navPropEntityURI))
                    {
                        AstoriaTestLog.IsNotNull(Context.TryGetEntityOfT(navPropType, navPropEntityURI), "Could not find entity in Navigation property ");
                    }
                }
            }
        }
        private static void RunNegativeActionTestWithAtom(TestCase testCase)
        {
            // These tests are specific to Atom and don't apply to JSON Light.
            // Any JSON Light negative cases are covered by ODL reader tests. See ODL tests OperationReaderJsonLightTests and ODataJsonLightDeserializerTests.
            using (TestWebRequest request = TestWebRequest.CreateForInProcessWcf())
                using (PlaybackService.ProcessRequestOverride.Restore())
                {
                    request.ServiceType = typeof(AstoriaUnitTests.Stubs.PlaybackService);
                    request.StartService();

                    PlaybackService.ProcessRequestOverride.Value = (req) =>
                    {
                        // These tests intentionally don't set the base URI of the context, so we need to also remove the xml:base attribute that is automatically
                        // generated by the PayloadGenerator. Otherwise another parsing error will occur before we hit the actual errors we are trying to validate.
                        string payload          = PayloadGenerator.Generate(testCase.ResponsePayloadBuilder, ODataFormat.Atom);
                        string xmlBaseAttribute = @"xml:base=""/""";
                        payload = payload.Remove(payload.IndexOf(xmlBaseAttribute), xmlBaseAttribute.Length);

                        req.SetResponseStreamAsText(payload);
                        req.ResponseHeaders.Add("Content-Type", "application/atom+xml");
                        req.SetResponseStatusCode(200);
                        return(req);
                    };

                    Uri uri = new Uri(request.ServiceRoot + "/" + testCase.RequestUriString);
                    DataServiceContext ctx = new DataServiceContext(null, ODataProtocolVersion.V4);
                    ctx.EnableAtom = true;

                    QueryOperationResponse <CustomerEntity> qor = (QueryOperationResponse <CustomerEntity>)ctx.Execute <CustomerEntity>(uri);
                    Assert.IsNotNull(qor);
                    Assert.IsNull(qor.Error);

                    IEnumerator <CustomerEntity> entities = qor.GetEnumerator();

                    Exception exception = AstoriaTest.TestUtil.RunCatching(delegate()
                    {
                        while (entities.MoveNext())
                        {
                            CustomerEntity c    = entities.Current;
                            EntityDescriptor ed = ctx.GetEntityDescriptor(c);
                            IEnumerable <OperationDescriptor> actualDescriptors = ed.OperationDescriptors;
                        }
                    });

                    Assert.IsNotNull(exception);
                    Assert.AreEqual(testCase.ExpectedErrorMessage, exception.Message);
                }
        }
        private static void RunPositiveTest(ODataFormat format, TestCase testCase)
        {
            MyDSPActionProvider  actionProvider = new MyDSPActionProvider();
            DSPServiceDefinition service        = new DSPServiceDefinition()
            {
                Metadata = Metadata, CreateDataSource = CreateDataSource, ActionProvider = actionProvider
            };

            service.DataServiceBehavior.MaxProtocolVersion = ODataProtocolVersion.V4;

            using (TestWebRequest request = service.CreateForInProcessWcf())
            {
                request.StartService();
                DataServiceContext ctx = new DataServiceContext(request.ServiceRoot, ODataProtocolVersion.V4);
                //ctx.EnableAtom = true;

                Uri uri = new Uri(request.ServiceRoot + "/" + testCase.RequestUriString);

                MakeFinalChangesToTestCase(testCase, format, actionProvider, request);

                if (format == ODataFormat.Json)
                {
                    JsonLightTestUtil.ConfigureContextForJsonLight(ctx, null);
                }
                else
                {
                    //ctx.Format.UseAtom();
                }

                QueryOperationResponse <CustomerEntity> qor = (QueryOperationResponse <CustomerEntity>)ctx.Execute <CustomerEntity>(uri);
                Assert.IsNotNull(qor);
                Assert.IsNull(qor.Error);

                IEnumerator <CustomerEntity> entities = qor.GetEnumerator();

                int expectedDescriptorsPerEntity = 0;

                while (entities.MoveNext())
                {
                    CustomerEntity   c  = entities.Current;
                    EntityDescriptor ed = ctx.GetEntityDescriptor(c);
                    IEnumerable <OperationDescriptor> actualDescriptors = ed.OperationDescriptors;
                    TestEquality(actualDescriptors, testCase.GetExpectedDescriptors(format)[expectedDescriptorsPerEntity++]);
                }
            }
        }
        private void RunPositiveFunctionTest(ODataFormat format, TestCase testCase)
        {
            // All of the functions tests use the PlaybackService since the WCF Data Services server doesn't support functions
            // The PlaybackService itself will not automatically turn Metadata into an absolute URI, so set that to false on all tests.
            // The tests also use absolute URIs for Target, so suppress that as well.
            testCase.AddBaseUriToMetadata = false;
            testCase.AddBaseUriToTarget   = false;

            using (TestWebRequest request = TestWebRequest.CreateForInProcessWcf())
                using (PlaybackService.ProcessRequestOverride.Restore())
                {
                    request.ServiceType = typeof(AstoriaUnitTests.Stubs.PlaybackService);
                    request.StartService();

                    var payloadBuilder = testCase.ResponsePayloadBuilder;
                    PlaybackService.ProcessRequestOverride.Value = (req) =>
                    {
                        string contentType;
                        if (format == ODataFormat.Json)
                        {
                            contentType             = UnitTestsUtil.JsonLightMimeType;
                            payloadBuilder.Metadata = request.BaseUri + "/$metadata#TestService.CustomerEntities/$entity";
                        }
                        else
                        {
                            contentType = UnitTestsUtil.AtomFormat;
                        }

                        req.SetResponseStreamAsText(PayloadGenerator.Generate(payloadBuilder, format));
                        req.ResponseHeaders.Add("Content-Type", contentType);
                        req.SetResponseStatusCode(200);
                        return(req);
                    };

                    testCase.AddBaseUriStringToExpectedDescriptors(request.ServiceRoot.OriginalString, format);

                    Uri uri = new Uri(request.ServiceRoot + "/" + testCase.RequestUriString);
                    DataServiceContext ctx = new DataServiceContext(request.ServiceRoot, ODataProtocolVersion.V4);
                    //ctx.EnableAtom = true;

                    if (format == ODataFormat.Json)
                    {
                        string serviceEdmx = GetServiceEdmxWithOperations(payloadBuilder);
                        JsonLightTestUtil.ConfigureContextForJsonLight(ctx, serviceEdmx);
                    }

                    QueryOperationResponse <CustomerEntity> qor = (QueryOperationResponse <CustomerEntity>)ctx.Execute <CustomerEntity>(uri);
                    Assert.IsNotNull(qor);
                    Assert.IsNull(qor.Error);

                    IEnumerator <CustomerEntity> entities = qor.GetEnumerator();

                    int expectedDescriptorsPerEntity = 0;

                    while (entities.MoveNext())
                    {
                        CustomerEntity   c  = entities.Current;
                        EntityDescriptor ed = ctx.GetEntityDescriptor(c);
                        IEnumerable <OperationDescriptor> actualDescriptors = ed.OperationDescriptors;
                        TestEquality(actualDescriptors, testCase.GetExpectedDescriptors(format)[expectedDescriptorsPerEntity++]);
                    }
                }
        }