public ODataFeedSerializerTests() { _model = SerializationTestsHelpers.SimpleCustomerOrderModel(); _customerSet = _model.EntityContainer.FindEntitySet("Customers"); _model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer))); _customers = new[] { new Customer() { FirstName = "Foo", LastName = "Bar", ID = 10, }, new Customer() { FirstName = "Foo", LastName = "Bar", ID = 42, } }; _customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection(); _writeContext = new ODataSerializerContext() { NavigationSource = _customerSet, Model = _model }; }
public ODataComplexTypeSerializerTests() { _model = SerializationTestsHelpers.SimpleCustomerOrderModel(); _address = new Address() { Street = "One Microsoft Way", City = "Redmond", State = "Washington", Country = "United States", ZipCode = "98052" }; _addressType = _model.FindDeclaredType("Default.Address") as IEdmComplexType; _model.SetAnnotationValue(_addressType, new ClrTypeAnnotation(typeof(Address))); _addressTypeRef = _addressType.ToEdmTypeReference(isNullable: false).AsComplex(); var cnAddressType = _model.FindDeclaredType("Default.CnAddress") as IEdmComplexType; _model.SetAnnotationValue(cnAddressType, new ClrTypeAnnotation(typeof(CnAddress))); var usAddressType = _model.FindDeclaredType("Default.UsAddress") as IEdmComplexType; _model.SetAnnotationValue(usAddressType, new ClrTypeAnnotation(typeof(UsAddress))); _locationType = _model.FindDeclaredType("Default.Location") as IEdmComplexType; _model.SetAnnotationValue(_locationType, new ClrTypeAnnotation(typeof(Location))); _locationTypeRef = _locationType.ToEdmTypeReference(isNullable: false).AsComplex(); ODataSerializerProvider serializerProvider = new DefaultODataSerializerProvider(); _serializer = new ODataComplexTypeSerializer(serializerProvider); TimeZoneInfoHelper.TimeZone = null; }
public ODataResourceSetSerializerTests() { _model = SerializationTestsHelpers.SimpleCustomerOrderModel(); _customerSet = _model.EntityContainer.FindEntitySet("Customers"); IEdmComplexType addressType = _model.SchemaElements.OfType <IEdmComplexType>() .First(c => c.Name == "Address"); _model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer))); _model.SetAnnotationValue(addressType, new ClrTypeAnnotation(typeof(Address))); _customers = new[] { new Customer() { FirstName = "Foo", LastName = "Bar", ID = 10, }, new Customer() { FirstName = "Foo", LastName = "Bar", ID = 42, } }; _customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection(); _addressesType = _model.GetEdmTypeReference(typeof(Address[])).AsCollection(); _writeContext = new ODataSerializerContext() { NavigationSource = _customerSet, Model = _model }; _serializerProvider = DependencyInjectionHelper.GetDefaultODataSerializerProvider(); }
public ODataDeltaFeedSerializerTests() { _model = SerializationTestsHelpers.SimpleCustomerOrderModel(); _customerSet = _model.EntityContainer.FindEntitySet("Customers"); _model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer))); _path = new ODataPath(new EntitySetPathSegment(_customerSet)); _customers = new[] { new Customer() { FirstName = "Foo", LastName = "Bar", ID = 10, }, new Customer() { FirstName = "Foo", LastName = "Bar", ID = 42, } }; _deltaFeedCustomers = new EdmChangedObjectCollection(_customerSet.EntityType()); EdmDeltaEntityObject newCustomer = new EdmDeltaEntityObject(_customerSet.EntityType()); newCustomer.TrySetPropertyValue("ID", 10); newCustomer.TrySetPropertyValue("FirstName", "Foo"); _deltaFeedCustomers.Add(newCustomer); _customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection(); _writeContext = new ODataSerializerContext() { NavigationSource = _customerSet, Model = _model, Path = _path }; }
public ODataCollectionSerializerTests() { _model = SerializationTestsHelpers.SimpleCustomerOrderModel(); _edmIntType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false); _serializerProvider = DependencyInjectionHelper.GetDefaultODataSerializerProvider(); _collectionType = new EdmCollectionTypeReference(new EdmCollectionType(_edmIntType)); _serializer = new ODataCollectionSerializer(_serializerProvider); }
public ODataCollectionSerializerTests() { _model = SerializationTestsHelpers.SimpleCustomerOrderModel(); _customerSet = _model.EntityContainer.FindEntitySet("Customers"); _edmIntType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false); _customer = new Customer() { FirstName = "Foo", LastName = "Bar", ID = 10, }; ODataSerializerProvider serializerProvider = new DefaultODataSerializerProvider(); _collectionType = new EdmCollectionTypeReference(new EdmCollectionType(_edmIntType)); _serializer = new ODataCollectionSerializer(serializerProvider); }
public ODataDeltaFeedSerializerTests() { _model = SerializationTestsHelpers.SimpleCustomerOrderModel(); _customerSet = _model.EntityContainer.FindEntitySet("Customers"); _model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer))); _path = new ODataPath(new EntitySetSegment(_customerSet)); _customers = new[] { new Customer() { FirstName = "Foo", LastName = "Bar", ID = 10, HomeAddress = new Address() { Street = "Street", ZipCode = null, } }, new Customer() { FirstName = "Foo", LastName = "Bar", ID = 42, } }; _deltaFeedCustomers = new EdmChangedObjectCollection(_customerSet.EntityType()); EdmDeltaEntityObject newCustomer = new EdmDeltaEntityObject(_customerSet.EntityType()); newCustomer.TrySetPropertyValue("ID", 10); newCustomer.TrySetPropertyValue("FirstName", "Foo"); EdmDeltaComplexObject newCustomerAddress = new EdmDeltaComplexObject(_model.FindType("Default.Address") as IEdmComplexType); newCustomerAddress.TrySetPropertyValue("Street", "Street"); newCustomerAddress.TrySetPropertyValue("ZipCode", null); newCustomer.TrySetPropertyValue("HomeAddress", newCustomerAddress); _deltaFeedCustomers.Add(newCustomer); _customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection(); _writeContext = new ODataSerializerContext() { NavigationSource = _customerSet, Model = _model, Path = _path }; _serializerProvider = DependencyInjectionHelper.GetDefaultODataSerializerProvider(); }
public void CreateODataComplexValue_WritesBaseAndDerivedProperties_ForDerivedComplexType() { // Arrange IEdmModel model = SerializationTestsHelpers.SimpleCustomerOrderModel(); IEdmComplexType addressType = model.FindDeclaredType("Default.CnAddress") as IEdmComplexType; Type cnAddress = typeof(CnAddress); model.SetAnnotationValue <ClrTypeAnnotation>(addressType, new ClrTypeAnnotation(cnAddress)); IEdmComplexTypeReference addressTypeRef = addressType.ToEdmTypeReference(isNullable: false).AsComplex(); ODataSerializerProvider serializerProvider = new DefaultODataSerializerProvider(); ODataComplexTypeSerializer serializer = new ODataComplexTypeSerializer(serializerProvider); ODataSerializerContext context = new ODataSerializerContext { Model = model }; Address address = new CnAddress() { Street = "One Microsoft Way", City = "Redmond", State = "Washington", Country = "United States", ZipCode = "98052", CnProp = new Guid("F83FB4CC-84BD-403B-B411-79926800F9A5") }; // Act var odataValue = serializer.CreateODataComplexValue(address, addressTypeRef, context); // Assert ODataComplexValue complexValue = Assert.IsType <ODataComplexValue>(odataValue); Assert.Equal(complexValue.TypeName, "Default.CnAddress"); Assert.Equal(6, complexValue.Properties.Count()); // Verify the derived property ODataProperty street = Assert.Single(complexValue.Properties.Where(p => p.Name == "CnProp")); Assert.Equal(new Guid("F83FB4CC-84BD-403B-B411-79926800F9A5"), street.Value); }