예제 #1
0
        public void UpdateUserImage()
        {
            var userImagePropName = "PhotoKey";

            SCUser user = SCObjectGenerator.PrepareUserObject();

            SCObjectOperations.Instance.AddUser(user, SCOrganization.GetRoot());

            ImageProperty image = ImageGenerator.PrepareImage();

            image.ResourceID = user.ID;

            Assert.IsTrue(CanSerialize(image));

            SCObjectOperations.Instance.UpdateObjectImageProperty(user, userImagePropName, image);

            SCUser userLoad = (SCUser)SchemaObjectAdapter.Instance.Load(user.ID);

            Assert.IsNotNull(userLoad);

            var imageLoad = JSONSerializerExecute.Deserialize <ImageProperty>(userLoad.Properties[userImagePropName].StringValue);
            MaterialContentCollection mcc = MaterialContentAdapter.Instance.Load(builder => builder.AppendItem("CONTENT_ID", imageLoad.ID));

            Assert.AreEqual(image.Name, imageLoad.Name);
            Assert.IsNotNull(mcc);
            Assert.AreEqual(1, mcc.Count);
            Assert.AreEqual(image.Content.ContentData.Length, mcc[0].ContentData.Length);

            SCObjectOperations.Instance.UpdateObjectImageProperty(user, userImagePropName, null);
            userLoad = (SCUser)SchemaObjectAdapter.Instance.Load(user.ID);

            Assert.AreEqual("", userLoad.Properties[userImagePropName].StringValue);
        }
예제 #2
0
        public void TestSerializeSchemaPropertyValueCollection()
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            System.IO.MemoryStream        ms   = new System.IO.MemoryStream();
            SchemaPropertyValueCollection obj1 = new SchemaPropertyValueCollection();

            SCGroup group = SCObjectGenerator.PrepareGroupObject();

            foreach (string key in group.Properties.GetAllKeys())
            {
                obj1.Add(group.Properties[key]);
            }

            bf.Serialize(ms, obj1);
            ms.Seek(0, System.IO.SeekOrigin.Begin);

            var obj2 = (SchemaPropertyValueCollection)bf.Deserialize(ms);

            Assert.AreEqual(obj1.Count, obj2.Count);

            var keys1 = obj1.GetAllKeys();

            foreach (var key in keys1)
            {
                Assert.IsTrue(obj2.ContainsKey(key));
                Assert.AreEqual(obj1[key].StringValue, obj2[key].StringValue);
            }
        }
예제 #3
0
        public void GetSetSchemaUserPropertiesTest()
        {
            SCUser user = SCObjectGenerator.PrepareUserObject();

            Assert.AreEqual("Great Shen Zheng", user.Name);
            Assert.AreEqual("峥", user.FirstName);
            Assert.AreEqual("沈", user.LastName);
        }
예제 #4
0
        public void TestSerializeGroup()
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            SCGroup obj1 = SCObjectGenerator.PrepareGroupObject();

            obj1.CreateDate     = DateTime.Now;
            obj1.VersionEndTime = new DateTime(567890);
            obj1.VersionEndTime = DateTime.MaxValue;
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            bf.Serialize(ms, obj1);
            ms.Seek(0, System.IO.SeekOrigin.Begin);
            SCGroup obj2 = (SCGroup)bf.Deserialize(ms);

            CommonAssert(obj1, obj2);
        }
예제 #5
0
        public void SetUserDeletedStatus()
        {
            SCUser user = SCObjectGenerator.PrepareUserObject();

            SCActionContext.Current.DoActions(() => SchemaObjectAdapter.Instance.Update(user));

            SCUser userLoaded = (SCUser)SchemaObjectAdapter.Instance.Load(user.ID);

            SCActionContext.Current.DoActions(() => SchemaObjectAdapter.Instance.UpdateStatus(userLoaded, SchemaObjectStatus.Deleted));

            Console.WriteLine(userLoaded.ID);
            SCUser userLoaded2 = (SCUser)SchemaObjectAdapter.Instance.Load(user.ID);

            Assert.AreEqual(SchemaObjectStatus.Deleted, userLoaded2.Status);
        }
예제 #6
0
        public void SchemaOrganizationToXml()
        {
            SCOrganization org = SCObjectGenerator.PrepareOrganizationObject();

            XElement orgElem = new XElement("Root").AddChildElement("Object");

            org.ToXElement(orgElem);

            Console.WriteLine(orgElem.Parent.ToString());

            SCOrganization orgDeserialized = new SCOrganization();

            orgDeserialized.FromXElement(orgElem);

            Assert.AreEqual(org.ID, orgDeserialized.ID);
            Assert.AreEqual(org.Name, orgDeserialized.Name);
        }
