本文整理汇总了C#中ODataVersion.ToSystemVersion方法的典型用法代码示例。如果您正苦于以下问题:C# ODataVersion.ToSystemVersion方法的具体用法?C# ODataVersion.ToSystemVersion怎么用?C# ODataVersion.ToSystemVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODataVersion
的用法示例。
在下文中一共展示了ODataVersion.ToSystemVersion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNullPropertyOnEntryTestDescriptor
private PayloadWriterTestDescriptor<ODataItem> CreateNullPropertyOnEntryTestDescriptor(
IEdmTypeReference dataType,
ODataVersion version,
bool allowNulls)
{
EdmPrimitiveTypeReference primitiveDataType = dataType as EdmPrimitiveTypeReference;
EdmComplexTypeReference complexDataType = dataType as EdmComplexTypeReference;
string typeName = primitiveDataType == null ? complexDataType.Definition.TestFullName() : primitiveDataType.Definition.TestFullName();
var td = new PayloadWriterTestDescriptor<ODataItem>(
this.Settings,
new ODataEntry
{
TypeName = "TestModel.EntityType",
Properties = new[] { new ODataProperty {
Name = "nullProperty",
Value = null } },
SerializationInfo = MySerializationInfo
},
(tc) =>
{
if (allowNulls)
{
if (tc.Format == ODataFormat.Atom)
{
return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Xml = "<d:nullProperty " +
"m:null='true' xmlns:m='http://docs.oasis-open.org/odata/ns/metadata' xmlns:d='http://docs.oasis-open.org/odata/ns/data' />",
FragmentExtractor = (result) => TestAtomUtils.ExtractPropertiesFromEntry(result).Element(TestAtomConstants.ODataXNamespace + "nullProperty")
};
}
else
{
return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Json = "\"nullProperty\":null",
FragmentExtractor = (result) => JsonUtils.UnwrapTopLevelValue(tc, result).Object().Property("nullProperty")
};
}
}
else
{
return new WriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
ExpectedException2 = ODataExpectedExceptions.ODataException("WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue", "nullProperty", typeName),
};
}
});
// doesn't have a clone method so has to new an EdmModel
EdmModel edmModel = new EdmModel();
var entityType = new EdmEntityType("TestModel", "EntityType");
edmModel.AddElement(entityType);
var container = new EdmEntityContainer("TestNS", "TestContainer");
entityType.AddStructuralProperty("nullProperty", dataType);
edmModel.AddElement(container);
td.Model = edmModel as IEdmModel;
// NOTE: important to set Edm version and to control null value validation!
td.Model.SetEdmVersion(version.ToSystemVersion());
return td;
}
示例2: CreateNonNullPropertyOnEntryTestDescriptor
private PayloadWriterTestDescriptor<ODataItem> CreateNonNullPropertyOnEntryTestDescriptor(
NonNullableEdmPrimitiveTypeWithValue nonNullablePrimitiveTypeWithValue,
bool typeAttributeExpected,
ODataVersion version,
string propertyName)
{
string typeName = EdmCoreModel.Instance.GetPrimitive(nonNullablePrimitiveTypeWithValue.Type, true).Definition.TestFullName();
bool isInvalidPropertyName = propertyName.IndexOfAny(InvalidCharactersInPropertyNames) >= 0;
var td = new PayloadWriterTestDescriptor<ODataItem>(
this.Settings,
new ODataEntry
{
TypeName = "TestModel.EntityType",
Properties = new[] { new ODataProperty {
Name = propertyName,
Value = nonNullablePrimitiveTypeWithValue.Value } },
SerializationInfo = MySerializationInfo
},
(tc) =>
{
if (tc.Format == ODataFormat.Atom)
{
return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Xml = "<d:" + propertyName + " " +
(typeAttributeExpected ? ("m:type='" + typeName + "' xmlns:m='http://docs.oasis-open.org/odata/ns/metadata' ") : string.Empty) +
"xmlns:d='http://docs.oasis-open.org/odata/ns/data'>" +
nonNullablePrimitiveTypeWithValue.AtomRepresentation +
"</d:" + propertyName + ">",
FragmentExtractor = (result) => TestAtomUtils.ExtractPropertiesFromEntry(result).Element(TestAtomConstants.ODataXNamespace + propertyName),
ExpectedException2 = isInvalidPropertyName
? ODataExpectedExceptions.ODataException("ValidationUtils_PropertiesMustNotContainReservedChars", propertyName, "':', '.', '@'")
: null,
};
}
else if (tc.Format == ODataFormat.Json)
{
return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Json = "\"" + JsonLightConstants.ODataValuePropertyName + "\":" + nonNullablePrimitiveTypeWithValue.JsonLightRepresentation,
FragmentExtractor = (result) => JsonLightWriterUtils.TrimWhitespace(result).Object().Property(propertyName),
ExpectedException2 = isInvalidPropertyName
? ODataExpectedExceptions.ODataException("ValidationUtils_PropertiesMustNotContainReservedChars", propertyName, "':', '.', '@'")
: null,
};
}
else
{
string formatName = tc.Format == null ? "null" : tc.Format.GetType().Name;
throw new NotSupportedException("Format " + formatName + " + is not supported.");
}
});
EdmModel edmModel = new EdmModel();
var entityType = new EdmEntityType("TestModel", "EntityType");
entityType.AddStructuralProperty(propertyName, EdmCoreModel.Instance.GetPrimitive(nonNullablePrimitiveTypeWithValue.Type, false));
edmModel.AddElement(entityType);
var container = new EdmEntityContainer("TestNS", "TestContainer");
edmModel.AddElement(container);
td.Model = edmModel as IEdmModel;
// NOTE: important to set Edm version and to control null value validation!
td.Model.SetEdmVersion(version.ToSystemVersion());
return td;
}
示例3: CreateNullPropertyOnComplexValueTestDescriptor
private PayloadWriterTestDescriptor<ODataProperty> CreateNullPropertyOnComplexValueTestDescriptor(
IEdmTypeReference dataType,
ODataVersion version,
bool allowNulls)
{
EdmPrimitiveTypeReference primitiveDataType = dataType as EdmPrimitiveTypeReference;
EdmComplexTypeReference complexDataType = dataType as EdmComplexTypeReference;
string typeName = primitiveDataType == null ? complexDataType.Definition.TestFullName() : primitiveDataType.Definition.TestFullName();
var td = new PayloadWriterTestDescriptor<ODataProperty>(
this.Settings,
new ODataProperty
{
Name = "complex",
Value = new ODataComplexValue
{
TypeName = "TestModel.ComplexType",
Properties = new[] { new ODataProperty {
Name = "nullProperty",
Value = null } }
}
},
(tc) =>
{
if (allowNulls)
{
if (tc.Format == ODataFormat.Atom)
{
return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Xml = "<d:nullProperty " +
"m:null='true' xmlns:m='http://docs.oasis-open.org/odata/ns/metadata' xmlns:d='http://docs.oasis-open.org/odata/ns/data' />",
FragmentExtractor = (result) => result.Element(TestAtomConstants.ODataXNamespace + "nullProperty")
};
}
else if (tc.Format == ODataFormat.Json)
{
return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Json = "\"nullProperty\":null",
FragmentExtractor = (result) => JsonLightWriterUtils.TrimWhitespace(result).Object().Property("nullProperty")
};
}
else
{
string formatName = tc.Format == null ? "null" : tc.Format.GetType().Name;
throw new NotSupportedException("Format " + formatName + " + is not supported.");
}
}
else
{
return new WriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
ExpectedException2 = ODataExpectedExceptions.ODataException("WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue", "nullProperty", typeName),
};
}
});
EdmModel edmModel = new EdmModel();
var complexType = new EdmComplexType("TestModel", "ComplexType");
complexType.AddStructuralProperty("nullProperty", dataType);
edmModel.AddElement(complexType);
var entityType = new EdmEntityType("TestModel", "EntityType");
entityType.AddStructuralProperty("complex", new EdmComplexTypeReference(complexType, isNullable: true));
edmModel.AddElement(entityType);
var container = new EdmEntityContainer("TestNS", "TestContainer");
edmModel.AddElement(container);
td.Model = edmModel as IEdmModel;
td.PayloadEdmElementContainer = entityType;
// NOTE: important to set Edm version to control null value validation!
td.Model.SetEdmVersion(version.ToSystemVersion());
return td;
}