本文整理匯總了C#中System.Web.OData.Formatter.Serialization.SelectExpandNode類的典型用法代碼示例。如果您正苦於以下問題:C# SelectExpandNode類的具體用法?C# SelectExpandNode怎麽用?C# SelectExpandNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SelectExpandNode類屬於System.Web.OData.Formatter.Serialization命名空間,在下文中一共展示了SelectExpandNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
示例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)));
}
示例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)));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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)));
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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)));
}