public async Task TestFromAndToDataWithElevatedTraits() { var corpus = TestHelper.GetLocalCorpus(testsSubpath, "TestFromAndToDataWithElevatedTraits", null); // need to set schema docs to the cdm namespace instead of using resources corpus.Storage.Mount("cdm", new LocalAdapter(TestHelper.SchemaDocumentsPath)); corpus.SetEventCallback(new EventCallback { Invoke = (CdmStatusLevel statusLevel, string message) => { if (message.Contains("unable to resolve an entity")) { Assert.Fail(); } } }, CdmStatusLevel.Warning); var entity = await corpus.FetchObjectAsync <CdmEntityDefinition>("local:/Account.cdm.json/Account"); var resEntity = await entity.CreateResolvedEntityAsync($"{entity.EntityName}_"); EntityPersistence.ToData(resEntity, new ResolveOptions(resEntity.InDocument), new CopyOptions() { StringRefs = true }); }
public override void Run () { Weapon w = new Weapon () { Name = "Best Weapon", Attachments = new List<Attachment>() { new Attachment() { Name = "Attach1" }, new Attachment() { Name = "Attach2" } } }; Console.WriteLine("Loading persistence directory..."); EntityPersistence p = new EntityPersistence ("Database"); Console.WriteLine("Writing entity with special subclass"); var id = p.WriteEntity<Weapon> (w); Console.WriteLine("Reading entity with special subclass"); Weapon read = p.RetrieveEntity<Weapon>(id); }
public override void Run() { Weapon w = new Weapon() { Name = "Best Weapon", Attachments = new List <Attachment>() { new Attachment() { Name = "Attach1" }, new Attachment() { Name = "Attach2" } } }; Console.WriteLine("Loading persistence directory..."); EntityPersistence p = new EntityPersistence("Database"); Console.WriteLine("Writing entity with special subclass"); var id = p.WriteEntity <Weapon> (w); Console.WriteLine("Reading entity with special subclass"); Weapon read = p.RetrieveEntity <Weapon>(id); }
public void Execute(ComboBox comboBox, EntityBaseCollection dataSource, EntityPersistence entityTarget, string propertyName) { comboBox.DataSource = dataSource; comboBox.DisplayMember = "Value"; comboBox.ValueMember = "Key"; object value = EntityReflection.Instance.GetValueProperty(entityTarget, propertyName); if (value != null && !string.IsNullOrEmpty(value.ToString())) { comboBox.SelectedValue = value; } Execute(comboBox, "SelectedValue", entityTarget, propertyName); }
public override void Run () { Player p = new Player () { Name = "MsgPackPlayer" }; Console.WriteLine ("Creating persistence directory..."); EntityPersistence m = new EntityPersistence ("Database"); Console.WriteLine ("Writing model"); Guid id = m.WriteEntity (p); Console.WriteLine ("Reading model"); m.RetrieveEntity<Player> (id); Console.WriteLine ("Reading nonexistent model"); m.RetrieveEntity<Player>(Guid.NewGuid()); }
public override void Run() { base.Run(); Console.WriteLine("Loading persistence directory..."); EntityPersistence p = new EntityPersistence("Database"); Console.WriteLine("Writing versioned class..."); var x = p.WriteEntity<ChangedClass>(new ChangedClass() { Id = new Guid(_fixedGuid), Name1 = "other version!" }); Console.WriteLine("Reading versioned class..."); var ent = p.RetrieveEntity<ChangedClass>(new Guid(_fixedGuid)); }
public override void Run() { base.Run(); Console.WriteLine("Loading persistence directory..."); EntityPersistence p = new EntityPersistence("Database"); Console.WriteLine("Writing versioned class..."); var x = p.WriteEntity <ChangedClass>(new ChangedClass() { Id = new Guid(_fixedGuid), Name1 = "other version!" }); Console.WriteLine("Reading versioned class..."); var ent = p.RetrieveEntity <ChangedClass>(new Guid(_fixedGuid)); }
private void setCheck(EntityPersistence entity) { if (!isCorrectTypeEntity(entity)) { return; } object valor = EntityReflection.Instance.GetValueProperty(entity, EntityProperty); if (valor != null) { Checked = Convert.ToBoolean(valor); } else { Checked = false; } }
public override void Run() { Player p = new Player() { Name = "MsgPackPlayer" }; Console.WriteLine("Creating persistence directory..."); EntityPersistence m = new EntityPersistence("Database"); Console.WriteLine("Writing model"); Guid id = m.WriteEntity(p); Console.WriteLine("Reading model"); m.RetrieveEntity <Player> (id); Console.WriteLine("Reading nonexistent model"); m.RetrieveEntity <Player>(Guid.NewGuid()); }
private bool isCorrectTypeEntity(EntityPersistence entity) { return(entitySource == entity.GetType().Name); }
public EntityManagement() { entityPersistence = new EntityPersistence(); }
public EntityEventArgs(EntityPersistence entity) { Entity = entity; }
public async Task TestPropertyPersistence() { var corpus = TestHelper.GetLocalCorpus(testsSubpath, "TestPropertyPersistence", null); var entity = await corpus.FetchObjectAsync <CdmEntityDefinition>("local:/PropertyEntity.cdm.json/PropertyEntity"); // test loading properties var attribute = entity.Attributes[0] as CdmTypeAttributeDefinition; Assert.IsTrue((bool)attribute.IsReadOnly); Assert.IsTrue((bool)attribute.IsNullable); Assert.AreEqual(attribute.SourceName, "propertyAttribute"); Assert.AreEqual(attribute.Description, "Attribute that has all properties set."); Assert.AreEqual(attribute.DisplayName, "Property Attribute"); Assert.AreEqual(attribute.SourceOrdering, 1); Assert.IsTrue((bool)attribute.ValueConstrainedToList); Assert.AreEqual(attribute.MaximumLength, 10); Assert.AreEqual(attribute.MaximumValue, "20"); Assert.AreEqual(attribute.MinimumValue, "1"); Assert.AreEqual(attribute.DataFormat, CdmDataFormat.String); Assert.AreEqual(attribute.DefaultValue[0]["displayText"], "Default"); // test loading negative value properties var negativeAttribute = entity.Attributes[1] as CdmTypeAttributeDefinition; Assert.IsFalse((bool)negativeAttribute.IsReadOnly); Assert.IsFalse((bool)negativeAttribute.IsNullable); Assert.IsNull(negativeAttribute.SourceName); Assert.IsNull(negativeAttribute.Description); Assert.IsNull(negativeAttribute.DisplayName); Assert.AreEqual(negativeAttribute.SourceOrdering, 0); Assert.IsFalse((bool)negativeAttribute.ValueConstrainedToList); Assert.AreEqual(negativeAttribute.MaximumLength, 0); Assert.AreEqual(negativeAttribute.MaximumValue, "0"); Assert.AreEqual(negativeAttribute.MinimumValue, "0"); Assert.AreEqual(negativeAttribute.DataFormat, CdmDataFormat.Unknown); Assert.AreEqual(negativeAttribute.DefaultValue[0]["displayText"], ""); // test loading values with wrongs types in file var wrongTypesAttribute = entity.Attributes[2] as CdmTypeAttributeDefinition; Assert.IsTrue((bool)wrongTypesAttribute.IsReadOnly); Assert.IsTrue((bool)wrongTypesAttribute.IsNullable); Assert.AreEqual(wrongTypesAttribute.SourceOrdering, 1); Assert.IsFalse((bool)wrongTypesAttribute.ValueConstrainedToList); Assert.AreEqual(wrongTypesAttribute.MaximumLength, 0); Assert.AreEqual(wrongTypesAttribute.MaximumValue, "20"); Assert.AreEqual(wrongTypesAttribute.MinimumValue, "0"); // test loading values with wrong types that cannot be properly converted var invalidValuesAttribute = entity.Attributes[3] as CdmTypeAttributeDefinition; Assert.IsFalse((bool)invalidValuesAttribute.IsReadOnly); Assert.IsNull(invalidValuesAttribute.MaximumLength); var entityData = EntityPersistence.ToData(entity, null, null); // test toData for properties var attributeData = entityData.HasAttributes[0].ToObject <TypeAttribute>(); Assert.IsTrue((bool)attributeData.IsReadOnly); Assert.IsTrue((bool)attributeData.IsNullable); Assert.AreEqual(attributeData.SourceName, "propertyAttribute"); Assert.AreEqual(attributeData.Description, "Attribute that has all properties set."); Assert.AreEqual(attributeData.DisplayName, "Property Attribute"); Assert.AreEqual(attributeData.SourceOrdering, 1); Assert.IsTrue((bool)attributeData.ValueConstrainedToList); Assert.AreEqual(attributeData.MaximumLength, 10); Assert.AreEqual(attributeData.MaximumValue, "20"); Assert.AreEqual(attributeData.MinimumValue, "1"); Assert.AreEqual(attributeData.DataFormat, "String"); Assert.AreEqual(attributeData.DefaultValue[0]["displayText"], "Default"); // test toData for negative value properties var negativeAttributeData = entityData.HasAttributes[1].ToObject <TypeAttribute>(); Assert.IsNull(negativeAttributeData.IsReadOnly); Assert.IsNull(negativeAttributeData.IsNullable); Assert.IsNull(negativeAttributeData.SourceName); Assert.IsNull(negativeAttributeData.Description); Assert.IsNull(negativeAttributeData.DisplayName); Assert.IsNull(negativeAttributeData.SourceOrdering); Assert.IsNull(negativeAttributeData.ValueConstrainedToList); Assert.AreEqual(negativeAttributeData.MaximumLength, 0); Assert.AreEqual(negativeAttributeData.MaximumValue, "0"); Assert.AreEqual(negativeAttributeData.MinimumValue, "0"); Assert.IsNull(negativeAttributeData.DataFormat); Assert.AreEqual(negativeAttributeData.DefaultValue[0]["displayText"], ""); // test toData for values with wrong types in file var wrongTypesAttributeData = entityData.HasAttributes[2].ToObject <TypeAttribute>(); Assert.IsTrue((bool)wrongTypesAttributeData.IsReadOnly); Assert.IsTrue((bool)wrongTypesAttributeData.IsNullable); Assert.AreEqual(wrongTypesAttributeData.SourceOrdering, 1); Assert.IsNull(wrongTypesAttributeData.ValueConstrainedToList); Assert.AreEqual(wrongTypesAttributeData.MaximumLength, 0); Assert.AreEqual(wrongTypesAttributeData.MaximumValue, "20"); Assert.AreEqual(wrongTypesAttributeData.MinimumValue, "0"); // test toData with wrong types that cannot be properly converted var invalidValuesAttributeData = entityData.HasAttributes[3].ToObject <TypeAttribute>(); Assert.IsNull(invalidValuesAttributeData.IsReadOnly); Assert.IsNull(invalidValuesAttributeData.MaximumLength); }
public async Task TestPropertyPersistence() { var corpus = TestHelper.GetLocalCorpus(testsSubpath, "TestPropertyPersistence", null); var callback = new EventCallback(); var functionWasCalled = false; var functionParameter1 = CdmStatusLevel.Info; string functionParameter2 = null; callback.Invoke = (CdmStatusLevel statusLevel, string message1) => { functionWasCalled = true; if (statusLevel.Equals(CdmStatusLevel.Error)) { functionParameter1 = statusLevel; functionParameter2 = message1; } }; corpus.SetEventCallback(callback); var entity = await corpus.FetchObjectAsync <CdmEntityDefinition>("local:/PropertyEntity.cdm.json/PropertyEntity"); // test loading properties var attribute = entity.Attributes[0] as CdmTypeAttributeDefinition; Assert.IsTrue((bool)attribute.IsReadOnly); Assert.IsTrue((bool)attribute.IsNullable); Assert.AreEqual(attribute.SourceName, "propertyAttribute"); Assert.AreEqual(attribute.Description, "Attribute that has all properties set."); Assert.AreEqual(attribute.DisplayName, "Property Attribute"); Assert.AreEqual(attribute.SourceOrdering, 1); Assert.IsTrue((bool)attribute.ValueConstrainedToList); Assert.AreEqual(attribute.MaximumLength, 10); Assert.AreEqual(attribute.MaximumValue, "20"); Assert.AreEqual(attribute.MinimumValue, "1"); Assert.AreEqual(attribute.DataFormat, CdmDataFormat.String); Assert.AreEqual(attribute.DefaultValue[0]["displayText"], "Default"); // test loading negative value properties var negativeAttribute = entity.Attributes[1] as CdmTypeAttributeDefinition; Assert.IsFalse((bool)negativeAttribute.IsReadOnly); Assert.IsFalse((bool)negativeAttribute.IsNullable); Assert.IsNull(negativeAttribute.SourceName); Assert.IsNull(negativeAttribute.Description); Assert.IsNull(negativeAttribute.DisplayName); Assert.AreEqual(negativeAttribute.SourceOrdering, 0); Assert.IsFalse((bool)negativeAttribute.ValueConstrainedToList); Assert.AreEqual(negativeAttribute.MaximumLength, 0); Assert.AreEqual(negativeAttribute.MaximumValue, "0"); Assert.AreEqual(negativeAttribute.MinimumValue, "0"); Assert.AreEqual(negativeAttribute.DataFormat, CdmDataFormat.Unknown); Assert.AreEqual(negativeAttribute.DefaultValue[0]["displayText"], ""); // test loading values with wrongs types in file var wrongTypesAttribute = entity.Attributes[2] as CdmTypeAttributeDefinition; Assert.IsTrue((bool)wrongTypesAttribute.IsReadOnly); Assert.IsTrue((bool)wrongTypesAttribute.IsNullable); Assert.AreEqual(wrongTypesAttribute.SourceOrdering, 1); Assert.IsFalse((bool)wrongTypesAttribute.ValueConstrainedToList); Assert.AreEqual(wrongTypesAttribute.MaximumLength, 0); Assert.AreEqual(wrongTypesAttribute.MaximumValue, "20"); Assert.AreEqual(wrongTypesAttribute.MinimumValue, "0"); // test loading values with wrong types that cannot be properly converted var invalidValuesAttribute = entity.Attributes[3] as CdmTypeAttributeDefinition; Assert.IsFalse((bool)invalidValuesAttribute.IsReadOnly); Assert.IsNull(invalidValuesAttribute.MaximumLength); // test loading values with empty default value list that should log error var emptyDefaultValueAttribute = entity.Attributes[4] as CdmTypeAttributeDefinition; // test log error "Default value missing languageTag or displayText." Assert.IsTrue(functionWasCalled); Assert.AreEqual(CdmStatusLevel.Error, functionParameter1); Assert.IsTrue(functionParameter2.Contains("Default value missing languageTag or displayText.")); Assert.IsNull(emptyDefaultValueAttribute.DefaultValue); // set the default value to an empty list for testing that it should be removed from the generated json. emptyDefaultValueAttribute.DefaultValue = new List <object>(); var entityData = EntityPersistence.ToData(entity, null, null); // test toData for properties var attributeData = entityData.HasAttributes[0].ToObject <TypeAttribute>(); Assert.IsTrue((bool)attributeData.IsReadOnly); Assert.IsTrue((bool)attributeData.IsNullable); Assert.AreEqual(attributeData.SourceName, "propertyAttribute"); Assert.AreEqual(attributeData.Description, "Attribute that has all properties set."); Assert.AreEqual(attributeData.DisplayName, "Property Attribute"); Assert.AreEqual(attributeData.SourceOrdering, 1); Assert.IsTrue((bool)attributeData.ValueConstrainedToList); Assert.AreEqual(attributeData.MaximumLength, 10); Assert.AreEqual(attributeData.MaximumValue, "20"); Assert.AreEqual(attributeData.MinimumValue, "1"); Assert.AreEqual(attributeData.DataFormat, "String"); Assert.AreEqual(attributeData.DefaultValue[0]["displayText"], "Default"); // test toData for negative value properties var negativeAttributeData = entityData.HasAttributes[1].ToObject <TypeAttribute>(); Assert.IsNull(negativeAttributeData.IsReadOnly); Assert.IsNull(negativeAttributeData.IsNullable); Assert.IsNull(negativeAttributeData.SourceName); Assert.IsNull(negativeAttributeData.Description); Assert.IsNull(negativeAttributeData.DisplayName); Assert.IsNull(negativeAttributeData.SourceOrdering); Assert.IsNull(negativeAttributeData.ValueConstrainedToList); Assert.AreEqual(negativeAttributeData.MaximumLength, 0); Assert.AreEqual(negativeAttributeData.MaximumValue, "0"); Assert.AreEqual(negativeAttributeData.MinimumValue, "0"); Assert.IsNull(negativeAttributeData.DataFormat); Assert.AreEqual(negativeAttributeData.DefaultValue[0]["displayText"], ""); // test toData for values with wrong types in file var wrongTypesAttributeData = entityData.HasAttributes[2].ToObject <TypeAttribute>(); Assert.IsTrue((bool)wrongTypesAttributeData.IsReadOnly); Assert.IsTrue((bool)wrongTypesAttributeData.IsNullable); Assert.AreEqual(wrongTypesAttributeData.SourceOrdering, 1); Assert.IsNull(wrongTypesAttributeData.ValueConstrainedToList); Assert.AreEqual(wrongTypesAttributeData.MaximumLength, 0); Assert.AreEqual(wrongTypesAttributeData.MaximumValue, "20"); Assert.AreEqual(wrongTypesAttributeData.MinimumValue, "0"); // test toData with wrong types that cannot be properly converted var invalidValuesAttributeData = entityData.HasAttributes[3].ToObject <TypeAttribute>(); Assert.IsNull(invalidValuesAttributeData.IsReadOnly); Assert.IsNull(invalidValuesAttributeData.MaximumLength); // test toData with empty default value list that should be written as null var emptyDefaultValueAttributeData = entityData.HasAttributes[4].ToObject <TypeAttribute>(); Assert.IsNull(emptyDefaultValueAttributeData.DefaultValue); }