Beispiel #1
0
        public void GetObjectDefinitionByGroupTest()
        {
            IObjectService service          = new DefaultObjectService();
            var            objectGroup      = service.GetObjectDefinitionGroups(null, null)[0];
            var            objectDefinition = service.GetObjectDefinitionsByGroup(objectGroup.GroupID, 1, 10, null);

            Assert.True(objectDefinition.Count > 0);
        }
Beispiel #2
0
        private static IObjectService Setup()
        {
            IStartupSetting setting = ConfigSectionHandler.GetConfig("htb.devfx").ToSetting <StartupSetting>("startup");
            string          configServiceTypeName = null;
            string          objectServiceTypeName = null;

            if (setting != null && setting.CoreSetting != null)
            {
                if (setting.CoreSetting.ConfigServiceSetting != null)
                {
                    configServiceTypeName = setting.CoreSetting.ConfigServiceSetting.TypeName;
                }
                if (setting.CoreSetting.ObjectServiceSetting != null)
                {
                    objectServiceTypeName = setting.CoreSetting.ObjectServiceSetting.TypeName;
                }
            }

            IConfigService configServiceInstance = null;

            if (!string.IsNullOrEmpty(configServiceTypeName))
            {
                configServiceInstance = (IConfigService)TypeHelper.CreateObject(configServiceTypeName, typeof(IConfigService), false);
            }
            if (configServiceInstance == null)
            {
                configServiceInstance = Config.ConfigService.Default;
            }

            if (configServiceInstance is IConfigServiceInternal)
            {
                ((IConfigServiceInternal)configServiceInstance).Init(setting);
            }
            else if (configServiceInstance is IInitializable)
            {
                ((IInitializable)configServiceInstance).Init();
            }

            IObjectService objectServiceInstance = null;

            if (!string.IsNullOrEmpty(objectServiceTypeName))
            {
                objectServiceInstance = (IObjectService)TypeHelper.CreateObject(objectServiceTypeName, typeof(IObjectService), false);
            }
            if (objectServiceInstance == null)
            {
                objectServiceInstance = new DefaultObjectService();
            }
            if (objectServiceInstance is IObjectServiceInternal)
            {
                ((IObjectServiceInternal)objectServiceInstance).Init(configServiceInstance);
            }
            else if (objectServiceInstance is IInitializable)
            {
                ((IInitializable)objectServiceInstance).Init();
            }
            return(objectServiceInstance);
        }
Beispiel #3
0
        private static IObjectService Setup(IDictionary items)
        {
            var appSetting     = ConfigHelper.CreateFromXmlFile("app.config") ?? ConfigHelper.CreateFromXmlFile(Assembly.GetEntryAssembly().ManifestModule.Name + ".config");
            var startupSetting = appSetting?.ToSetting <StartupSetting>($"{ConfigHelper.RootSettingName}/startup");
            var setting        = ConfigServiceBase.Init(startupSetting, appSetting);

            var objectServiceInstance = new DefaultObjectService();

            objectServiceInstance.Init(setting, items);
            return(objectServiceInstance);
        }
Beispiel #4
0
        public void UpdateObjectTest()
        {
            IObjectService service  = new DefaultObjectService();
            ServiceObject  svObject = service.GetAllSerivceObjects(service.GetAllObjectDefinitions()[0].ObjectDefinitionID, null, null)[0];

            svObject.OnlyUpdateProperties = true;

            svObject.Properties.Add(new ObjectKeyValuePair()
            {
                KeyName = "Person Name",
                Value   = new PrimeObjectField()
                {
                    PrimeDataType = PrimeFieldDataType.String,
                    Value         = "Peter, Robert - Updated"
                }
            });

            svObject.Properties.Add(new ObjectKeyValuePair()
            {
                KeyName = "Person Image",
                Value   = new ObjectFileField()
                {
                    FileCRC       = "10001001",
                    FileExtension = ".docx",
                    FileFullPath  = "c:\\location-update.docx",
                    FileName      = "location-update.docx",
                    FileUrl       = "http://www.url.com",
                    FileSize      = 10,
                    Created       = DateTime.Now,
                    Updated       = DateTime.Now
                }
            });

            int objectId      = service.CreateORUpdateGeneralObject(svObject);
            var serviceobject = service.GetServiceObjectById(objectId, new string[]
            {
                "Person Name",
                "Person Image"
            }, null);

            Assert.Equal(serviceobject.GetPropertyValue <PrimeObjectField>("Person Name").GetStrongTypeValue <string>(), "Peter, Robert - Updated");
            Assert.Equal(serviceobject.GetPropertyValue <ObjectFileField>("Person Image").FileName, "location-update.docx");
        }
