Exemplo n.º 1
0
        /// <summary>
        /// Saves or updates the entity without its children.
        /// </summary>
        ///
        /// <param name="entity">
        /// Entity to save or update.
        /// </param>
        ///
        /// <param name="idGenerator">
        /// ObjectIDGenerator instance to generate IDs for objects.
        /// </param>
        ///
        /// <param name="options">
        /// Optional options.
        /// </param>
        ///
        /// <returns>
        /// The number of affected rows.
        /// </returns>
        internal int PersistWithChildren(ref VahapYigit.Test.Models.UserRole entity, ObjectIDGenerator idGenerator, SaveOptions options = null)
        {
            int rowCount = 0;

            if (entity.User != null && idGenerator.HasId(entity.User, withForceId: true) == 0)
            {
                using (var db = new UserCrud(base.UserContext))
                {
                    var child = entity.User;

                    rowCount += db.PersistWithChildren(ref child, idGenerator, options);

                    entity.IdUser = child.Id;
                }
            }

            if (entity.Role != null && idGenerator.HasId(entity.Role, withForceId: true) == 0)
            {
                using (var db = new RoleCrud(base.UserContext))
                {
                    var child = entity.Role;

                    rowCount += db.PersistWithChildren(ref child, idGenerator, options);

                    entity.IdRole = child.Id;
                }
            }

            rowCount += this.Persist(ref entity, options);

            return(rowCount);
        }
Exemplo n.º 2
0
        public static bool TryLocate(TTarget key, out TEvents value)
        {
            var id = _generator.HasId(key, out var firstTime);

            Asr.IsFalse(firstTime);
            return(_eventRegistry.TryGetValue(id, out value));
        }
Exemplo n.º 3
0
    // Test simple object identifier generation.
    public void TestObjectIDGeneratorSimple()
    {
        ObjectIDGenerator gen  = new ObjectIDGenerator();
        Object            obj1 = new Object();
        Object            obj2 = new Object();
        Object            obj3 = new Object();
        bool firstTime;

        AssertEquals("Simple (1)", 1, gen.GetId(obj1, out firstTime));
        Assert("Simple (2)", firstTime);

        AssertEquals("Simple (3)", 2, gen.GetId(obj2, out firstTime));
        Assert("Simple (4)", firstTime);

        AssertEquals("Simple (5)", 2, gen.GetId(obj2, out firstTime));
        Assert("Simple (6)", !firstTime);

        AssertEquals("Simple (7)", 1, gen.HasId(obj1, out firstTime));
        Assert("Simple (8)", !firstTime);

        AssertEquals("Simple (9)", 0, gen.HasId(obj3, out firstTime));
        Assert("Simple (10)", firstTime);

        AssertEquals("Simple (11)", 3, gen.GetId(obj3, out firstTime));
        Assert("Simple (12)", firstTime);
    }
	// Test simple object identifier generation.
	public void TestObjectIDGeneratorSimple()
			{
				ObjectIDGenerator gen = new ObjectIDGenerator();
				Object obj1 = new Object();
				Object obj2 = new Object();
				Object obj3 = new Object();
				bool firstTime;

				AssertEquals("Simple (1)", 1, gen.GetId(obj1, out firstTime));
				Assert("Simple (2)", firstTime);

				AssertEquals("Simple (3)", 2, gen.GetId(obj2, out firstTime));
				Assert("Simple (4)", firstTime);

				AssertEquals("Simple (5)", 2, gen.GetId(obj2, out firstTime));
				Assert("Simple (6)", !firstTime);

				AssertEquals("Simple (7)", 1, gen.HasId(obj1, out firstTime));
				Assert("Simple (8)", !firstTime);

				AssertEquals("Simple (9)", 0, gen.HasId(obj3, out firstTime));
				Assert("Simple (10)", firstTime);

				AssertEquals("Simple (11)", 3, gen.GetId(obj3, out firstTime));
				Assert("Simple (12)", firstTime);
			}
