当前位置: 首页>>代码示例>>C#>>正文


C# TestCase.GetExpectedDescriptors方法代码示例

本文整理汇总了C#中TestCase.GetExpectedDescriptors方法的典型用法代码示例。如果您正苦于以下问题:C# TestCase.GetExpectedDescriptors方法的具体用法?C# TestCase.GetExpectedDescriptors怎么用?C# TestCase.GetExpectedDescriptors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestCase的用法示例。


在下文中一共展示了TestCase.GetExpectedDescriptors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunPositiveFunctionTest

        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++]);
                }
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:63,代码来源:OperationDescriptorTests.cs

示例2: RunPositiveTest

        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++]);
                }
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:42,代码来源:OperationDescriptorTests.cs


注:本文中的TestCase.GetExpectedDescriptors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。