Beispiel #5
0
        public void GetObjectTest()
        {
            IObjectService service = new DefaultObjectService();
            var            objects = service.GetAllSerivceObjects(service.GetAllObjectDefinitions()[0].ObjectDefinitionID, new string[] {
                "Person Name",
                "Person Sex",
                "Person AGE",
                "Person Image",
                "Person Manager"
            }, null);

            var obj = objects[0];

            Assert.Equal(obj.ObjectName, "Peter");
            Assert.Equal(obj.GetPropertyValue <PrimeObjectField>("Person Name").GetStrongTypeValue <string>(), "Peter, Robert");
            Assert.Equal(obj.GetPropertyValue <SingleSelectionField>("Person Sex").SelectedItemID, 5);
            Assert.Equal(obj.GetPropertyValue <PrimeObjectField>("Person AGE").GetStrongTypeValue <int>(), 30);
            Assert.Equal(obj.GetPropertyValue <ObjectFileField>("Person Image").FileName, "location.docx");
            Assert.Equal(obj.GetPropertyValue <ObjectReferenceField>("Person Manager").ReferedGeneralObjectID, 1);


            obj = service.GetServiceObjectById(obj.ObjectID, new string[] {
                "Person Name",
                "Person Sex",
                "Person Manager"
            }, null);
            Assert.Equal(obj.ObjectName, "Peter");
            Assert.Equal(obj.GetPropertyValue <PrimeObjectField>("Person Name").GetStrongTypeValue <string>(), "Peter, Robert");
            Assert.Equal(obj.GetPropertyValue <SingleSelectionField>("Person Sex").SelectedItemID, 5);
            Assert.Equal(obj.GetPropertyValue <ObjectReferenceField>("Person Manager").ReferedGeneralObjectID, 1);


            objects = service.GetServiceObjects(obj.ObjectDefinitionId, new string[] {
                "Person Name",
                "Person Sex",
                "Person Manager"
            }, 1, 10, null);
            obj = objects[0];
            Assert.Equal(obj.ObjectName, "Peter");
            Assert.Equal(obj.GetPropertyValue <PrimeObjectField>("Person Name").GetStrongTypeValue <string>(), "Peter, Robert");
            Assert.Equal(obj.GetPropertyValue <SingleSelectionField>("Person Sex").SelectedItemID, 5);
            Assert.Equal(obj.GetPropertyValue <ObjectReferenceField>("Person Manager").ReferedGeneralObjectID, 1);
        }
Beispiel #6
0
        public void CreateObjectDefGroupTest()
        {
            IObjectService service = new DefaultObjectService();

            var objDefinitionGroups = service.GetObjectDefinitionGroups(null, null);
            var defaultGroup        = objDefinitionGroups
                                      .Where(g => g.GroupKey.Equals("GROUP_SERVER_OBJECT"))
                                      .FirstOrDefault();

            if (defaultGroup == null)
            {
                service.CreateOrUpdateObjectDefinitionGroup(new ObjectDefinitionGroup()
                {
                    GroupKey  = "GROUP_SERVER_OBJECT",
                    GroupName = "SERVER OBJECT",
                });
            }

            Assert.True(service.GetObjectDefinitionGroups(null, null).Count == 1);
        }