예제 #7
0
        public void RemoveUserAndOrganizationRelationTest()
        {
            SCOrganization org  = SCObjectGenerator.PrepareOrganizationObject();
            SCUser         user = SCObjectGenerator.PrepareUserObject();

            SCRelationObject relation = UpdateRelation(org, user);

            SCRelationObject relationLoaded = SchemaRelationObjectAdapter.Instance.Load(org.ID, user.ID);

            Console.WriteLine("Org ID: {0}, User ID: {1}", org.ID, user.ID);

            SchemaRelationObjectAdapter.Instance.UpdateStatus(relationLoaded, SchemaObjectStatus.Deleted);

            relationLoaded = SchemaRelationObjectAdapter.Instance.Load(org.ID, user.ID);

            Assert.AreEqual(SchemaObjectStatus.Deleted, relationLoaded.Status);
        }
예제 #8
0
        public void LoadSimpleObjectTest()
        {
            SCOrganization root = SCOrganization.GetRoot();

            SCOrganization newOrg = SCObjectGenerator.PrepareOrganizationObject();

            SCObjectOperations.Instance.AddOrganization(newOrg, root);

            root.ClearRelativeData();
            SCSimpleObjectCollection simpleChildren = root.CurrentChildren.ToSimpleObjects();

            SCSimpleObject simpleObj = simpleChildren.Find(obj => obj.ID == newOrg.ID);

            Console.WriteLine(simpleObj.DisplayName);

            Assert.IsNotNull(simpleObj);
            Assert.AreEqual(simpleObj.Name, simpleObj.DisplayName);
        }
예제 #9
0
        public void PersistSchemaUser()
        {
            SCUser user = SCObjectGenerator.PrepareUserObject();

            user.Properties.TrySetValue("CadreType", MCS.Library.OGUPermission.UserAttributesType.JiaoLiuGanBu);

            SCActionContext.Current.DoActions(() => SchemaObjectAdapter.Instance.Update(user));

            SCUser userLoaded = (SCUser)SchemaObjectAdapter.Instance.Load(user.ID);

            Console.WriteLine(user.Properties.GetValue("CadreType", MCS.Library.OGUPermission.UserAttributesType.Unspecified));

            Assert.IsNotNull(userLoaded);
            Assert.AreEqual(user.ID, userLoaded.ID);
            Assert.AreEqual(user.Name, userLoaded.Name);
            Assert.AreEqual(user.FirstName, userLoaded.FirstName);
            Assert.AreEqual(user.LastName, userLoaded.LastName);
        }
예제 #10
0
        public void SchemaOrganizationToSimpleJson()
        {
            SCOrganization org = SCObjectGenerator.PrepareOrganizationObject();

            JSONSerializerExecute.RegisterConverter(typeof(SchemaObjectSimpleConverter));

            string serializedData = JSONSerializerExecute.Serialize(org);

            Console.WriteLine(serializedData);

            SCOrganization deserializedOrg = JSONSerializerExecute.Deserialize <SCOrganization>(serializedData);

            Assert.AreEqual(org.ID, deserializedOrg.ID);
            Assert.AreEqual(org.Name, deserializedOrg.Name);
            Assert.AreEqual(org.Properties.GetValue("CodeName", string.Empty), deserializedOrg.Properties.GetValue("CodeName", string.Empty));
            Assert.AreEqual(org.Properties.GetValue("DisplayName", string.Empty), deserializedOrg.Properties.GetValue("DisplayName", string.Empty));
            Assert.AreEqual(org.Properties.GetValue("Description", string.Empty), deserializedOrg.Properties.GetValue("Description", string.Empty));
        }
예제 #11
0
        public void DoubleInsertSameSchemaUser()
        {
            SCUser user = SCObjectGenerator.PrepareUserObject();

            SCActionContext.Current.DoActions(() => SchemaObjectAdapter.Instance.Update(user));

            user.Name = "一般的沈峥";

            SCActionContext.Current.DoActions(() => SchemaObjectAdapter.Instance.Update(user));

            SCUser userLoaded = (SCUser)SchemaObjectAdapter.Instance.Load(user.ID);

            Assert.IsNotNull(userLoaded);
            Assert.AreEqual(user.ID, userLoaded.ID);
            Assert.AreEqual(user.Name, userLoaded.Name);
            Assert.AreEqual(user.FirstName, userLoaded.FirstName);
            Assert.AreEqual(user.LastName, userLoaded.LastName);
        }
예제 #12
0
        public void SchemaUserToXml()
        {
            SCUser user = SCObjectGenerator.PrepareUserObject();

            XElement userElem = new XElement("Root").AddChildElement("Object");

            user.ToXElement(userElem);

            Console.WriteLine(userElem.Parent.ToString());

            SCUser userDeserialized = new SCUser();

            userDeserialized.FromXElement(userElem);

            Assert.AreEqual(user.ID, userDeserialized.ID);
            Assert.AreEqual(user.Name, userDeserialized.Name);
            Assert.AreEqual(user.FirstName, userDeserialized.FirstName);
            Assert.AreEqual(user.LastName, userDeserialized.LastName);
        }
