public void AutoComputeETagWithOptimisticConcurrencyControlAnnotation()
        {
            const string expected = "{" +
                "\"@odata.context\":\"http://example.com/$metadata#People/$entity\"," +
                "\"@odata.id\":\"People(123)\"," +
                "\"@odata.etag\":\"W/\\\"'lucy',12306\\\"\"," +
                "\"@odata.editLink\":\"People(123)\"," +
                "\"@odata.mediaEditLink\":\"People(123)/$value\"," +
                "\"ID\":123," +
                "\"Name\":\"lucy\"," +
                "\"Class\":12306," +
                "\"Alias\":\"lily\"}";
            EdmModel model = new EdmModel();

            EdmEntityType personType = new EdmEntityType("MyNs", "Person", null, false, false, true);
            personType.AddKeys(personType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            var nameProperty = personType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: true));
            var classProperty = personType.AddStructuralProperty("Class", EdmPrimitiveTypeKind.Int32);
            personType.AddStructuralProperty("Alias", EdmCoreModel.Instance.GetString(isNullable: true), null, EdmConcurrencyMode.Fixed);

            var container = new EdmEntityContainer("MyNs", "Container");
            model.AddElement(personType);
            container.AddEntitySet("People", personType);
            model.AddElement(container);

            IEdmEntitySet peopleSet = model.FindDeclaredEntitySet("People");
            model.SetOptimisticConcurrencyControlAnnotation(peopleSet, new[] {nameProperty, classProperty});
            ODataEntry entry = new ODataEntry
            {
                Properties = new[]
                {
                    new ODataProperty {Name = "ID", Value = 123}, 
                    new ODataProperty {Name = "Name", Value = "lucy"}, 
                    new ODataProperty {Name = "Class", Value = 12306}, 
                    new ODataProperty {Name = "Alias", Value = "lily"},
                }
            };

            string actual = GetWriterOutputForContentTypeAndKnobValue(entry, model, peopleSet, personType);
            Assert.Equal(expected, actual);
        }
        public void TestCoreOptimisticConcurrencyControlInlineAnnotation()
        {
            EdmModel model = new EdmModel();

            EdmEntityContainer container = new EdmEntityContainer("DefaultNamespace", "Container");
            EdmEntityType personType = new EdmEntityType("DefaultNamespace", "Person");
            EdmStructuralProperty propertyId = personType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            personType.AddKeys(propertyId);
            IEdmStructuralProperty concurrencyProperty = personType.AddStructuralProperty("Concurrency", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(personType);
            container.AddEntitySet("People", personType);
            model.AddElement(container);
            container.AddEntitySet("Students", personType);

            IEdmEntitySet peopleSet = model.FindDeclaredEntitySet("People");
            model.SetOptimisticConcurrencyControlAnnotation(peopleSet, new[] { concurrencyProperty });
            model.SetOptimisticConcurrencyControlAnnotation(peopleSet, new[] { concurrencyProperty });

            IEdmEntitySet studentSet = model.FindDeclaredEntitySet("Students");
            model.SetOptimisticConcurrencyControlAnnotation(studentSet, new[] { concurrencyProperty });

            IEnumerable<EdmError> errors;
            StringWriter sw = new StringWriter();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.Encoding = System.Text.Encoding.UTF8;
            XmlWriter xw = XmlWriter.Create(sw, settings);
            model.TryWriteCsdl(xw, out errors);
            xw.Flush();
            xw.Close();
            var actual = sw.ToString();

            const string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""DefaultNamespace"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
  <EntityType Name=""Person"">
    <Key>
      <PropertyRef Name=""Id"" />
    </Key>
    <Property Name=""Id"" Type=""Edm.Int32"" Nullable=""false"" />
    <Property Name=""Concurrency"" Type=""Edm.Int32"" />
  </EntityType>
  <EntityContainer Name=""Container"">
    <EntitySet Name=""People"" EntityType=""DefaultNamespace.Person"">
      <Annotation Term=""Org.OData.Core.V1.OptimisticConcurrencyControl"">
        <Collection>
          <PropertyPath>Concurrency</PropertyPath>
        </Collection>
      </Annotation>
    </EntitySet>
    <EntitySet Name=""Students"" EntityType=""DefaultNamespace.Person"">
      <Annotation Term=""Org.OData.Core.V1.OptimisticConcurrencyControl"">
        <Collection>
          <PropertyPath>Concurrency</PropertyPath>
        </Collection>
      </Annotation>
    </EntitySet>
  </EntityContainer>
</Schema>";

            Assert.AreEqual(expected, actual);
        }