Exemplo n.º 5
0
        //
        // Tests getting the ID for an existing object
        //
        public void TestHasId1()
        {
            bool testBool1;
            bool testBool3;

            id = generator.GetId(obj1, out testBool1);
            long testId2 = generator.HasId(obj1, out testBool3);

            Assert.AreEqual(false, testBool3);         // this has been inserted before, "C1");
            Assert.AreEqual(id, testId2);              // we should get the same ID, "C2");
        }
        /// <summary>
        /// Determines whether an object has already been assigned an ID.
        /// </summary>
        ///
        /// <param name="source">
        /// ObjectIDGenerator source.
        /// </param>
        ///
        /// <param name="obj">
        /// The object you are asking for.
        /// </param>
        ///
        /// <param name="withForceId">
        /// HasId() does not set the Id by default.
        /// This value indicates whether the Id is set if HasId() returns zero at first time.
        /// </param>
        ///
        /// <returns>
        /// The object ID of obj if previously known to the System.Runtime.Serialization.ObjectIDGenerator; otherwise, zero.
        /// </returns>
        public static long HasId(this ObjectIDGenerator source, object obj, bool withForceId = false)
        {
            bool firstTime;
            long id = source.HasId(obj, out firstTime);

            if (id == 0 && withForceId)
            {
                source.GetId(obj);
            }

            return(id);
        }
Exemplo n.º 7
0
        private long FindIndex(ListNode node, ObjectIDGenerator generator)
        {
            if (node == null)
            {
                return(-1);
            }

            if (generator.HasId(node, out _) == 0)
            {
                return(-1);
            }

            return(generator.GetId(node, out _) - 1);
        }
        public long GetProxyIdentifier <TProxy>(TProxy proxy) where TProxy : class
        {
            if (proxy == null)
            {
                var mockExceptionMessage = _mockFailureMessageFactory.GetNullProxyFailureMessage();

                throw new MockException(mockExceptionMessage);
            }

            var result = _objectIdGenerator.HasId(proxy, out var isObjectFirstAppearance);
            var isUnidentifiedObject = result == 0 || isObjectFirstAppearance;

            var proxyIdentifier = isUnidentifiedObject
                ? _objectIdGenerator.GetId(proxy, out isObjectFirstAppearance)
                : result;

            return(proxyIdentifier);
        }
Exemplo n.º 9
0
    // Add large numbers of objects to an ObjectIDGenerator.
    public void TestObjectIDGeneratorMany()
    {
        ObjectIDGenerator gen = new ObjectIDGenerator();

        Object[] list = new Object [1024];
        bool     firstTime;
        int      posn;

        for (posn = 0; posn < 1024; ++posn)
        {
            list[posn] = new Object();
            AssertEquals("Many (1)", posn + 1,
                         gen.GetId(list[posn], out firstTime));
            Assert("Many (2)", firstTime);
            AssertEquals("Many (3)", (posn / 2) + 1,
                         gen.GetId(list[posn / 2], out firstTime));
            Assert("Many (4)", !firstTime);
            AssertEquals("Many (5)", (posn / 2) + 1,
                         gen.HasId(list[posn / 2], out firstTime));
            Assert("Many (6)", !firstTime);
        }
    }
Exemplo n.º 10
0
        private bool PropertyIsSanitizable(PropertyInfo property, object propertyValue, ObjectIDGenerator idGenerator)
        {
            /* Get all properties that are either:
             * a) strings that aren't null or whitespace
             * b) uris that aren't null
             * c) non-terminal objects that we haven't already visited in the graph.
             * d) properties without the SanitizationIgnoreAttribute
             * */

            bool propertyValueHasId;

            return(property.GetCustomAttributes(typeof(SanitizationIgnoreAttribute), true)
                   .SingleOrDefault()
                   .ToMaybe()
                   .Bind(_ => false.ToMaybe())
                   .FromMaybe(true) &&
                   ((property.PropertyType == typeof(String) && !String.IsNullOrWhiteSpace(propertyValue as String)) ||
                    (property.PropertyType == typeof(Uri) && propertyValue != null) ||
                    (propertyValue != null &&
                     !IsTerminalObject(propertyValue.GetType()) &&
                     idGenerator.HasId(propertyValue, out propertyValueHasId) == 0)));
        }
