예제 #1
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);
        }
예제 #2
0
        public void TestSerializeOrg()
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            var obj1 = SCObjectGenerator.PrepareOrganizationObject();

            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);

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

            CommonAssert(obj1, obj2);
        }
예제 #3
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);
        }
예제 #4
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));
        }
예제 #5
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);
        }
예제 #6
0
        public void TestSerializeRelation()
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            var org  = SCObjectGenerator.PrepareOrganizationObject();
            var user = SCObjectGenerator.PrepareUserObject();
            SCRelationObject obj1 = new SCRelationObject(org, 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 = (SCRelationObject)bf.Deserialize(ms);

            RelationAssert(obj1, obj2);
        }
예제 #7
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());
        }
예제 #8
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);
        }
예제 #9
0
        public void GetSetSchemaOrganizationPropertiesTest()
        {
            SCOrganization org = SCObjectGenerator.PrepareOrganizationObject();

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