Beispiel #7
0
        public void CreateObjectDefinitionTest()
        {
            IObjectService service = new DefaultObjectService();

            ObjectDefinition definition = new ObjectDefinition();

            definition.IsFeildsUpdateOnly      = false;
            definition.ObjectDefinitionKey     = "PERSON_TEST";
            definition.ObjectDefinitionGroupID = service.GetObjectDefinitionGroups(null, null)[0].GroupID;
            definition.ObjectDefinitionName    = "Person";
            definition.ObjectOwner             = "Admin";
            definition.UpdatedBy = "Admin";

            //Person name
            definition.ObjectFields.Add(new PrimeDefinitionField()
            {
                ObjectDefinitionFieldKey  = "PERSON_NAME",
                ObjectDefinitionFieldName = "Person Name",
                PrimeDataType             = PrimeFieldDataType.String
            });


            SingleSDefinitionField selectionField = new SingleSDefinitionField()
            {
                ObjectDefinitionFieldKey  = "PERSON_SEX",
                ObjectDefinitionFieldName = "Person Sex"
            };

            selectionField.SelectionItems.Add(new DefinitionSelectItem()
            {
                SelectDisplayName = "Male",
                SelectItemKey     = "Male"
            });
            selectionField.SelectionItems.Add(
                new DefinitionSelectItem()
            {
                SelectItemKey     = "Female",
                SelectDisplayName = "Female"
            });

            //Person Sex
            definition.ObjectFields.Add(selectionField);

            //Person Age
            definition.ObjectFields.Add(new PrimeDefinitionField()
            {
                ObjectDefinitionFieldKey  = "PERSON_AGE",
                ObjectDefinitionFieldName = "Person AGE",
                PrimeDataType             = PrimeFieldDataType.Integer
            });

            //person Image
            definition.ObjectFields.Add(new ObjectDefinitionField(GeneralObjectDefinitionFieldType.File)
            {
                GeneralObjectDefinitionFiledType = GeneralObjectDefinitionFieldType.File,
                ObjectDefinitionFieldKey         = "PERSON_IMAGE",
                ObjectDefinitionFieldName        = "Person Image"
            });

            //Manager
            definition.ObjectFields.Add(new ObjRefDefinitionField()
            {
                ObjectDefinitionFieldKey  = "PERSON_MANAGER",
                ObjectDefinitionFieldName = "Person Manager",
                ReferedObjectDefinitionID = 1
            });

            var objDef = service.GetAllObjectDefinitions()
                         .Where(od => od.ObjectDefinitionName.Equals("Person"))
                         .FirstOrDefault();

            //avoid to insert the duplicated value.
            if (objDef != null)
            {
                definition.ObjectDefinitionID = objDef.ObjectDefinitionID;
            }

            int objdefintionId = service.CreateORUpdateObjectDefinition(definition);

            Assert.True(objdefintionId > 0);
        }
Beispiel #8
0
        public void CreateObjectTest()
        {
            IObjectService service  = new DefaultObjectService();
            ServiceObject  svObject = new ServiceObject();

            svObject.ObjectName           = "Peter";
            svObject.ObjectOwner          = "Admin";
            svObject.OnlyUpdateProperties = false;
            svObject.UpdatedBy            = "Admin";
            svObject.CreatedBy            = "Admin";

            var objDef = service.GetAllObjectDefinitions()
                         .Where(od => od.ObjectDefinitionName.Equals("Person"))
                         .FirstOrDefault();

            if (objDef != null)
            {
                svObject.ObjectDefinitionId = objDef.ObjectDefinitionID;
            }


            Console.WriteLine("ObjectDefintionID = " + svObject.ObjectDefinitionId);
            svObject.Properties.Add(new ObjectKeyValuePair()
            {
                KeyName = "Person Name",
                Value   = new PrimeObjectField()
                {
                    PrimeDataType = PrimeFieldDataType.String,
                    Value         = "Peter, Robert"
                }
            });
            svObject.Properties.Add(new ObjectKeyValuePair()
            {
                KeyName = "Person Sex",
                Value   = new SingleSelectionField()
                {
                    SelectedItemID = 5
                }
            });
            svObject.Properties.Add(new ObjectKeyValuePair()
            {
                KeyName = "Person AGE",
                Value   = new PrimeObjectField()
                {
                    PrimeDataType = PrimeFieldDataType.Integer,
                    Value         = 30
                }
            });
            svObject.Properties.Add(new ObjectKeyValuePair()
            {
                KeyName = "Person Image",
                Value   = new ObjectFileField()
                {
                    FileCRC       = "10001001",
                    FileExtension = ".docx",
                    FileFullPath  = "c:\\location.docx",
                    FileName      = "location.docx",
                    FileUrl       = "http://www.url.com",
                    FileSize      = 10,
                    Created       = DateTime.Now,
                    Updated       = DateTime.Now
                }
            });

            svObject.Properties.Add(new ObjectKeyValuePair()
            {
                KeyName = "Person Manager",
                Value   = new ObjectReferenceField()
                {
                    ReferedGeneralObjectID = 1
                }
            });


            var objects = service.GetAllSerivceObjects(service.GetAllObjectDefinitions()[0].ObjectDefinitionID, new string[] {
                "Person Name",
                "Person Sex",
                "Person AGE",
                "Person Image",
                "Person Manager"
            }, null);

            var currObj = objects != null?objects.Where(o => o.ObjectName.Equals("Peter")).FirstOrDefault()
                              :  null;

            if (currObj == null)
            {
                int objId = service.CreateORUpdateGeneralObject(svObject);
            }

            Assert.True(service.GetGeneralObjectCount(service.GetAllObjectDefinitions()[0].ObjectDefinitionID, null) >= 1);
        }