Exemplo n.º 11
0
        // This gives back the next object to be serialized.  Objects
        // are returned in a FIFO order based on how they were passed
        // to Schedule.  The id of the object is put into the objID parameter
        // and the Object itself is returned from the function.
        private object GetNext(out long objID)
        {
            bool isNew;

            //The Queue is empty here.  We'll throw if we try to dequeue the empty queue.
            if (_objectQueue.Count == 0)
            {
                objID = 0;
                return(null);
            }

            object obj = _objectQueue.Dequeue();

            // A WriteObjectInfo is queued if this object was a member of another object
            object realObj = obj is WriteObjectInfo ? ((WriteObjectInfo)obj)._obj : obj;

            objID = _idGenerator.HasId(realObj, out isNew);
            if (isNew)
            {
                throw new SerializationException(SR.Format(SR.Serialization_ObjNoID, realObj));
            }

            return(obj);
        }
Exemplo n.º 12
0
    // Test exception cases.
    public void TestObjectIDGeneratorExceptions()
    {
        ObjectIDGenerator gen = new ObjectIDGenerator();
        bool firstTime;

        try
        {
            gen.GetId(null, out firstTime);
            Fail("Exceptions (1)");
        }
        catch (ArgumentNullException)
        {
            // Success.
        }
        try
        {
            gen.HasId(null, out firstTime);
            Fail("Exceptions (1)");
        }
        catch (ArgumentNullException)
        {
            // Success.
        }
    }
	// Test exception cases.
	public void TestObjectIDGeneratorExceptions()
			{
				ObjectIDGenerator gen = new ObjectIDGenerator();
				bool firstTime;
				try
				{
					gen.GetId(null, out firstTime);
					Fail("Exceptions (1)");
				}
				catch(ArgumentNullException)
				{
					// Success.
				}
				try
				{
					gen.HasId(null, out firstTime);
					Fail("Exceptions (1)");
				}
				catch(ArgumentNullException)
				{
					// Success.
				}
			}
