本文整理汇总了C#中System.Web.OData.Formatter.Serialization.SelectExpandNode类的典型用法代码示例。如果您正苦于以下问题:C# SelectExpandNode类的具体用法?C# SelectExpandNode怎么用?C# SelectExpandNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SelectExpandNode类属于System.Web.OData.Formatter.Serialization命名空间,在下文中一共展示了SelectExpandNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateEntry
public override ODataEntry CreateEntry(SelectExpandNode selectExpandNode, EntityInstanceContext entityInstanceContext)
{
ODataEntry entry = base.CreateEntry(selectExpandNode, entityInstanceContext);
Document document = entityInstanceContext.EntityInstance as Document;
if (entry != null && document != null)
{
// annotate the document with the score.
entry.InstanceAnnotations.Add(new ODataInstanceAnnotation("org.northwind.search.score", new ODataPrimitiveValue(document.Score)));
}
return entry;
}
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:13,代码来源:CustomODataFormatter.cs
示例2: GetPropertiesToBeSelected_Selects_ExpectedProperties_OnCustomer
[InlineData("ID", "Orders($select=ID),Orders($expand=Customer($select=ID))", true, "ID")] // deep expand and selects
public void GetPropertiesToBeSelected_Selects_ExpectedProperties_OnCustomer(
string select, string expand, bool specialCustomer, string structuralPropertiesToSelect)
{
// Arrange
SelectExpandClause selectExpandClause =
new ODataUriParser(_model.Model, serviceRoot: null).ParseSelectAndExpand(select, expand, _model.Customer, _model.Customers);
IEdmEntityType entityType = specialCustomer ? _model.SpecialCustomer : _model.Customer;
// Act
SelectExpandNode selectExpandNode = new SelectExpandNode(selectExpandClause, entityType, _model.Model);
var result = selectExpandNode.SelectedStructuralProperties;
// Assert
Assert.Equal(structuralPropertiesToSelect, String.Join(",", result.Select(p => p.Name).OrderBy(n => n)));
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:16,代码来源:SelectExpandNodeTest.cs
示例3: GetPropertiesToBeSelected_Selects_ExpectedProperties_OnCustomer
[InlineData("ID", "Orders($select=ID),Orders($expand=Customer($select=ID))", true, "ID")] // deep expand and selects
public void GetPropertiesToBeSelected_Selects_ExpectedProperties_OnCustomer(
string select, string expand, bool specialCustomer, string structuralPropertiesToSelect)
{
// Arrange
ODataQueryOptionParser parser = new ODataQueryOptionParser(_model.Model, _model.Customer, _model.Customers,
new Dictionary<string, string> { { "$select", select }, { "$expand", expand } });
SelectExpandClause selectExpandClause = parser.ParseSelectAndExpand();
IEdmEntityType entityType = specialCustomer ? _model.SpecialCustomer : _model.Customer;
// Act
SelectExpandNode selectExpandNode = new SelectExpandNode(selectExpandClause, entityType, _model.Model);
var result = selectExpandNode.SelectedStructuralProperties;
// Assert
Assert.Equal(structuralPropertiesToSelect, String.Join(",", result.Select(p => p.Name).OrderBy(n => n)));
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:18,代码来源:SelectExpandNodeTest.cs
示例4: CreateEntry_SetsEtagToNotNull_IfWithConcurrencyProperty
public void CreateEntry_SetsEtagToNotNull_IfWithConcurrencyProperty()
{
// Arrange
Mock<IEdmStructuralProperty> mockConcurrencyProperty = new Mock<IEdmStructuralProperty>();
mockConcurrencyProperty.SetupGet(s => s.ConcurrencyMode).Returns(EdmConcurrencyMode.Fixed);
mockConcurrencyProperty.SetupGet(s => s.Name).Returns("City");
SelectExpandNode selectExpandNode = new SelectExpandNode
{
SelectedStructuralProperties = { new Mock<IEdmStructuralProperty>().Object, mockConcurrencyProperty.Object }
};
ODataProperty[] properties = new[] { new ODataProperty(), new ODataProperty() };
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
serializer.CallBase = true;
serializer
.Setup(s => s.CreateStructuralProperty(selectExpandNode.SelectedStructuralProperties.ElementAt(0), _entityInstanceContext))
.Returns(properties[0]);
serializer
.Setup(s => s.CreateStructuralProperty(selectExpandNode.SelectedStructuralProperties.ElementAt(1), _entityInstanceContext))
.Returns(properties[1]);
MockHttpRequestMessage request = new MockHttpRequestMessage();
HttpConfiguration configuration = new HttpConfiguration();
Mock<IETagHandler> mockETagHandler = new Mock<IETagHandler>();
string tag = "\"'anycity'\"";
EntityTagHeaderValue etagHeaderValue = new EntityTagHeaderValue(tag, isWeak: true);
mockETagHandler.Setup(e => e.CreateETag(It.IsAny<IDictionary<string, object>>())).Returns(etagHeaderValue);
configuration.SetETagHandler(mockETagHandler.Object);
request.SetConfiguration(configuration);
_entityInstanceContext.Request = request;
// Act
ODataEntry entry = serializer.Object.CreateEntry(selectExpandNode, _entityInstanceContext);
// Assert
Assert.Equal(etagHeaderValue.ToString(), entry.ETag);
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:36,代码来源:ODataEntityTypeSerializerTests.cs
示例5: CreateEntry_SetsETagToNull_IfModelDontHaveConcurrencyProperty
public void CreateEntry_SetsETagToNull_IfModelDontHaveConcurrencyProperty()
{
// Arrange
IEdmEntitySet orderSet = _model.EntityContainer.FindEntitySet("Orders");
Order order = new Order()
{
Name = "Foo",
Shipment = "Bar",
ID = 10,
};
_writeContext.NavigationSource = orderSet;
_entityInstanceContext = new EntityInstanceContext(_writeContext, orderSet.EntityType().AsReference(), order);
SelectExpandNode selectExpandNode = new SelectExpandNode
{
SelectedStructuralProperties = { new Mock<IEdmStructuralProperty>().Object, new Mock<IEdmStructuralProperty>().Object }
};
ODataProperty[] properties = new[] { new ODataProperty(), new ODataProperty() };
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
serializer.CallBase = true;
serializer
.Setup(s => s.CreateStructuralProperty(selectExpandNode.SelectedStructuralProperties.ElementAt(0), _entityInstanceContext))
.Returns(properties[0]);
serializer
.Setup(s => s.CreateStructuralProperty(selectExpandNode.SelectedStructuralProperties.ElementAt(1), _entityInstanceContext))
.Returns(properties[1]);
MockHttpRequestMessage request = new MockHttpRequestMessage();
request.SetConfiguration(new HttpConfiguration());
_entityInstanceContext.Request = request;
// Act
ODataEntry entry = serializer.Object.CreateEntry(selectExpandNode, _entityInstanceContext);
// Assert
Assert.Null(entry.ETag);
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:39,代码来源:ODataEntityTypeSerializerTests.cs
示例6: CreateEntry_SetsETagToNull_IfRequestIsNull
public void CreateEntry_SetsETagToNull_IfRequestIsNull()
{
// Arrange
SelectExpandNode selectExpandNode = new SelectExpandNode
{
SelectedStructuralProperties = { new Mock<IEdmStructuralProperty>().Object, new Mock<IEdmStructuralProperty>().Object }
};
ODataProperty[] properties = new[] { new ODataProperty(), new ODataProperty() };
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
serializer.CallBase = true;
serializer
.Setup(s => s.CreateStructuralProperty(selectExpandNode.SelectedStructuralProperties.ElementAt(0), _entityInstanceContext))
.Returns(properties[0]);
serializer
.Setup(s => s.CreateStructuralProperty(selectExpandNode.SelectedStructuralProperties.ElementAt(1), _entityInstanceContext))
.Returns(properties[1]);
// Act
ODataEntry entry = serializer.Object.CreateEntry(selectExpandNode, _entityInstanceContext);
// Assert
Assert.Null(entry.ETag);
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:24,代码来源:ODataEntityTypeSerializerTests.cs
示例7: CreateEntry_Calls_CreateStructuralProperty_ForEachSelectedStructuralProperty
public void CreateEntry_Calls_CreateStructuralProperty_ForEachSelectedStructuralProperty()
{
// Arrange
SelectExpandNode selectExpandNode = new SelectExpandNode
{
SelectedStructuralProperties = { new Mock<IEdmStructuralProperty>().Object, new Mock<IEdmStructuralProperty>().Object }
};
ODataProperty[] properties = new ODataProperty[] { new ODataProperty(), new ODataProperty() };
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
serializer.CallBase = true;
serializer
.Setup(s => s.CreateStructuralProperty(selectExpandNode.SelectedStructuralProperties.ElementAt(0), _entityInstanceContext))
.Returns(properties[0])
.Verifiable();
serializer
.Setup(s => s.CreateStructuralProperty(selectExpandNode.SelectedStructuralProperties.ElementAt(1), _entityInstanceContext))
.Returns(properties[1])
.Verifiable();
// Act
ODataEntry entry = serializer.Object.CreateEntry(selectExpandNode, _entityInstanceContext);
// Assert
serializer.Verify();
Assert.Equal(properties, entry.Properties);
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:27,代码来源:ODataEntityTypeSerializerTests.cs
示例8: CreateEntry
public override ODataEntry CreateEntry(SelectExpandNode selectExpandNode, EntityInstanceContext entityInstanceContext)
{
ODataEntry entry = base.CreateEntry(selectExpandNode, entityInstanceContext);
// instance annotation on entry
ODataPrimitiveValue guidValue = new ODataPrimitiveValue(new Guid("A6E07EAC-AD49-4BF7-A06E-203FF4D4B0D8"));
entry.InstanceAnnotations.Add(new ODataInstanceAnnotation("Entry.GuidAnnotation", guidValue));
ODataPrimitiveValue strValue = new ODataPrimitiveValue("Hello World.");
entry.InstanceAnnotations.Add(new ODataInstanceAnnotation("Hello.World", strValue));
return entry;
}
开发者ID:xuanvufs,项目名称:WebApi,代码行数:12,代码来源:ODataFormatterTests.cs
示例9: GetNavigationPropertiesToBeExpanded_Expands_ExpectedProperties
[InlineData(null, "NS.SpecialCustomer/SpecialOrders", true, "SpecialOrders")] // expand derived navigation property on derived type -> expand requested
public void GetNavigationPropertiesToBeExpanded_Expands_ExpectedProperties(
string select, string expand, bool specialCustomer, string navigationPropertiesToExpand)
{
// Arrange
SelectExpandClause selectExpandClause =
new ODataUriParser(_model.Model, serviceRoot: null).ParseSelectAndExpand(select, expand, _model.Customer, _model.Customers);
IEdmEntityType entityType = specialCustomer ? _model.SpecialCustomer : _model.Customer;
// Act
SelectExpandNode selectExpandNode = new SelectExpandNode(selectExpandClause, entityType, _model.Model);
var result = selectExpandNode.ExpandedNavigationProperties.Keys;
// Assert
Assert.Equal(navigationPropertiesToExpand, String.Join(",", result.Select(p => p.Name).OrderBy(n => n)));
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:17,代码来源:SelectExpandNodeTest.cs
示例10: CreateEntry_UsesCorrectTypeName
public void CreateEntry_UsesCorrectTypeName()
{
EntityInstanceContext instanceContext =
new EntityInstanceContext { EntityType = _customerType.EntityDefinition(), SerializerContext = _writeContext };
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
serializer.CallBase = true;
SelectExpandNode selectExpandNode = new SelectExpandNode();
// Act
ODataEntry entry = serializer.Object.CreateEntry(selectExpandNode, instanceContext);
// Assert
Assert.Equal("Default.Customer", entry.TypeName);
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:14,代码来源:ODataEntityTypeSerializerTests.cs
示例11: WriteObjectInline_ExpandsUsingInnerSerializerUsingRightContext_ExpandedNavigationProperties
public void WriteObjectInline_ExpandsUsingInnerSerializerUsingRightContext_ExpandedNavigationProperties()
{
// Arrange
IEdmEntityType customerType = _customerSet.EntityType();
IEdmNavigationProperty ordersProperty = customerType.NavigationProperties().Single(p => p.Name == "Orders");
ODataQueryOptionParser parser = new ODataQueryOptionParser(_model, customerType, _customerSet,
new Dictionary<string, string> { { "$select", "Orders" }, { "$expand", "Orders" } });
SelectExpandClause selectExpandClause = parser.ParseSelectAndExpand();
SelectExpandNode selectExpandNode = new SelectExpandNode
{
ExpandedNavigationProperties =
{
{ ordersProperty, selectExpandClause.SelectedItems.OfType<ExpandedNavigationSelectItem>().Single().SelectAndExpand }
}
};
Mock<ODataWriter> writer = new Mock<ODataWriter>();
Mock<ODataEdmTypeSerializer> innerSerializer = new Mock<ODataEdmTypeSerializer>(ODataPayloadKind.Entry);
innerSerializer
.Setup(s => s.WriteObjectInline(_customer.Orders, ordersProperty.Type, writer.Object, It.IsAny<ODataSerializerContext>()))
.Callback((object o, IEdmTypeReference t, ODataWriter w, ODataSerializerContext context) =>
{
Assert.Same(context.NavigationSource.Name, "Orders");
Assert.Same(context.SelectExpandClause, selectExpandNode.ExpandedNavigationProperties.Single().Value);
})
.Verifiable();
Mock<ODataSerializerProvider> serializerProvider = new Mock<ODataSerializerProvider>();
serializerProvider.Setup(p => p.GetEdmTypeSerializer(ordersProperty.Type))
.Returns(innerSerializer.Object);
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(serializerProvider.Object);
serializer.Setup(s => s.CreateSelectExpandNode(It.IsAny<EntityInstanceContext>())).Returns(selectExpandNode);
serializer.CallBase = true;
_writeContext.SelectExpandClause = selectExpandClause;
// Act
serializer.Object.WriteObjectInline(_customer, _customerType, writer.Object, _writeContext);
// Assert
innerSerializer.Verify();
// check that the context is rolled back
Assert.Same(_writeContext.NavigationSource.Name, "Customers");
Assert.Same(_writeContext.SelectExpandClause, selectExpandClause);
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:46,代码来源:ODataEntityTypeSerializerTests.cs
示例12: WriteObjectInline_Calls_CreateNavigationLink_ForEachExpandedNavigationProperty
public void WriteObjectInline_Calls_CreateNavigationLink_ForEachExpandedNavigationProperty()
{
// Arrange
SelectExpandNode selectExpandNode = new SelectExpandNode
{
ExpandedNavigationProperties =
{
{ new Mock<IEdmNavigationProperty>().Object, null },
{ new Mock<IEdmNavigationProperty>().Object, null }
}
};
Mock<ODataWriter> writer = new Mock<ODataWriter>();
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
serializer.Setup(s => s.CreateSelectExpandNode(It.IsAny<EntityInstanceContext>())).Returns(selectExpandNode);
var expandedNavigationProperties = selectExpandNode.ExpandedNavigationProperties.ToList();
serializer.Setup(s => s.CreateNavigationLink(expandedNavigationProperties[0].Key, It.IsAny<EntityInstanceContext>())).Verifiable();
serializer.Setup(s => s.CreateNavigationLink(expandedNavigationProperties[1].Key, It.IsAny<EntityInstanceContext>())).Verifiable();
serializer.CallBase = true;
// Act
serializer.Object.WriteObjectInline(_customer, _customerType, writer.Object, _writeContext);
// Assert
serializer.Verify();
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:26,代码来源:ODataEntityTypeSerializerTests.cs
示例13: ODataNavigationLink
public void WriteObjectInline_WritesNavigationLinksReturnedBy_CreateNavigationLink_ForEachSelectedNavigationProperty()
{
// Arrange
SelectExpandNode selectExpandNode = new SelectExpandNode
{
SelectedNavigationProperties =
{
new Mock<IEdmNavigationProperty>().Object,
new Mock<IEdmNavigationProperty>().Object
}
};
ODataNavigationLink[] navigationLinks = new[]
{
new ODataNavigationLink(),
new ODataNavigationLink()
};
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
serializer.Setup(s => s.CreateSelectExpandNode(It.IsAny<EntityInstanceContext>())).Returns(selectExpandNode);
serializer
.Setup(s => s.CreateNavigationLink(selectExpandNode.SelectedNavigationProperties.ElementAt(0), It.IsAny<EntityInstanceContext>()))
.Returns(navigationLinks[0]);
serializer
.Setup(s => s.CreateNavigationLink(selectExpandNode.SelectedNavigationProperties.ElementAt(1), It.IsAny<EntityInstanceContext>()))
.Returns(navigationLinks[1]);
serializer.CallBase = true;
Mock<ODataWriter> writer = new Mock<ODataWriter>();
writer.Setup(w => w.WriteStart(navigationLinks[0])).Verifiable();
writer.Setup(w => w.WriteStart(navigationLinks[1])).Verifiable();
// Act
serializer.Object.WriteObjectInline(_customer, _customerType, writer.Object, _writeContext);
// Assert
writer.Verify();
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:36,代码来源:ODataEntityTypeSerializerTests.cs
示例14: WriteObjectInline_Calls_CreateEntry
public void WriteObjectInline_Calls_CreateEntry()
{
// Arrange
SelectExpandNode selectExpandNode = new SelectExpandNode();
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
ODataWriter writer = new Mock<ODataWriter>().Object;
serializer.Setup(s => s.CreateSelectExpandNode(It.IsAny<EntityInstanceContext>())).Returns(selectExpandNode);
serializer.Setup(s => s.CreateEntry(selectExpandNode, It.Is<EntityInstanceContext>(e => Verify(e, _customer, _writeContext)))).Verifiable();
serializer.CallBase = true;
// Act
serializer.Object.WriteObjectInline(_customer, _customerType, writer, _writeContext);
// Assert
serializer.Verify();
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:17,代码来源:ODataEntityTypeSerializerTests.cs
示例15: WriteObjectInline_SetsParentContext_ForExpandedNavigationProperties
public void WriteObjectInline_SetsParentContext_ForExpandedNavigationProperties()
{
// Arrange
ODataWriter mockWriter = new Mock<ODataWriter>().Object;
IEdmNavigationProperty ordersProperty = _customerSet.EntityType().DeclaredNavigationProperties().Single();
Mock<ODataEdmTypeSerializer> expandedItemSerializer = new Mock<ODataEdmTypeSerializer>(ODataPayloadKind.Feed);
Mock<ODataSerializerProvider> serializerProvider = new Mock<ODataSerializerProvider>();
serializerProvider.Setup(p => p.GetEdmTypeSerializer(ordersProperty.Type))
.Returns(expandedItemSerializer.Object);
SelectExpandNode selectExpandNode = new SelectExpandNode
{
ExpandedNavigationProperties =
{
{ ordersProperty, new SelectExpandClause(new SelectItem[0], allSelected: true) }
}
};
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(serializerProvider.Object);
serializer.Setup(s => s.CreateSelectExpandNode(It.IsAny<EntityInstanceContext>())).Returns(selectExpandNode);
serializer.Setup(s => s.CreateEntry(selectExpandNode, _entityInstanceContext)).Returns(new ODataEntry());
serializer.CallBase = true;
// Act
serializer.Object.WriteObjectInline(_customer, _customerType, mockWriter, _writeContext);
// Assert
expandedItemSerializer.Verify(
s => s.WriteObjectInline(It.IsAny<object>(), ordersProperty.Type, mockWriter,
It.Is<ODataSerializerContext>(c => c.ExpandedEntity.SerializerContext == _writeContext)));
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:30,代码来源:ODataEntityTypeSerializerTests.cs
示例16: CreateEntry
/// <summary>
/// Creates the <see cref="ODataEntry"/> to be written while writing this entity.
/// </summary>
/// <param name="selectExpandNode">The <see cref="SelectExpandNode"/> describing the response graph.</param>
/// <param name="entityInstanceContext">The context for the entity instance being written.</param>
/// <returns>The created <see cref="ODataEntry"/>.</returns>
public virtual ODataEntry CreateEntry(SelectExpandNode selectExpandNode, EntityInstanceContext entityInstanceContext)
{
if (selectExpandNode == null)
{
throw Error.ArgumentNull("selectExpandNode");
}
if (entityInstanceContext == null)
{
throw Error.ArgumentNull("entityInstanceContext");
}
string typeName = entityInstanceContext.EntityType.FullName();
ODataEntry entry = new ODataEntry
{
TypeName = typeName,
Properties = CreateStructuralPropertyBag(selectExpandNode.SelectedStructuralProperties, entityInstanceContext),
Actions = CreateODataActions(selectExpandNode.SelectedActions, entityInstanceContext)
};
IEdmEntityType pathType = GetODataPathType(entityInstanceContext.SerializerContext);
AddTypeNameAnnotationAsNeeded(entry, pathType, entityInstanceContext.SerializerContext.MetadataLevel);
if (entityInstanceContext.EntitySet != null)
{
IEdmModel model = entityInstanceContext.SerializerContext.Model;
EntitySetLinkBuilderAnnotation linkBuilder = model.GetEntitySetLinkBuilder(entityInstanceContext.EntitySet);
EntitySelfLinks selfLinks = linkBuilder.BuildEntitySelfLinks(entityInstanceContext, entityInstanceContext.SerializerContext.MetadataLevel);
if (selfLinks.IdLink != null)
{
entry.Id = new Uri(selfLinks.IdLink);
}
if (selfLinks.ReadLink != null)
{
entry.ReadLink = selfLinks.ReadLink;
}
if (selfLinks.EditLink != null)
{
entry.EditLink = selfLinks.EditLink;
}
string etag = CreateETag(entityInstanceContext);
if (etag != null)
{
entry.ETag = etag;
}
}
return entry;
}
开发者ID:modulexcite,项目名称:aspnetwebstack-1,代码行数:59,代码来源:ODataEntityTypeSerializer.cs
示例17: CreateEntry_IgnoresProperty_IfCreateStructuralPropertyReturnsNull
public void CreateEntry_IgnoresProperty_IfCreateStructuralPropertyReturnsNull()
{
// Arrange
SelectExpandNode selectExpandNode = new SelectExpandNode
{
SelectedStructuralProperties = { new Mock<IEdmStructuralProperty>().Object }
};
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
serializer.CallBase = true;
serializer
.Setup(s => s.CreateStructuralProperty(selectExpandNode.SelectedStructuralProperties.ElementAt(0), _entityInstanceContext))
.Returns<ODataProperty>(null);
// Act
ODataEntry entry = serializer.Object.CreateEntry(selectExpandNode, _entityInstanceContext);
// Assert
serializer.Verify();
Assert.Empty(entry.Properties);
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:21,代码来源:ODataEntityTypeSerializerTests.cs
示例18: WriteObjectInline_CanExpandNavigationProperty_ContainingEdmObject
public void WriteObjectInline_CanExpandNavigationProperty_ContainingEdmObject()
{
// Arrange
IEdmEntityType customerType = _customerSet.EntityType();
IEdmNavigationProperty ordersProperty = customerType.NavigationProperties().Single(p => p.Name == "Orders");
Mock<IEdmObject> orders = new Mock<IEdmObject>();
orders.Setup(o => o.GetEdmType()).Returns(ordersProperty.Type);
object ordersValue = orders.Object;
Mock<IEdmEntityObject> customer = new Mock<IEdmEntityObject>();
customer.Setup(c => c.TryGetPropertyValue("Orders", out ordersValue)).Returns(true);
customer.Setup(c => c.GetEdmType()).Returns(customerType.AsReference());
ODataQueryOptionParser parser = new ODataQueryOptionParser(_model, customerType, _customerSet,
new Dictionary<string, string> { { "$select", "Orders" }, { "$expand", "Orders" } });
SelectExpandClause selectExpandClause = parser.ParseSelectAndExpand();
SelectExpandNode selectExpandNode = new SelectExpandNode();
selectExpandNode.ExpandedNavigationProperties[ordersProperty] = selectExpandClause.SelectedItems.OfType<ExpandedNavigationSelectItem>().Single().SelectAndExpand;
Mock<ODataWriter> writer = new Mock<ODataWriter>();
Mock<ODataEdmTypeSerializer> ordersSerializer = new Mock<ODataEdmTypeSerializer>(ODataPayloadKind.Entry);
ordersSerializer.Setup(s => s.WriteObjectInline(ordersValue, ordersProperty.Type, writer.Object, It.IsAny<ODataSerializerContext>())).Verifiable();
Mock<ODataSerializerProvider> serializerProvider = new Mock<ODataSerializerProvider>();
serializerProvider.Setup(p => p.GetEdmTypeSerializer(ordersProperty.Type)).Returns(ordersSerializer.Object);
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(serializerProvider.Object);
serializer.Setup(s => s.CreateSelectExpandNode(It.IsAny<EntityInstanceContext>())).Returns(selectExpandNode);
serializer.CallBase = true;
// Act
serializer.Object.WriteObjectInline(customer.Object, _customerType, writer.Object, _writeContext);
//Assert
ordersSerializer.Verify();
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:39,代码来源:ODataEntityTypeSerializerTests.cs
示例19: CreateEntry_Calls_CreateODataAction_ForEachSelectAction
public void CreateEntry_Calls_CreateODataAction_ForEachSelectAction()
{
// Arrange
ODataAction[] actions = new ODataAction[] { new ODataAction(), new ODataAction() };
SelectExpandNode selectExpandNode = new SelectExpandNode
{
SelectedActions = { new Mock<IEdmAction>().Object, new Mock<IEdmAction>().Object }
};
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializerProvider);
serializer.CallBase = true;
serializer.Setup(s => s.CreateODataAction(selectExpandNode.SelectedActions.ElementAt(0), _entityInstanceContext)).Returns(actions[0]).Verifiable();
serializer.Setup(s => s.CreateODataAction(selectExpandNode.SelectedActions.ElementAt(1), _entityInstanceContext)).Returns(actions[1]).Verifiable();
// Act
ODataEntry entry = serializer.Object.CreateEntry(selectExpandNode, _entityInstanceContext);
// Assert
Assert.Equal(actions, entry.Actions);
serializer.Verify();
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:21,代码来源:ODataEntityTypeSerializerTests.cs
示例20: CreateSelectExpandNode
/// <summary>
/// Creates the <see cref="SelectExpandNode"/> that describes the set of properties and actions to select and expand while writing this entity.
/// </summary>
/// <param name="entityInstanceContext">Contains the entity instance being written and the context.</param>
/// <returns>
/// The <see cref="SelectExpandNode"/> that describes the set of properties and actions to select and expand while writing this entity.
/// </returns>
public virtual SelectExpandNode CreateSelectExpandNode(EntityInstanceContext entityInstanceContext)
{
if (entityInstanceContext == null)
{
throw Error.ArgumentNull("entityInstanceContext");
}
ODataSerializerContext writeContext = entityInstanceContext.SerializerContext;
IEdmEntityType entityType = entityInstanceContext.EntityType;
object selectExpandNode;
Tuple<SelectExpandClause, IEdmEntityType> key = Tuple.Create(writeContext.SelectExpandClause, entityType);
if (!writeContext.Items.TryGetValue(key, out selectExpandNode))
{
// cache the selectExpandNode so that if we are writing a feed we don't have to construct it again.
selectExpandNode = new SelectExpandNode(entityType, writeContext);
writeContext.Items[key] = selectExpandNode;
}
return selectExpandNode as SelectExpandNode;
}
开发者ID:BarclayII,项目名称:WebApi,代码行数:27,代码来源:ODataEntityTypeSerializer.cs
注:本文中的System.Web.OData.Formatter.Serialization.SelectExpandNode类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论