示例#1
0
        public void SequenceTestSerialize()
        {
            Sequence<int> before = new Sequence<int>(3);
            before.AddRange( new[] {1,2});
            before.Add(3);
            before.Add(4);

            Assert.Equal(4, before[0]);
            Assert.Equal(3, before[1]);
            Assert.Equal(2, before[2]);
            Assert.Equal(3, before.Capacity);
            Assert.Equal(4, before.CountOfAllObservedItems);

            //JsonSerializerSettings serializerSettings = new JsonSerializerSettings();
            //serializerSettings.Converters.Add(new SequenceConverter());

            string serialized = JsonConvert.SerializeObject(before);
            Sequence<int> after = JsonConvert.DeserializeObject<Sequence<int>>(serialized);

            Assert.Equal(4, after[0]);
            Assert.Equal(3, after[1]);
            Assert.Equal(2,after[2]);
            Assert.Equal(3, after.Capacity);
            Assert.Equal(4, after.CountOfAllObservedItems);
            Assert.Equal(before, after);
        }
示例#2
0
        public void SequenceTestSerialize()
        {
            Sequence <int> before = new Sequence <int>(3);

            before.AddRange(new[] { 1, 2 });
            before.Add(3);
            before.Add(4);

            Assert.Equal(4, before[0]);
            Assert.Equal(3, before[1]);
            Assert.Equal(2, before[2]);
            Assert.Equal(3, before.Capacity);
            Assert.Equal(4, before.CountOfAllObservedItems);

            //JsonSerializerSettings serializerSettings = new JsonSerializerSettings();
            //serializerSettings.Converters.Add(new SequenceConverter());

            string         serialized = JsonConvert.SerializeObject(before);
            Sequence <int> after      = JsonConvert.DeserializeObject <Sequence <int> >(serialized);

            Assert.Equal(4, after[0]);
            Assert.Equal(3, after[1]);
            Assert.Equal(2, after[2]);
            Assert.Equal(3, after.Capacity);
            Assert.Equal(4, after.CountOfAllObservedItems);
            Assert.Equal(before, after);
        }
示例#3
0
 public void SequenceTestToList()
 {
     Sequence<int> s = new Sequence<int>(5);
     s.AddRange(new[] { 1, 2, 3 });
     List<int> asList = s.ToList();
     Assert.Equal(1, asList[0]);
     Assert.Equal(2, asList[1]);
     Assert.Equal(3, asList[2]);
 }
示例#4
0
        public void SequenceTestToList()
        {
            Sequence <int> s = new Sequence <int>(5);

            s.AddRange(new[] { 1, 2, 3 });
            List <int> asList = s.ToList();

            Assert.Equal(1, asList[0]);
            Assert.Equal(2, asList[1]);
            Assert.Equal(3, asList[2]);
        }
示例#5
0
        /// <summary>
        /// If it is a structural object class, then the objectClass attribute of objects of the class does not contain
        /// the name of the auxiliary class aux.
        /// </summary>
        /// <param name="obj">The object of model.</param>
        public static void CheckStructure(ModelObject obj)
        {
            //Collect possSuperiors.
            Sequence <object> possSuperiors = new Sequence <object>();
            //Get current class name.
            string className = obj[StandardNames.ldapDisplayName].UnderlyingValues.ElementAt(0).ToString();
            //Get super class list.
            Sequence <string> superClassList = GetSuperClassList(obj.dc, className);

            //For each super class
            foreach (string superClass in superClassList)
            {
                //Get class object of this class name.
                ModelObject classObject = obj.dc.GetClass(superClass);

                //Get possSuperiors.
                if (classObject[StandardNames.possSuperiors] != null)
                {
                    possSuperiors = possSuperiors.AddRange(classObject[StandardNames.possSuperiors].UnderlyingValues);
                }

                //Get systemPossSuperiors.
                if (classObject[StandardNames.systemPossSuperiors] != null)
                {
                    possSuperiors = possSuperiors.AddRange(classObject[StandardNames.systemPossSuperiors].UnderlyingValues);
                }
            }

            //For each poss superior class name...
            foreach (string possSuperior in possSuperiors)
            {
                #region two

                //Get the poss superior object and possibleInferiors attribute.
                ModelObject superiorObj = obj.dc.GetClass(possSuperior);
                ModelObject attrObject  = superiorObj.dc.GetAttribute(StandardNames.possibleInferiors);

                if (superiorObj != null)
                {
                    AttributeContext parsingContext = obj.dc.GetAttributeContext(StandardNames.possibleInferiors);

                    //If this class alrady contains the possibleInferiors...
                    if (superiorObj[StandardNames.possibleInferiors] != null)
                    {
                        string valueString = String.Empty;
                        foreach (object val in superiorObj[StandardNames.possibleInferiors].UnderlyingValues)
                        {
                            valueString = valueString + val.ToString() + ";";
                        }

                        //Append the current class name with already existing possibleInferiors attribute.
                        valueString = valueString + className;
                        superiorObj[StandardNames.possibleInferiors] = parsingContext.Parse(valueString);
                    }
                    else
                    {
                        //Create a new possibleInferiors attribute with the cureent class name.
                        superiorObj[StandardNames.possibleInferiors] = parsingContext.Parse(className);
                    }
                }
                else
                {
                    Checks.Fail(
                        "{0} class's possSuperior {1} is not in Schema NC.",
                        className,
                        superiorObj.attributes[StandardNames.cn].UnderlyingValues.ElementAt(0).ToString());
                }

                #endregion
            }
        }