Exemplo n.º 14
0
        /// <summary>
        /// Traverses the specified object graph looking for all strings to be sanitized by <see cref="ISanitizeText"/>.
        /// </summary>
        /// <param name="objectToSanitize">The object to sanitize.</param>
        public virtual void Sanitize(Object objectToSanitize)
        {
            if (objectToSanitize == null || IsTerminalObject(objectToSanitize.GetType()))
            {
                return;
            }

            var idGenerator      = new ObjectIDGenerator();
            var stack            = new Stack <Node>();
            var sanitizableNodes = new HashSet <Node>();

            stack.Push(new Node(null, objectToSanitize, null, false));

            while (stack.Count > 0)
            {
                Node currentItem = stack.Pop();

                if (currentItem.Value == null)
                {
                    continue;
                }

                Boolean firstOccurrence;
                idGenerator.GetId(currentItem.Value, out firstOccurrence);

                /* There is no way to assign a unique ID to a string as far as I can tell.
                 * Therefore, any strings encountered with the same value will be sanitized
                 * each time.
                 * */
                if (!firstOccurrence && !(currentItem.Value is String))
                {
                    continue; // Should never get here because of WHERE filter below.
                }

                var currentItemType = currentItem.PropertyInfo == null?currentItem.Value.GetType() : currentItem.PropertyInfo.PropertyType;

                if (!IsTerminalObject(currentItemType))
                {
                    if (!(currentItemType.IsGenericType) && currentItemType.GetInterfaces().All(i => !i.IsGenericType))
                    {
                        Boolean propertyValueHasId;

                        /* Get all properties that are either:
                         * a) strings that aren't null or whitespace
                         * b) non-terminal objects that we haven't already visited in the graph.
                         * */
                        (from property in currentItemType.GetProperties(BindingFlags.Instance | BindingFlags.Public)
                         let propertyValue = property.GetValue(currentItem.Value, null)
                                             let allowHtml = property.GetCustomAttributes(typeof(SanitizationHtmlAttribute), true).SingleOrDefault().ToMaybe().Bind(_ => true.ToMaybe()).FromMaybe(false)
                                                             where (property.PropertyType == typeof(String) &&
                                                                    !String.IsNullOrWhiteSpace(propertyValue as String) &&
                                                                    property.GetCustomAttributes(typeof(SanitizationIgnoreAttribute), true)
                                                                    .SingleOrDefault()
                                                                    .ToMaybe()
                                                                    .Bind(_ => false.ToMaybe())
                                                                    .FromMaybe(true)) ||
                                                             (propertyValue != null &&
                                                              !IsTerminalObject(propertyValue.GetType()) &&
                                                              idGenerator.HasId(propertyValue, out propertyValueHasId) == 0)
                                                             select new Node(currentItem.Value, propertyValue, property, allowHtml))
                        .ForEach(stack.Push);

                        continue;
                    }

                    if (IsDictionary(currentItemType))
                    {
                        var genericDictionaryInterface =
                            currentItemType.IsGenericType &&
                            currentItemType.GetGenericTypeDefinition() == typeof(IDictionary <,>)
                                ? currentItemType
                                : currentItemType.GetInterfaces()
                            .SingleOrDefault(
                                interfaceType =>
                                interfaceType.IsGenericType &&
                                interfaceType.GetGenericTypeDefinition() == typeof(IDictionary <,>));

                        if (genericDictionaryInterface != null)
                        {
                            ProcessGenericDictionary(genericDictionaryInterface, sanitizableNodes, currentItem, currentItemType, stack);
                            continue;
                        }

                        throw new NotSupportedException("ObjectGraphSanitizer does not support non-generic dictionaries.");
                    }

                    if (IsEnumerable(currentItemType))
                    {
                        var genericEnumerableInterface =
                            currentItemType.IsGenericType &&
                            currentItemType.GetGenericTypeDefinition() == typeof(IEnumerable <>)
                                ? currentItemType
                                : currentItemType.GetInterfaces()
                            .SingleOrDefault(
                                interfaceType =>
                                interfaceType.IsGenericType &&
                                interfaceType.GetGenericTypeDefinition() == typeof(IEnumerable <>));

                        if (genericEnumerableInterface != null)
                        {
                            ProcessGenericEnumerable(genericEnumerableInterface, sanitizableNodes, currentItem, stack);
                            continue;
                        }

                        throw new NotSupportedException("ObjectGraphSanitizer does not support non-generic enumerables.");
                    }

                    continue;
                }

                if (currentItem.Parent != null && currentItem.PropertyInfo != null)
                {
                    sanitizableNodes.Add(currentItem);
                    continue;
                }

                throw new SanitizationException(String.Format("ObjectGraphSanitizer could not handle the object type: {0}", currentItemType));
            }

            SanitizeNodes(sanitizableNodes);
        }
Exemplo n.º 15
0
        private void SerializeComponent(
            object obj,
            bool specifyEncoding)
        {
            if (_typeFormat == FormatterTypeStyle.TypesAlways)
            {
                specifyEncoding = true;
            }

            // A null component
            if (obj == null)
            {
                Null();
                return;
            }
            Type objType    = obj.GetType();
            bool canBeValue = _mapper.IsInternalSoapType(objType);
            bool firstTime;
            long id = 0;

            // An object already serialized
            if ((id = idGen.HasId(obj, out firstTime)) != 0L)
            {
                Href((long)idGen.GetId(obj, out firstTime));
                return;
            }



            // A string
            if (objType == typeof(string))
            {
                if (_typeFormat != FormatterTypeStyle.XsdString)
                {
                    id = idGen.GetId(obj, out firstTime);
                    Id(id);
                }
//				specifyEncoding = false;
            }

            // This component has to be
            // serialized later
            if (!canBeValue && !objType.IsValueType)
            {
                long href = idGen.GetId(obj, out firstTime);
                Href(href);
                _objectQueue.Enqueue(new EnqueuedObject(obj, href));
                return;
            }

            if (specifyEncoding)
            {
                EncodeType(objType);
            }

            // A struct
            if (!canBeValue && objType.IsValueType)
            {
                SerializeObject(obj, 0);
                return;
            }

            _xmlWriter.WriteString(_mapper.GetInternalSoapValue(this, obj));
        }
