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


C# BaseEntity.Union方法代码示例

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


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

示例1: BaseEntity

        public void ODataTypeAnnotationAppearsForAllEntitiesInFullMetadataAndForDerivedEntityTypesInFullAndMinimalMetadata(string acceptHeader)
        {
            //Arrange
            BaseEntity[] baseEntities = new BaseEntity[] { new BaseEntity(1), new BaseEntity(2), new BaseEntity(3), new BaseEntity(4), new BaseEntity(5), new BaseEntity(6), new BaseEntity(7) }; //InstanceCreator.CreateInstanceOf<BaseEntity[]>(new Random(RandomSeedGenerator.GetRandomSeed()));
            DerivedEntity[] derivedEntities = new DerivedEntity[] { new DerivedEntity(8), new DerivedEntity(9), new DerivedEntity(10), new DerivedEntity(11), new DerivedEntity(12), new DerivedEntity(13), new DerivedEntity(14) };  //InstanceCreator.CreateInstanceOf<DerivedEntity[]>(new Random(RandomSeedGenerator.GetRandomSeed()));
            BaseEntity[] entities = baseEntities.Union(derivedEntities, new BaseEntity.IdEqualityComparer()).ToArray();
            string requestUrl = BaseAddress.ToLowerInvariant() + "/Inheritance/BaseEntity/";
            string expectedTypeName;
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            request.SetAcceptHeader(acceptHeader);

            //Act
            HttpResponseMessage response = Client.SendAsync(request).Result;
            JObject result = response.Content.ReadAsJObject();

            //Assert
            JArray returnedEntities = (JArray)result["value"];
            for (int i = 0; i < returnedEntities.Count; i++)
            {
                JObject returnedEntity = (JObject)returnedEntities[i];
                BaseEntity originalEntity = entities.FirstOrDefault(x => x.Id == (int)returnedEntity["Id"]);
                Assert.NotNull(originalEntity);
                if (acceptHeader.Contains("nometadata"))
                {
                    JsonAssert.DoesNotContainProperty("odata.type", returnedEntity);
                }
                else if (acceptHeader.Contains("fullmetadata"))
                {
                    expectedTypeName = originalEntity.GetType().FullName;
                    JsonAssert.Equal(expectedTypeName, "odata.type", returnedEntity);
                }
                else
                {
                    if (originalEntity is DerivedEntity)
                    {
                        expectedTypeName = originalEntity.GetType().FullName;
                        JsonAssert.Equal(expectedTypeName, "odata.type", returnedEntity);
                    }
                    else
                    {
                        JsonAssert.DoesNotContainProperty("odata.type", returnedEntity);
                    }
                }
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:45,代码来源:EntryMetadataTests.cs


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