Exemple #1
0
        public void Multi_Type_Entity_Test()
        {
            var intEntity = new IntEntity()
            {
                Id = 1
            };
            var longEntity = new LongEntity()
            {
                Id = 1
            };
            var stringEntity = new StringEntity()
            {
                Id = "A"
            };
            var guidEntity = new GuidEntity()
            {
                Id = new Guid()
            };
            var userEntity = new UserEntity()
            {
                Id = { No = 1, Code = "AA" }
            };

            Assert.NotNull(intEntity);
            Assert.NotNull(longEntity);
            Assert.NotNull(stringEntity);
            Assert.NotNull(guidEntity);
            Assert.NotNull(userEntity);
        }
        public void TestSaveIntEntity()
        {
            var entity = new IntEntity {
                IntField = 16
            };
            IntEntity savedEntity = Backendless.Persistence.Save(entity);

            Assert.IsNotNull(savedEntity, "Server returned a null result");
            Assert.IsNotNull(savedEntity.ObjectId, "Returned object doesn't have expected field id");
            Assert.IsNotNull(savedEntity.Created, "Returned object doesn't have expected field created");
            Assert.AreEqual(entity.IntField, savedEntity.IntField, "Returned object has wrong field value");
        }
        public void PropertyMap_WhenUsingSetter_ShouldSetTheValueInTheEntityProperty()
        {
            const int newId = 12345;

            var sut = BuildMap <IntEntity, int>(x => x.Id);

            var entity = new IntEntity();

            sut.Setter(entity, newId);

            sut.AssertPropertyMap(IdColumnName);

            Assert.Equal(entity.Id, newId);
        }
        public void PropertyMap_WhenUsingGetter_ShouldGetterTheCurrentValueFromTheEntityProperty()
        {
            const int newId = 54321;

            var sut = BuildMap <IntEntity, int>(x => x.Id);

            var entity = new IntEntity {
                Id = newId
            };

            var result = sut.Getter(entity);

            sut.AssertPropertyMap(IdColumnName);

            Assert.Equal(result, newId);
        }
Exemple #5
0
        public void Entity_No_Equals_Test()
        {
            var intEntity = new IntEntity()
            {
                Id = 1
            };
            var longEntity = new LongEntity()
            {
                Id = 1
            };

            Assert.False(intEntity.Equals(longEntity));


            var guidEntity1 = new GuidEntity();
            var guidEntity2 = new GuidEntity();

            Assert.False(guidEntity1.Equals(guidEntity2));
        }
Exemple #6
0
        public void Entity_IsTransient_Test()
        {
            var intEntity = new IntEntity();

            Assert.True(intEntity.IsTransient());

            var longEntity = new LongEntity();

            Assert.True(longEntity.IsTransient());

            var stringEntity = new StringEntity();

            Assert.True(stringEntity.IsTransient());

            var guidEntity = new GuidEntity();

            Assert.True(guidEntity.IsTransient());

            var userEntity = new UserEntity();

            Assert.True(userEntity.IsTransient());
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var uiDoc =
                commandData.Application.ActiveUIDocument;

            Reference r;

            try
            {
                r = uiDoc.Selection.PickObject(ObjectType.Element);
            }
            catch (Exception ex)
            {
                return(Result.Cancelled);
            }

            var element =
                uiDoc
                .Document
                .GetElement(r.ElementId);
            // Create a new instance of the class
            IntEntity intEntity =
                new IntEntity();

            // Set property value
            intEntity.SomeValue = 777;

            // attach to the element
            element.SetEntity(intEntity);


            //read entity
            var intEntity2 =
                element.GetEntity <IntEntity>();

            if (intEntity2 != null)
            {
                TaskDialog.Show(intEntity2.GetType().Name, intEntity2.SomeValue.ToString());
            }


            // 1. Looking for the schema in the memory
            Schema schema = Schema.Lookup(new Guid("4E5B6F62-B8B3-4A2F-9B06-DDD953D4D4BC"));

            // 2. Check if schema exists in the memory or not
            if (schema == null)
            {
                //3. Create it, if not
                schema = CreateSchema();
            }

            // 4. Create entity of the specific schema
            var entity = new Entity(schema);

            // 5. Set the value for the Field.
            // HERE WE HAVE TO REMEMEBER THE NAME OF THE SCHEMA FIELD
            entity.Set("SomeValue", 888);

            // 6. Attach entity to the element
            element.SetEntity(entity);

            // read

            var schema2 =
                Schema.Lookup(new Guid("4E5B6F62-B8B3-4A2F-9B06-DDD953D4D4BC"));

            if (schema2 != null)
            {
                var entity2   = element.GetEntity(schema2);
                var someValue =
                    entity2.Get <int>("SomeValue");
                TaskDialog.Show("Entity value", someValue.ToString());
            }


            //write entity with map and array field

            // Check if schema exists in the memory.
            var schema3 =
                Schema.Lookup(new Guid("1899FD3C-7046-4B53-945A-AA1370B8C577"));

            if (schema3 == null)
            {
                // create if not
                schema3 = CreateComplexSchema();
            }

            var entity4 =
                new Entity(schema3);

            //Map fields
            IDictionary <int, Entity> mapOfEntities =
                new Dictionary <int, Entity>();

            // create sub-entity 1
            var entity7 =
                new Entity(new Guid("4E5B6F62-B8B3-4A2F-9B06-DDD953D4D4BC"));

            entity7.Set("SomeValue", 7);

            // create sub-entity 2
            var entity8 =
                new Entity(new Guid("4E5B6F62-B8B3-4A2F-9B06-DDD953D4D4BC"));

            entity8.Set("SomeValue", 8);

            mapOfEntities.Add(7, entity7);
            mapOfEntities.Add(8, entity8);

            entity4.Set("MapField", mapOfEntities);

            element.SetEntity(entity4);


            //Change value in map field

            var entity10 =
                element.GetEntity(schema3);

            var mapField =
                entity10.Get <IDictionary <int, Entity> >("MapField");

            if (mapField != null)
            {
                if (mapField.ContainsKey(8))
                {
                    var entity11 = mapField[8];
                    entity11.Set("SomeValue", 999);

                    // write changes =
                    entity10.Set("MapField", mapField);

                    element.SetEntity(entity10);
                }
            }


            // the same with Extension
            ComplexEntity complexEntity =
                new ComplexEntity();

            complexEntity.MapField =
                new Dictionary <int, IntEntity>
            {
                { 9, new IntEntity()
                  {
                      SomeValue = 9
                  } },
                { 10, new IntEntity()
                  {
                      SomeValue = 10
                  } }
            };

            element.SetEntity(complexEntity);

            //Change value in map field
            var complexEntity2 =
                element.GetEntity <ComplexEntity>();

            if (complexEntity2 != null)
            {
                if (complexEntity.MapField.ContainsKey(9))
                {
                    var entityInMapField =
                        complexEntity.MapField[9];
                    entityInMapField.SomeValue = 9898;

                    element.SetEntity(complexEntity2);
                }
            }

            return(Result.Succeeded);
        }