Exemplo n.º 16
0
 public virtual bool runTest()
 {
    Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
    int iCountErrors = 0;
    int iCountTestcases = 0;
    String strLoc = "Loc_000oo";
    try {
    do
    {
      ObjectIDGenerator objIDGen;
      Object obj;
      long objId1, objId2;
      bool firstTime;
      Object boo2, cur2, dt2, dec2, dbl2, gui2, i16, i32, i64, sgl2, ts2;
      strLoc = "Loc_100aa";
      objIDGen = new ObjectIDGenerator();
      obj = null;
      iCountTestcases++;
      try
      {
        objIDGen.HasId(null, out firstTime);
        iCountErrors++;
        printerr("Error_289t2! Expected Exception not thrown");
      } catch (ArgumentException aExc) {}
      catch (Exception exc)
      {
        iCountErrors++;
        printerr("Error_t2gsa! Incorrect Exception thrown : exc=="+exc.ToString());
      }
      strLoc = "Loc_150aa";
      objIDGen = new ObjectIDGenerator();
      obj = new Decimal(10);
      iCountTestcases++;
      objId1 = objIDGen.HasId(obj, out firstTime);
      iCountTestcases++;
      if(!firstTime)
      {
        iCountErrors++;
        printerr("Error_209ts");
      }
      objId1 = objIDGen.HasId(obj, out firstTime);
      if(!firstTime)
      {
        iCountErrors++;
        printerr("Error_209ts");
      }
      if(objId1 != 0)
      {
        iCountErrors++;
        printerr("Error_150bb! Did not return null for non-existent object");
      }
      strLoc = "Loc_200aa";
      objIDGen = new ObjectIDGenerator();
      obj = new Decimal(10);
      objId1 = objIDGen.GetId(obj, out firstTime);
      iCountTestcases++;
      if(!firstTime)
      {
        iCountErrors++;
        printerr("Error_200bb! Whoa, This object haven't been searched for before.");
      }
      strLoc = "Loc_300aa";
      objIDGen = new ObjectIDGenerator();
      obj = new Decimal(10);
      objId1 = objIDGen.GetId(obj, out firstTime);
      iCountTestcases++;
      if(!firstTime)
      {
        iCountErrors++;
        printerr("Error_300bb! Whoa, This object haven't been searched for before.");
      }
      objId2 = objIDGen.HasId(obj, out firstTime);
      iCountTestcases++;
      if(objId1 != objId2)
      {
        iCountErrors++;
        printerr("Error_300cc! Different object id's returned for the same object");
      }
      iCountTestcases++;
      if(firstTime)
      {
        iCountErrors++;
        printerr("Error_300ee! This object has already been queried, firsttime should be false");
      }
      strLoc = "Loc_400aa";
      boo2 = false;
      dt2 = DateTime.Now;
      dec2 = new Decimal(15.2);
      dbl2 = ((Double)12.2);
      gui2 = Guid.NewGuid();
      i16 = ((Int16)18);
      i32 = ((Int32)42);
      i64 = ((Int64)11);
      sgl2 = ((Single)(Single)3.4);
      ts2 = new TimeSpan(12, 12, 12);
      objIDGen = new ObjectIDGenerator();
      strLoc = "Loc_32948";
      objId1 = objIDGen.GetId(boo2, out firstTime);
      iCountTestcases++;
      if(!firstTime)
      {
        iCountErrors++;
        printerr("Error_400bb! FirstTime is incorrectly false");
      }
      objId2 = objIDGen.HasId(boo2, out firstTime);
      iCountTestcases++;
      if(objId1 != objId2)
      {
        iCountErrors++;
        printerr("Error_400cc! Object id's not same for same object");
      }
      iCountTestcases++;
      if(firstTime)
      {
        iCountErrors++;
        printerr("Error_400dd! FirstTime is incorrectly false");
      }
      strLoc = "Loc_600aa";
      objId1 = objIDGen.GetId(dt2, out firstTime);
      iCountTestcases++;
      if(!firstTime)
      {
        iCountErrors++;
        printerr("Error_600bb! FirstTime is incorrectly false");
      }
      objId2 = objIDGen.HasId(dt2, out firstTime);
      iCountTestcases++;
      if(firstTime)
      {
        iCountErrors++;
        printerr("Error_600cc! FirstTime is incorrectl true");
      }
      iCountTestcases++;
      if(objId2 != objId1)
      {
        iCountErrors++;
        printerr("Error_600dd! Object Id's different for same object");
      }
      strLoc = "Loc_700aa";
      objId1 = objIDGen.GetId(dec2, out firstTime);
      iCountTestcases++;
      if(!firstTime)
      {
        iCountErrors++;
        printerr("Error_700bb! FirstTime is incorrectly false");
      }
      objId2 = objIDGen.HasId(dec2, out firstTime);
      iCountTestcases++;
      if(firstTime)
      {
        iCountErrors++;
        printerr("Error_700cc! FirstTime is incorrecly true");
      }
      iCountTestcases++;
      if(objId2 != objId1)
      {
        iCountErrors++;
        printerr("Error_700dd! Object id's different for same object");
      }
      strLoc = "Loc_800aa";
      objId1 = objIDGen.GetId(dbl2, out firstTime);
      iCountTestcases++;
      if(!firstTime)
      {
        iCountErrors++;
        printerr("Error_800bb! FirstTime is incorrectly false");
      }
      objId2 = objIDGen.HasId(dbl2, out firstTime);
      iCountTestcases++;
      if(firstTime)
      {
        iCountErrors++;
        printerr("Error_800cc! FirstTime is incorrecly true");
      }
      iCountTestcases++;
      if(objId2 != objId1)
      {
        iCountErrors++;
        printerr("Error_800dd! Object id's different for same object");
      }
      strLoc = "Loc_900aa";
      objId1 = objIDGen.GetId(gui2, out firstTime);
      iCountTestcases++;
      if(!firstTime)
      {
        iCountErrors++;
        printerr("Error_800bb! FirstTime is incorrectly false");
      }
      objId2 = objIDGen.HasId(gui2, out firstTime);
      iCountTestcases++;
      if(firstTime)
      {
        iCountErrors++;
        printerr("Error_800cc! FirstTime is incorrecly true");
      }
      iCountTestcases++;
      if(objId2 != objId1)
      {
        iCountErrors++;
        printerr("Error_800dd! Object id's different for same object");
      }
      strLoc = "Loc_1000a";
      objId1 = objIDGen.GetId(i16, out firstTime);
      iCountTestcases++;
      if(!firstTime)
      {
        iCountErrors++;
        printerr("Error_1000b! FirstTime is incorrectly false");
      }
      objId2 = objIDGen.HasId(i16, out firstTime);
      iCountTestcases++;
      if(firstTime)
      {
        iCountErrors++;
        printerr("Error_1000c! FirstTime is incorrecly true");
      }
      iCountTestcases++;
      if(objId2 != objId1)
      {
        iCountErrors++;
        printerr("Error_1000d! Object id's different for same object");
      }
      strLoc = "Loc_2805fe";
      objIDGen = new ObjectIDGenerator();
      dec2 = new Decimal(10);
      dbl2 = ((Double)10);
      objId1 = objIDGen.GetId(dec2, out firstTime);
      objId2 = objIDGen.HasId(dbl2, out firstTime);
      iCountTestcases++;
      if(objId1 == objId2)
      {
        iCountErrors++;
        printerr("Error_98532! Id's of two different objects are equal");
      }
    } while (false);
    } catch (Exception exc_general ) {
       ++iCountErrors;
       Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.StackTrace);
    }
    if ( iCountErrors == 0 )
    {
       Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
       return true;
    }
    else
    {
       Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
       return false;
    }
 }
