// TODO: Change the payload of null top-level properties #645
        public void NonNullablePropertiesWithNullValuesTest()
        {
            IEnumerable <NonNullablePropertyTest> testCases = new NonNullablePropertyTest[]
            {
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetString(false), TypeName = "Edm.String"
                },
                new NonNullablePropertyTest {
                    Value = "foo", DataType = EdmCoreModel.Instance.GetString(false), TypeName = "Edm.String"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetBinary(false), TypeName = "Edm.Binary"
                },
                new NonNullablePropertyTest {
                    Value = new byte[] { 1, 2, 3 }, DataType = EdmCoreModel.Instance.GetBinary(false), TypeName = "Edm.Binary"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetBoolean(false), TypeName = "Edm.Boolean"
                },
                new NonNullablePropertyTest {
                    Value = true, DataType = EdmCoreModel.Instance.GetBoolean(false), TypeName = "Edm.Boolean"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetByte(false), TypeName = "Edm.Byte"
                },
                new NonNullablePropertyTest {
                    Value = (byte)1, DataType = EdmCoreModel.Instance.GetByte(false), TypeName = "Edm.Byte"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetDateTimeOffset(false), TypeName = "Edm.DateTimeOffset"
                },
                new NonNullablePropertyTest {
                    Value = new DateTimeOffset(new DateTime(2011, 08, 31), TimeSpan.Zero), DataType = EdmCoreModel.Instance.GetDateTimeOffset(false), TypeName = "Edm.DateTimeOffset"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetDecimal(false), TypeName = "Edm.Decimal"
                },
                new NonNullablePropertyTest {
                    Value = (decimal)1.0, DataType = EdmCoreModel.Instance.GetDecimal(false), TypeName = "Edm.Decimal"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetDouble(false), TypeName = "Edm.Double"
                },
                new NonNullablePropertyTest {
                    Value = (double)1.0, DataType = EdmCoreModel.Instance.GetDouble(false), TypeName = "Edm.Double"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetSingle(false), TypeName = "Edm.Single"
                },
                new NonNullablePropertyTest {
                    Value = (float)1.0, DataType = EdmCoreModel.Instance.GetSingle(false), TypeName = "Edm.Single"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetSByte(false), TypeName = "Edm.SByte"
                },
                new NonNullablePropertyTest {
                    Value = (sbyte)1, DataType = EdmCoreModel.Instance.GetSByte(false), TypeName = "Edm.SByte"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetInt16(false), TypeName = "Edm.Int16"
                },
                new NonNullablePropertyTest {
                    Value = (Int16)1, DataType = EdmCoreModel.Instance.GetInt16(false), TypeName = "Edm.Int16"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetInt32(false), TypeName = "Edm.Int32"
                },
                new NonNullablePropertyTest {
                    Value = (Int32)1, DataType = EdmCoreModel.Instance.GetInt32(false), TypeName = "Edm.Int32"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetInt64(false), TypeName = "Edm.Int64"
                },
                new NonNullablePropertyTest {
                    Value = (Int64)1, DataType = EdmCoreModel.Instance.GetInt64(false), TypeName = "Edm.Int64"
                },
                new NonNullablePropertyTest {
                    Value = null, DataType = EdmCoreModel.Instance.GetGuid(false), TypeName = "Edm.Guid"
                },
                new NonNullablePropertyTest {
                    Value = Guid.NewGuid(), DataType = EdmCoreModel.Instance.GetGuid(false), TypeName = "Edm.Guid"
                },
            };

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors =
                testCases.Select(testCase => new PayloadReaderTestDescriptor(this.Settings)
            {
                PayloadElement    = PayloadBuilder.PrimitiveValue(testCase.Value).WithTypeAnnotation(testCase.DataType),
                PayloadEdmModel   = new EdmModel().Fixup(),
                ExpectedException = testCase.Value == null
                        ? ODataExpectedExceptions.ODataException("ReaderValidationUtils_NullNamedValueForNonNullableType", "value", testCase.TypeName)
                        : null,
            });

            testDescriptors = testDescriptors.Select(td => td.InProperty("propertyName"));
            testDescriptors = testDescriptors.SelectMany(td => this.PayloadGenerator.GenerateReaderPayloads(td));

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                if (!(testDescriptor.PayloadElement is PrimitiveProperty) &&
                    testDescriptor.ExpectedException != null)
                {
                    testDescriptor = new PayloadReaderTestDescriptor(testDescriptor);
                    testDescriptor.ExpectedException = ODataExpectedExceptions.ODataException(
                        "ReaderValidationUtils_NullNamedValueForNonNullableType",
                        "propertyName",
                        testDescriptor.ExpectedException.ExpectedMessage.Arguments.ElementAt(1));
                }

                var property = testDescriptor.PayloadElement as PropertyInstance;

                testDescriptor.RunTest(testConfiguration);
            });
        }
        public void NonNullablePropertiesWithNullValuesTest()
        {
            IEnumerable<NonNullablePropertyTest> testCases = new NonNullablePropertyTest[]
            {
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetString(false), TypeName = "Edm.String" },
                new NonNullablePropertyTest { Value = "foo", DataType = EdmCoreModel.Instance.GetString(false), TypeName = "Edm.String" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetBinary(false), TypeName = "Edm.Binary" },
                new NonNullablePropertyTest { Value = new byte[] { 1, 2, 3 }, DataType = EdmCoreModel.Instance.GetBinary(false), TypeName = "Edm.Binary" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetBoolean(false), TypeName = "Edm.Boolean" },
                new NonNullablePropertyTest { Value = true, DataType = EdmCoreModel.Instance.GetBoolean(false), TypeName = "Edm.Boolean" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetByte(false), TypeName = "Edm.Byte" },
                new NonNullablePropertyTest { Value = (byte)1, DataType = EdmCoreModel.Instance.GetByte(false), TypeName = "Edm.Byte" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetDateTimeOffset(false), TypeName = "Edm.DateTimeOffset" },
                new NonNullablePropertyTest { Value = new DateTimeOffset(new DateTime(2011, 08, 31), TimeSpan.Zero), DataType = EdmCoreModel.Instance.GetDateTimeOffset(false), TypeName = "Edm.DateTimeOffset" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetDecimal(false), TypeName = "Edm.Decimal" },
                new NonNullablePropertyTest { Value = (decimal)1.0, DataType = EdmCoreModel.Instance.GetDecimal(false), TypeName = "Edm.Decimal" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetDouble(false), TypeName = "Edm.Double" },
                new NonNullablePropertyTest { Value = (double)1.0, DataType = EdmCoreModel.Instance.GetDouble(false), TypeName = "Edm.Double" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetSingle(false), TypeName = "Edm.Single" },
                new NonNullablePropertyTest { Value = (float)1.0, DataType = EdmCoreModel.Instance.GetSingle(false), TypeName = "Edm.Single" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetSByte(false), TypeName = "Edm.SByte" },
                new NonNullablePropertyTest { Value = (sbyte)1, DataType = EdmCoreModel.Instance.GetSByte(false), TypeName = "Edm.SByte" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetInt16(false), TypeName = "Edm.Int16" },
                new NonNullablePropertyTest { Value = (Int16)1, DataType = EdmCoreModel.Instance.GetInt16(false), TypeName = "Edm.Int16" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetInt32(false), TypeName = "Edm.Int32" },
                new NonNullablePropertyTest { Value = (Int32)1, DataType = EdmCoreModel.Instance.GetInt32(false), TypeName = "Edm.Int32" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetInt64(false), TypeName = "Edm.Int64" },
                new NonNullablePropertyTest { Value = (Int64)1, DataType = EdmCoreModel.Instance.GetInt64(false), TypeName = "Edm.Int64" },
                new NonNullablePropertyTest { Value = null, DataType = EdmCoreModel.Instance.GetGuid(false), TypeName = "Edm.Guid" },
                new NonNullablePropertyTest { Value = Guid.NewGuid(), DataType = EdmCoreModel.Instance.GetGuid(false), TypeName = "Edm.Guid" },
            };

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors =
                testCases.Select(testCase => new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.PrimitiveValue(testCase.Value).WithTypeAnnotation(testCase.DataType),
                    PayloadEdmModel = new EdmModel().Fixup(),
                    ExpectedException = testCase.Value == null
                        ? ODataExpectedExceptions.ODataException("ReaderValidationUtils_NullValueForNonNullableType", testCase.TypeName)
                        : null,
                });

            testDescriptors = testDescriptors.Select(td => td.InProperty("propertyName"));
            testDescriptors = testDescriptors.SelectMany(td => this.PayloadGenerator.GenerateReaderPayloads(td));

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    if (!(testDescriptor.PayloadElement is PrimitiveProperty)
                        && testDescriptor.ExpectedException != null)
                    {
                        testDescriptor = new PayloadReaderTestDescriptor(testDescriptor);
                        testDescriptor.ExpectedException = ODataExpectedExceptions.ODataException(
                            "ReaderValidationUtils_NullNamedValueForNonNullableType",
                            "propertyName",
                            testDescriptor.ExpectedException.ExpectedMessage.Arguments.ElementAt(0));
                    }

                    var property = testDescriptor.PayloadElement as PropertyInstance;
                    if (property != null && testConfiguration.Format == ODataFormat.Atom)
                    {
                        property.Name = null;
                    }

                    testDescriptor.RunTest(testConfiguration);
                });
        }