예제 #13
0
        public void LoadUserByXPathTest()
        {
            SchemaObjectAdapter.Instance.ClearAllData();

            SCUser user = SCObjectGenerator.PrepareUserObject();

            user.FirstName = "SZ's brother";
            string firstName = user.FirstName;

            //更新一次,插入最原始的版本
            SCActionContext.Current.DoActions(() => SchemaObjectAdapter.Instance.Update(user));

            string xPath = string.Format("Object[@FirstName=\"{0}\"]", firstName);

            SchemaObjectBase loadedUser = SchemaObjectAdapter.Instance.LoadByXPath(xPath, new string[] { "Users" }, DateTime.MinValue).FirstOrDefault();

            Assert.IsNotNull(loadedUser);
            Assert.AreEqual(firstName, loadedUser.Properties.GetValue("FirstName", string.Empty));
        }
예제 #14
0
        public void TestSerializeMemberRelation()
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            var role = SCObjectGenerator.PrepareRoleObject();
            var user = SCObjectGenerator.PrepareUserObject();
            var obj1 = new SCMemberRelation(role, user);

            obj1.CreateDate     = DateTime.Now;
            obj1.VersionEndTime = new DateTime(567890);
            obj1.VersionEndTime = DateTime.MaxValue;
            obj1.ID             = MCS.Library.Core.UuidHelper.NewUuidString();
            obj1.InnerSort      = 23;
            obj1.Status         = SchemaObjectStatus.Deleted;
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            bf.Serialize(ms, obj1);
            ms.Seek(0, System.IO.SeekOrigin.Begin);
            var obj2 = (SCMemberRelation)bf.Deserialize(ms);

            RelationAssert(obj1, obj2);
        }
예제 #15
0
        public void AddUserInOrganizationTest()
        {
            SCOrganization org  = SCObjectGenerator.PrepareOrganizationObject();
            SCUser         user = SCObjectGenerator.PrepareUserObject();

            SCRelationObject relation = UpdateRelation(org, user);

            org.ClearRelativeData();

            SCRelationObject relationLoaded = SchemaRelationObjectAdapter.Instance.Load(org.ID, user.ID);

            Console.WriteLine("Org ID: {0}, User ID: {1}", org.ID, user.ID);

            Assert.IsNotNull(relationLoaded);
            Assert.AreEqual(org.ID, relationLoaded.ParentID);
            Assert.AreEqual(user.ID, relationLoaded.ID);
            Assert.AreEqual(user.VersionStartTime, org.VersionStartTime);
            Assert.AreEqual(relation.VersionStartTime, org.VersionStartTime);

            ChildrenCheck(SCOrganization.GetRoot(), org, user);
            ParentsCheck(user, org, SCOrganization.GetRoot());
        }
예제 #16
0
        public void DuplicatePersistSchemaUser()
        {
            SCUser user = SCObjectGenerator.PrepareUserObject();

            string firstUserName = user.Name;

            //更新一次,插入最原始的版本
            SCActionContext.Current.DoActions(() => SchemaObjectAdapter.Instance.Update(user));

            //加载最原始的版本
            SCUser originalLoadedUser = (SCUser)SchemaObjectAdapter.Instance.Load(user.ID);

            originalLoadedUser.Name = "沈峥";

            //再更新一次,获取新版本
            SCActionContext.Current.DoActions(() => SchemaObjectAdapter.Instance.Update(originalLoadedUser));

            SCUser firstLoadedUser   = (SCUser)SchemaObjectAdapter.Instance.Load(originalLoadedUser.ID, originalLoadedUser.VersionStartTime);
            SCUser currentLoadedUser = (SCUser)SchemaObjectAdapter.Instance.Load(originalLoadedUser.ID);

            Assert.AreEqual(firstUserName, firstLoadedUser.Name);
            Assert.AreEqual(originalLoadedUser.Name, currentLoadedUser.Name);
        }
예제 #17
0
        public void DuplicatePersistSchemaUser()
        {
            SCOrganization org = SCObjectGenerator.PrepareOrganizationObject();

            string firstOrgName = org.Name;

            //更新一次,插入最原始的版本
            SCActionContext.Current.DoActions(() => SchemaObjectAdapter.Instance.Update(org));

            //加载最原始的版本
            SCOrganization originalLoadedOrg = (SCOrganization)SchemaObjectAdapter.Instance.Load(org.ID);

            originalLoadedOrg.Name = "根组织";

            //再更新一次,获取新版本
            SCActionContext.Current.DoActions(() => SchemaObjectAdapter.Instance.Update(originalLoadedOrg));

            SCOrganization firstLoadedOrg   = (SCOrganization)SchemaObjectAdapter.Instance.Load(originalLoadedOrg.ID, originalLoadedOrg.VersionStartTime);
            SCOrganization currentLoadedOrg = (SCOrganization)SchemaObjectAdapter.Instance.Load(originalLoadedOrg.ID);

            Assert.AreEqual(firstOrgName, firstLoadedOrg.Name);
            Assert.AreEqual(originalLoadedOrg.Name, currentLoadedOrg.Name);
        }
예제 #18
0
        public void GetSetSchemaOrganizationPropertiesTest()
        {
            SCOrganization org = SCObjectGenerator.PrepareOrganizationObject();

            Assert.AreEqual("Root Organization", org.Name);
        }