Exemplo n.º 17
0
    public virtual bool runTest()
    {
        Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
        int    iCountErrors    = 0;
        int    iCountTestcases = 0;
        String strLoc          = "Loc_000oo";

        try {
            do
            {
                ObjectIDGenerator objIDGen;
                Object            obj;
                long   objId1, objId2;
                bool   firstTime;
                Object boo2, cur2, dt2, dec2, dbl2, gui2, i16, i32, i64, sgl2, ts2;
                strLoc   = "Loc_100aa";
                objIDGen = new ObjectIDGenerator();
                obj      = null;
                iCountTestcases++;
                try
                {
                    objIDGen.HasId(null, out firstTime);
                    iCountErrors++;
                    printerr("Error_289t2! Expected Exception not thrown");
                } catch (ArgumentException aExc) {}
                catch (Exception exc)
                {
                    iCountErrors++;
                    printerr("Error_t2gsa! Incorrect Exception thrown : exc==" + exc.ToString());
                }
                strLoc   = "Loc_150aa";
                objIDGen = new ObjectIDGenerator();
                obj      = new Decimal(10);
                iCountTestcases++;
                objId1 = objIDGen.HasId(obj, out firstTime);
                iCountTestcases++;
                if (!firstTime)
                {
                    iCountErrors++;
                    printerr("Error_209ts");
                }
                objId1 = objIDGen.HasId(obj, out firstTime);
                if (!firstTime)
                {
                    iCountErrors++;
                    printerr("Error_209ts");
                }
                if (objId1 != 0)
                {
                    iCountErrors++;
                    printerr("Error_150bb! Did not return null for non-existent object");
                }
                strLoc   = "Loc_200aa";
                objIDGen = new ObjectIDGenerator();
                obj      = new Decimal(10);
                objId1   = objIDGen.GetId(obj, out firstTime);
                iCountTestcases++;
                if (!firstTime)
                {
                    iCountErrors++;
                    printerr("Error_200bb! Whoa, This object haven't been searched for before.");
                }
                strLoc   = "Loc_300aa";
                objIDGen = new ObjectIDGenerator();
                obj      = new Decimal(10);
                objId1   = objIDGen.GetId(obj, out firstTime);
                iCountTestcases++;
                if (!firstTime)
                {
                    iCountErrors++;
                    printerr("Error_300bb! Whoa, This object haven't been searched for before.");
                }
                objId2 = objIDGen.HasId(obj, out firstTime);
                iCountTestcases++;
                if (objId1 != objId2)
                {
                    iCountErrors++;
                    printerr("Error_300cc! Different object id's returned for the same object");
                }
                iCountTestcases++;
                if (firstTime)
                {
                    iCountErrors++;
                    printerr("Error_300ee! This object has already been queried, firsttime should be false");
                }
                strLoc   = "Loc_400aa";
                boo2     = false;
                dt2      = DateTime.Now;
                dec2     = new Decimal(15.2);
                dbl2     = ((Double)12.2);
                gui2     = Guid.NewGuid();
                i16      = ((Int16)18);
                i32      = ((Int32)42);
                i64      = ((Int64)11);
                sgl2     = ((Single)(Single)3.4);
                ts2      = new TimeSpan(12, 12, 12);
                objIDGen = new ObjectIDGenerator();
                strLoc   = "Loc_32948";
                objId1   = objIDGen.GetId(boo2, out firstTime);
                iCountTestcases++;
                if (!firstTime)
                {
                    iCountErrors++;
                    printerr("Error_400bb! FirstTime is incorrectly false");
                }
                objId2 = objIDGen.HasId(boo2, out firstTime);
                iCountTestcases++;
                if (objId1 != objId2)
                {
                    iCountErrors++;
                    printerr("Error_400cc! Object id's not same for same object");
                }
                iCountTestcases++;
                if (firstTime)
                {
                    iCountErrors++;
                    printerr("Error_400dd! FirstTime is incorrectly false");
                }
                strLoc = "Loc_600aa";
                objId1 = objIDGen.GetId(dt2, out firstTime);
                iCountTestcases++;
                if (!firstTime)
                {
                    iCountErrors++;
                    printerr("Error_600bb! FirstTime is incorrectly false");
                }
                objId2 = objIDGen.HasId(dt2, out firstTime);
                iCountTestcases++;
                if (firstTime)
                {
                    iCountErrors++;
                    printerr("Error_600cc! FirstTime is incorrectl true");
                }
                iCountTestcases++;
                if (objId2 != objId1)
                {
                    iCountErrors++;
                    printerr("Error_600dd! Object Id's different for same object");
                }
                strLoc = "Loc_700aa";
                objId1 = objIDGen.GetId(dec2, out firstTime);
                iCountTestcases++;
                if (!firstTime)
                {
                    iCountErrors++;
                    printerr("Error_700bb! FirstTime is incorrectly false");
                }
                objId2 = objIDGen.HasId(dec2, out firstTime);
                iCountTestcases++;
                if (firstTime)
                {
                    iCountErrors++;
                    printerr("Error_700cc! FirstTime is incorrecly true");
                }
                iCountTestcases++;
                if (objId2 != objId1)
                {
                    iCountErrors++;
                    printerr("Error_700dd! Object id's different for same object");
                }
                strLoc = "Loc_800aa";
                objId1 = objIDGen.GetId(dbl2, out firstTime);
                iCountTestcases++;
                if (!firstTime)
                {
                    iCountErrors++;
                    printerr("Error_800bb! FirstTime is incorrectly false");
                }
                objId2 = objIDGen.HasId(dbl2, out firstTime);
                iCountTestcases++;
                if (firstTime)
                {
                    iCountErrors++;
                    printerr("Error_800cc! FirstTime is incorrecly true");
                }
                iCountTestcases++;
                if (objId2 != objId1)
                {
                    iCountErrors++;
                    printerr("Error_800dd! Object id's different for same object");
                }
                strLoc = "Loc_900aa";
                objId1 = objIDGen.GetId(gui2, out firstTime);
                iCountTestcases++;
                if (!firstTime)
                {
                    iCountErrors++;
                    printerr("Error_800bb! FirstTime is incorrectly false");
                }
                objId2 = objIDGen.HasId(gui2, out firstTime);
                iCountTestcases++;
                if (firstTime)
                {
                    iCountErrors++;
                    printerr("Error_800cc! FirstTime is incorrecly true");
                }
                iCountTestcases++;
                if (objId2 != objId1)
                {
                    iCountErrors++;
                    printerr("Error_800dd! Object id's different for same object");
                }
                strLoc = "Loc_1000a";
                objId1 = objIDGen.GetId(i16, out firstTime);
                iCountTestcases++;
                if (!firstTime)
                {
                    iCountErrors++;
                    printerr("Error_1000b! FirstTime is incorrectly false");
                }
                objId2 = objIDGen.HasId(i16, out firstTime);
                iCountTestcases++;
                if (firstTime)
                {
                    iCountErrors++;
                    printerr("Error_1000c! FirstTime is incorrecly true");
                }
                iCountTestcases++;
                if (objId2 != objId1)
                {
                    iCountErrors++;
                    printerr("Error_1000d! Object id's different for same object");
                }
                strLoc   = "Loc_2805fe";
                objIDGen = new ObjectIDGenerator();
                dec2     = new Decimal(10);
                dbl2     = ((Double)10);
                objId1   = objIDGen.GetId(dec2, out firstTime);
                objId2   = objIDGen.HasId(dbl2, out firstTime);
                iCountTestcases++;
                if (objId1 == objId2)
                {
                    iCountErrors++;
                    printerr("Error_98532! Id's of two different objects are equal");
                }
            } while (false);
        } catch (Exception exc_general) {
            ++iCountErrors;
            Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==\n" + exc_general.StackTrace);
        }
        if (iCountErrors == 0)
        {
            Console.WriteLine("paSs.   " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases);
            return(true);
        }
        else
        {
            Console.WriteLine("FAiL!   " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums);
            return(false);
        }
    }
	// Add large numbers of objects to an ObjectIDGenerator.
	public void TestObjectIDGeneratorMany()
			{
				ObjectIDGenerator gen = new ObjectIDGenerator();
				Object[] list = new Object [1024];
				bool firstTime;
				int posn;
				for(posn = 0; posn < 1024; ++posn)
				{
					list[posn] = new Object();
					AssertEquals("Many (1)", posn + 1,
								 gen.GetId(list[posn], out firstTime));
					Assert("Many (2)", firstTime);
					AssertEquals("Many (3)", (posn / 2) + 1,
								 gen.GetId(list[posn / 2], out firstTime));
					Assert("Many (4)", !firstTime);
					AssertEquals("Many (5)", (posn / 2) + 1,
								 gen.HasId(list[posn / 2], out firstTime));
					Assert("Many (6)", !firstTime);
				}
			}
Exemplo n.º 19
0
 public long HasId(object obj, out bool firstTime)
 {
     return(_objIDGenerator.HasId(obj, out firstTime));
 }