public void CreateODataComplexValue_WritesDerivedComplexTypeProperty()
        {
            // Arrange
            Location location = new Location
            {
                Name = "Location #2",
                Address = new CnAddress
                {
                    City = "Shanghai",
                    CnProp = new Guid("87f049bd-9976-4843-9434-a5735b0daf10"),
                    Country = "CN",
                    State = "Shanghai",
                    Street = "ZiXing Rd",
                    ZipCode = "200241"
                }
            };

            // Act
            var odataValue = _serializer.CreateODataComplexValue(location, _locationTypeRef, new ODataSerializerContext { Model = _model });
            ODataComplexValue complexValue = Assert.IsType<ODataComplexValue>(odataValue);

            // Assert
            Assert.Equal(complexValue.TypeName, "Default.Location");
            Assert.Equal(2, complexValue.Properties.Count());

            ODataProperty name = Assert.Single(complexValue.Properties.Where(p => p.Name == "Name"));
            Assert.Equal("Location #2", name.Value);

            ODataProperty address = Assert.Single(complexValue.Properties.Where(p => p.Name == "Address"));
            ODataComplexValue addressComplexValue = Assert.IsType<ODataComplexValue>(address.Value);

            Assert.Equal(addressComplexValue.TypeName, "Default.CnAddress");

            Assert.Equal(
                addressComplexValue.Properties.Select(p => Tuple.Create(p.Name, p.Value.ToString())),
                new[] { 
                    Tuple.Create("Street","ZiXing Rd"), 
                    Tuple.Create("City","Shanghai"),
                    Tuple.Create("State","Shanghai"),
                    Tuple.Create("Country", "CN"),
                    Tuple.Create("ZipCode","200241"),
                    Tuple.Create("CnProp","87f049bd-9976-4843-9434-a5735b0daf10")});
        }
        public void CreateODataComplexValue_WritesDerivedComplexTypeProperty_IfNull()
        {
            // Arrange
            Location location = new Location
            {
                Name = "Location #3",
                Address = null
            };

            // Act
            var odataValue = _serializer.CreateODataComplexValue(location, _locationTypeRef, new ODataSerializerContext { Model = _model });
            ODataComplexValue complexValue = Assert.IsType<ODataComplexValue>(odataValue);

            // Assert
            Assert.Equal(complexValue.TypeName, "Default.Location");
            Assert.Equal(2, complexValue.Properties.Count());

            ODataProperty name = Assert.Single(complexValue.Properties.Where(p => p.Name == "Name"));
            Assert.Equal("Location #3", name.Value);

            ODataProperty address = Assert.Single(complexValue.Properties.Where(p => p.Name == "Address"));
            Assert.Null(address.Value);
        }
        public void CreateODataComplexValue_WritesBaseComplexTypeProperty()
        {
            // Arrange
            Location location = new Location
            {
                Name = "Location #1",
                Address = _address
            };

            // Act
            var odataValue = _serializer.CreateODataComplexValue(location, _locationTypeRef, new ODataSerializerContext { Model = _model });
            ODataComplexValue complexValue = Assert.IsType<ODataComplexValue>(odataValue);

            // Assert
            Assert.Equal(complexValue.TypeName, "Default.Location");
            Assert.Equal(2, complexValue.Properties.Count());

            ODataProperty name = Assert.Single(complexValue.Properties.Where(p => p.Name == "Name"));
            Assert.Equal("Location #1", name.Value);

            ODataProperty address = Assert.Single(complexValue.Properties.Where(p => p.Name == "Address"));
            ODataComplexValue addressComplexValue = Assert.IsType<ODataComplexValue>(address.Value);

            Assert.Equal(addressComplexValue.TypeName, "Default.Address");

            Assert.Equal(
                addressComplexValue.Properties.Select(p => Tuple.Create(p.Name, p.Value as string)),
                new[] { 
                    Tuple.Create("Street","One Microsoft Way"),
                    Tuple.Create("City","Redmond"),
                    Tuple.Create("State","Washington"),
                    Tuple.Create("Country", "United States"),
                    Tuple.Create("ZipCode","98052") });
        }