public async Task TestCardinalityPersistence() { var corpus = TestHelper.GetLocalCorpus(testsSubpath, "TestCardinalityPersistence", null); // test FromData var entity = await corpus.FetchObjectAsync <CdmEntityDefinition>("local:/someEntity.cdm.json/someEntity"); var attribute = (CdmTypeAttributeDefinition)entity.Attributes[0]; Assert.IsNotNull(attribute.Cardinality); Assert.AreEqual(attribute.Cardinality.Minimum, "0"); Assert.AreEqual(attribute.Cardinality.Maximum, "1"); // test ToData var attributeData = TypeAttributePersistence.ToData(attribute, new ResolveOptions(entity.InDocument), new CopyOptions()); Assert.IsNotNull(attributeData.Cardinality); Assert.IsNotNull(attributeData.Cardinality.Minimum, "0"); Assert.IsNotNull(attributeData.Cardinality.Maximum, "1"); }
public void TestNonNullDefaultValueAttribute() { JArray jArray = new JArray( new JObject( new JProperty("languageTag", "en"), new JProperty("displayText", "Preferred Customer"), new JProperty("attributeValue", "1"), new JProperty("displayOrder", "0")), new JObject( new JProperty("languageTag", "en"), new JProperty("displayText", "Standard"), new JProperty("attributeValue", "2"), new JProperty("displayOrder", "1"))); JObject input = new JObject(new JProperty("defaultValue", jArray)); CdmTypeAttributeDefinition cdmTypeAttributeDefinition = TypeAttributePersistence.FromData(new ResolveContext(new CdmCorpusDefinition(), null), input); TypeAttribute result = PersistenceLayer.ToData <CdmTypeAttributeDefinition, TypeAttribute>(cdmTypeAttributeDefinition, null, null, PersistenceLayer.CdmFolder); Assert.IsNotNull(result); Assert.IsTrue(JToken.DeepEquals(input["defaultValue"], result.DefaultValue)); }