本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmComplexType.ToTypeReference方法的典型用法代码示例。如果您正苦于以下问题:C# EdmComplexType.ToTypeReference方法的具体用法?C# EdmComplexType.ToTypeReference怎么用?C# EdmComplexType.ToTypeReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmComplexType
的用法示例。
在下文中一共展示了EdmComplexType.ToTypeReference方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HeterogeneousCollectionReaderTest
public void HeterogeneousCollectionReaderTest()
{
EdmModel model = new EdmModel();
var cityType = new EdmComplexType("TestModel", "CityType");
cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true));
model.AddElement(cityType);
var addressType = new EdmComplexType("TestModel", "AddressType");
addressType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true));
model.AddElement(addressType);
var testContainer = new EdmEntityContainer("TestModel", "TestContainer");
model.AddElement(testContainer);
EdmFunction citiesFunction = new EdmFunction("TestModel", "Cities", EdmCoreModel.GetCollection(cityType.ToTypeReference()));
model.AddElement(citiesFunction);
EdmOperationImport citiesFunctionImport = testContainer.AddFunctionImport("Cities", citiesFunction);
model.Fixup();
// Add some hand-crafted payloads
IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
{
// expected type without type names in the payload and heterogeneous items
new PayloadReaderTestDescriptor(this.Settings)
{
PayloadElement = new ComplexInstanceCollection(
PayloadBuilder.ComplexValue().Property("Name", PayloadBuilder.PrimitiveValue("Vienna")),
PayloadBuilder.ComplexValue().Property("Street", PayloadBuilder.PrimitiveValue("Am Euro Platz")))
.ExpectedFunctionImport(citiesFunctionImport)
.CollectionName(null),
PayloadEdmModel = model,
ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "Street", "TestModel.CityType"),
},
};
this.CombinatorialEngineProvider.RunCombinations(
testDescriptors,
this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
(testDescriptor, testConfiguration) =>
{
testDescriptor.RunTest(testConfiguration);
});
}
示例2: BuildModelWithFunctionImport
/// <summary>
/// Creates a test model shared among parameter reader/writer tests.
/// </summary>
/// <returns>Returns a model with function imports.</returns>
public static IEdmModel BuildModelWithFunctionImport()
{
EdmCoreModel coreModel = EdmCoreModel.Instance;
EdmModel model = new EdmModel();
const string defaultNamespaceName = "TestModel";
EdmEntityContainer container = new EdmEntityContainer(defaultNamespaceName, "TestContainer");
model.AddElement(container);
EdmComplexType complexType = new EdmComplexType(defaultNamespaceName, "ComplexType");
complexType.AddProperty(new EdmStructuralProperty(complexType, "PrimitiveProperty", coreModel.GetString(false)));
complexType.AddProperty(new EdmStructuralProperty(complexType, "ComplexProperty", complexType.ToTypeReference(false)));
model.AddElement(complexType);
EdmEnumType enumType = new EdmEnumType(defaultNamespaceName, "EnumType");
model.AddElement(enumType);
EdmEntityType entityType = new EdmEntityType(defaultNamespaceName, "EntityType");
entityType.AddKeys(new IEdmStructuralProperty[] {new EdmStructuralProperty(entityType, "ID", coreModel.GetInt32(false))});
entityType.AddProperty(new EdmStructuralProperty(entityType, "ComplexProperty", complexType.ToTypeReference()));
container.AddActionAndActionImport(model, "FunctionImport_Primitive", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("primitive", coreModel.GetString(false));
container.AddActionAndActionImport(model, "FunctionImport_NullablePrimitive", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("nullablePrimitive", coreModel.GetString(true));
EdmCollectionType stringCollectionType = new EdmCollectionType(coreModel.GetString(true));
container.AddActionAndActionImport(model, "FunctionImport_PrimitiveCollection", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("primitiveCollection", stringCollectionType.ToTypeReference(false));
container.AddActionAndActionImport(model, "FunctionImport_Complex", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("complex", complexType.ToTypeReference(true));
EdmCollectionType complexCollectionType = new EdmCollectionType(complexType.ToTypeReference());
container.AddActionAndActionImport(model, "FunctionImport_ComplexCollection", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("complexCollection", complexCollectionType.ToTypeReference());
container.AddActionAndActionImport(model, "FunctionImport_Entry", null /*returnType*/, null /*entitySet*/, true /*bindable*/).Action.AsEdmAction().AddParameter("entry", entityType.ToTypeReference());
EdmCollectionType entityCollectionType = new EdmCollectionType(entityType.ToTypeReference());
container.AddActionAndActionImport(model, "FunctionImport_Feed", null /*returnType*/, null /*entitySet*/, true /*bindable*/).Action.AsEdmAction().AddParameter("feed", entityCollectionType.ToTypeReference());
container.AddActionAndActionImport(model, "FunctionImport_Stream", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("stream", coreModel.GetStream(false));
container.AddActionAndActionImport(model, "FunctionImport_Enum", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("enum", enumType.ToTypeReference());
var functionImport_PrimitiveTwoParameters = container.AddActionAndActionImport(model, "FunctionImport_PrimitiveTwoParameters", null /*returnType*/, null /*entitySet*/, false /*bindable*/);
functionImport_PrimitiveTwoParameters.Action.AsEdmAction().AddParameter("p1", coreModel.GetInt32(false));
functionImport_PrimitiveTwoParameters.Action.AsEdmAction().AddParameter("p2", coreModel.GetString(false));
container.AddActionAndActionImport(model, "FunctionImport_Int", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("p1", coreModel.GetInt32(false));
container.AddActionAndActionImport(model, "FunctionImport_Double", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("p1", coreModel.GetDouble(false));
EdmCollectionType int32CollectionType = new EdmCollectionType(coreModel.GetInt32(false));
container.AddActionAndActionImport(model, "FunctionImport_NonNullablePrimitiveCollection", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("p1", int32CollectionType.ToTypeReference(false));
EdmComplexType complexType2 = new EdmComplexType(defaultNamespaceName, "ComplexTypeWithNullableProperties");
complexType2.AddProperty(new EdmStructuralProperty(complexType2, "StringProperty", coreModel.GetString(true)));
complexType2.AddProperty(new EdmStructuralProperty(complexType2, "IntegerProperty", coreModel.GetInt32(true)));
model.AddElement(complexType2);
var functionImport_MultipleNullableParameters = container.AddActionAndActionImport(model, "FunctionImport_MultipleNullableParameters", null /*returnType*/, null /*entitySet*/, false /*bindable*/);
var function_MultipleNullableParameters = functionImport_MultipleNullableParameters.Action.AsEdmAction();
function_MultipleNullableParameters.AddParameter("p1", coreModel.GetBinary(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p2", coreModel.GetBoolean(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p3", coreModel.GetByte(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p5", coreModel.GetDateTimeOffset(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p6", coreModel.GetDecimal(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p7", coreModel.GetDouble(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p8", coreModel.GetGuid(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p9", coreModel.GetInt16(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p10", coreModel.GetInt32(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p11", coreModel.GetInt64(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p12", coreModel.GetSByte(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p13", coreModel.GetSingle(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p14", coreModel.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p15", coreModel.GetString(true /*isNullable*/));
function_MultipleNullableParameters.AddParameter("p16", complexType2.ToTypeReference(true /*isNullable*/));
return model;
}
示例3: MetadataDocumentReaderTestsForRepro
public void MetadataDocumentReaderTestsForRepro()
{
List<MetadataReaderTestDescriptor> testCases = new List<MetadataReaderTestDescriptor>();
EdmModel model = new EdmModel();
var addressType = new EdmComplexType("TestModel", "Address");
addressType.AddStructuralProperty("Zip", EdmPrimitiveTypeKind.Int32, isNullable: false);
addressType.AddStructuralProperty("Image", EdmPrimitiveTypeKind.Stream, isNullable: false);
model.AddElement(addressType);
var personType = new EdmEntityType("TestModel", "Person");
personType.AddKeys(personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, isNullable: false));
personType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String, isNullable: true);
personType.AddStructuralProperty("Photo", EdmPrimitiveTypeKind.Stream, isNullable: false);
personType.AddStructuralProperty("Address", addressType.ToTypeReference());
personType.AddStructuralProperty("Photos", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetStream(isNullable: false)));
model.AddElement(personType);
var container = new EdmEntityContainer("TestModel", "DefaultContainer");
container.AddEntitySet("Person", personType);
model.AddElement(container);
//personType.EntityPropertyMapping("Name", SyndicationItemProperty.AuthorName);
// TODO: Both the mappings below fail differently. Once it is fixed add these tests to error tests in MetadataDocumentReaderErrorTests.cs file.
// This fails since annotations don't match which is very likely due to the product silently dropping the annotation mapped to stream.
// Where as the mapping on property on ComplexType fails with the right error message.
// personType.EntityPropertyMapping("Photo", SyndicationItemProperty.Summary);
// personType.EntityPropertyMapping("Address/Image", SyndicationItemProperty.Title);
// The below fails with yet another error message saying basically that mapping is different.
// personType.EntityPropertyMapping("Photos", SyndicationItemProperty.AuthorEmail);
testCases.Add(this.CreateMetadataDescriptor(model));
this.CombinatorialEngineProvider.RunCombinations(
testCases,
this.ReaderTestConfigurationProvider.DefaultFormatConfigurations.Where(tc => tc.Synchronous && !tc.IsRequest),
(testDescriptor, testConfiguration) => testDescriptor.RunTest(testConfiguration));
}
示例4: CollectionValueTest
public void CollectionValueTest()
{
EdmModel model = new EdmModel();
var complexType = new EdmComplexType("TestModel", "ComplexType").Property("Name", EdmPrimitiveTypeKind.String, true);
model.AddElement(complexType);
var owningType = new EdmEntityType("TestModel", "OwningType");
owningType.AddKeys(owningType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false)));
owningType.AddStructuralProperty("PrimitiveCollection", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false)));
owningType.AddStructuralProperty("ComplexCollection", EdmCoreModel.GetCollection(complexType.ToTypeReference()));
model.AddElement(owningType);
model.Fixup();
var primitiveMultiValue = PayloadBuilder.PrimitiveMultiValue("Collection(Edm.Int32)").Item(42).Item(43);
var complexMultiValue = PayloadBuilder.ComplexMultiValue("Collection(TestModel.ComplexType)").Item(
PayloadBuilder.ComplexValue("TestModel.ComplexType")
.PrimitiveProperty("Name", "Value")
.AddAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }))
.JsonRepresentation("[{\"Name\":\"Value\"}]")
.AddAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null });
IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new[]
{
new PayloadReaderTestDescriptor(this.Settings)
{
DebugDescription = "null collection in request - should fail.",
PayloadEdmModel = model,
PayloadElement = PayloadBuilder.Property("PrimitiveCollection",
PayloadBuilder.PrimitiveMultiValue("Collection(Edm.Int32)"))
.JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNullAnnotationName + "\":true }")
.ExpectedProperty(owningType, "PrimitiveCollection"),
SkipTestConfiguration = tc => !tc.IsRequest,
ExpectedException = ODataExpectedExceptions.ODataException("ReaderValidationUtils_NullValueForNonNullableType", "Collection(Edm.Int32)")
},
new PayloadReaderTestDescriptor(this.Settings)
{
DebugDescription = "null collection in response - should fail.",
PayloadEdmModel = model,
PayloadElement = PayloadBuilder.Property("PrimitiveCollection",
PayloadBuilder.PrimitiveMultiValue("Collection(Edm.Int32)"))
.JsonRepresentation(
"{" +
"\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\"," +
"\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNullAnnotationName + "\":true" +
"}")
.ExpectedProperty(owningType, "PrimitiveCollection"),
SkipTestConfiguration = tc => tc.IsRequest,
ExpectedException = ODataExpectedExceptions.ODataException("ReaderValidationUtils_NullValueForNonNullableType", "Collection(Edm.Int32)")
},
new PayloadReaderTestDescriptor(this.Settings)
{
DebugDescription = "Primitive value for collection - should fail.",
PayloadEdmModel = model,
PayloadElement = PayloadBuilder.Property("PrimitiveCollection",
PayloadBuilder.PrimitiveMultiValue("Collection(Edm.Int32)")
.JsonRepresentation("42"))
.ExpectedProperty(owningType, "PrimitiveCollection"),
ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartArray", "PrimitiveValue")
},
new PayloadReaderTestDescriptor(this.Settings)
{
DebugDescription = "Object value for collection - should fail.",
PayloadEdmModel = model,
PayloadElement = PayloadBuilder.Property("PrimitiveCollection",
PayloadBuilder.PrimitiveMultiValue("Collection(Edm.Int32)")
.JsonRepresentation("{}"))
.ExpectedProperty(owningType, "PrimitiveCollection"),
ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetectedWithPropertyName", "StartArray", "StartObject", "value")
},
new PayloadReaderTestDescriptor(this.Settings)
{
DebugDescription = "Simple primitive collection.",
PayloadEdmModel = model,
PayloadElement = PayloadBuilder.Property("PrimitiveCollection",
primitiveMultiValue
.JsonRepresentation("[42,43]")
.AddAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }))
.ExpectedProperty(owningType, "PrimitiveCollection"),
ExpectedResultPayloadElement = tc => tc.IsRequest
? PayloadBuilder.Property(string.Empty, primitiveMultiValue)
: PayloadBuilder.Property("PrimitiveCollection", primitiveMultiValue)
},
new PayloadReaderTestDescriptor(this.Settings)
{
DebugDescription = "Simple complex collection.",
PayloadEdmModel = model,
PayloadElement = PayloadBuilder.Property("ComplexCollection", complexMultiValue)
.ExpectedProperty(owningType, "ComplexCollection"),
ExpectedResultPayloadElement = tc => tc.IsRequest
? PayloadBuilder.Property(string.Empty, complexMultiValue)
: PayloadBuilder.Property("ComplexCollection", complexMultiValue)
},
};
this.CombinatorialEngineProvider.RunCombinations(
testDescriptors,
this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
(testDescriptor, testConfiguration) =>
{
// These descriptors are already tailored specifically for Json Light and
// do not require normalization.
//.........这里部分代码省略.........