Esempio n. 1
0
        public void AutoNumberField_Seed()
        {
            var field = new AutoNumberField( );

            field.Name           = "TestAutoNumberField";
            field.AutoNumberSeed = 123;

            var definition = new Definition( );

            definition.Name = "TestAutoNumberDefinition";
            definition.Fields.Add(field.As <Field>( ));
            definition.Save( );

            Entity instance1 = new Entity(definition.Id);

            instance1.Save( );
            int value = instance1.GetField <int>(field);

            Assert.AreEqual(123, value);

            Entity instance2 = new Entity(definition.Id);

            instance2.Save( );
            value = instance2.GetField <int>(field);
            Assert.AreEqual(124, value);

            Entity instance3 = new Entity(definition.Id);

            instance3.Save( );
            value = instance3.GetField <int>(field);
            Assert.AreEqual(125, value);
        }
 /// <summary>
 ///     Constructor.
 /// </summary>
 internal AutoNumberFieldHelper(AutoNumberField fieldEntity)
 {
     _field = fieldEntity;
 }
Esempio n. 3
0
        protected IStorageAutoNumberField CreateEmptyAutoNumberFieldObject(AutoNumberField field)
        {
            var storageService = service.StorageService;

            return((IStorageAutoNumberField)storageService.GetObjectFactory().CreateEmptyFieldObject(field.GetType()));
        }
Esempio n. 4
0
        public static IFieldHelper ConvertToFieldHelper(IEntity fieldEntity)
        {
            if (fieldEntity == null)
            {
                throw new ArgumentNullException("fieldEntity");
            }

            // Ensure we have the specific type of field in question.
            IEntity field = Entity.AsNative(fieldEntity);

            if (field == null)
            {
                throw new Exception("Assert false");
            }

            StringField stringField = field as StringField;

            if (stringField != null)
            {
                return(new StringFieldHelper(stringField));
            }

            AliasField aliasField = field as AliasField;

            if (aliasField != null)
            {
                return(new AliasFieldHelper(aliasField));
            }

            AutoNumberField autoNumberField = field as AutoNumberField;

            if (autoNumberField != null)
            {
                return(new AutoNumberFieldHelper(autoNumberField));
            }

            BoolField boolField = field as BoolField;

            if (boolField != null)
            {
                return(new BoolFieldHelper(boolField));
            }

            CurrencyField currencyField = field as CurrencyField;

            if (currencyField != null)
            {
                return(new CurrencyFieldHelper(currencyField));
            }

            DateField dateField = field as DateField;

            if (dateField != null)
            {
                return(new DateFieldHelper(dateField));
            }

            DateTimeField dateTimeField = field as DateTimeField;

            if (dateTimeField != null)
            {
                return(new DateTimeFieldHelper(dateTimeField));
            }

            DecimalField decimalField = field as DecimalField;

            if (decimalField != null)
            {
                return(new DecimalFieldHelper(decimalField));
            }

            IntField intField = field as IntField;

            if (intField != null)
            {
                return(new IntFieldHelper(intField));
            }

            TimeField timeField = field as TimeField;

            if (timeField != null)
            {
                return(new TimeFieldHelper(timeField));
            }

            GuidField guidField = field as GuidField;

            if (guidField != null)
            {
                return(new GuidFieldHelper(guidField));
            }

            XmlField xmlField = field as XmlField;

            if (xmlField != null)
            {
                return(new XmlFieldHelper(xmlField));
            }

            throw new Exception("Entity is not a valid field type: " + field.GetType().ToString());
        }
Esempio n. 5
0
        public void AutoNumberField_Concurrency( )
        {
            var field      = new AutoNumberField( );
            var definition = new Definition( );
            var deletables = new List <Entity>( );

            try
            {
                field.Name = "TestAutoNumberField";

                definition.Name = "TestAutoNumberDefinition";
                definition.Fields.Add(field.As <Field>( ));
                definition.Save( );

                var    values     = new List <int>( );
                object lockObject = new object( );

                var thread1 = new Thread(() =>
                {
                    for (int i = 0; i < 10; i++)
                    {
                        var instance = new Entity(definition.Id);
                        instance.Save( );
                        deletables.Add(instance);
                        int value = instance.GetField <int>(field);

                        lock ( lockObject )
                        {
                            values.Add(value);
                        }
                    }
                });

                var thread2 = new Thread(() =>
                {
                    for (int i = 0; i < 10; i++)
                    {
                        var instance = new Entity(definition.Id);
                        instance.Save( );
                        deletables.Add(instance);
                        int value = instance.GetField <int>(field);

                        lock ( lockObject )
                        {
                            values.Add(value);
                        }
                    }
                });

                thread1.IsBackground = true;
                thread1.Start( );

                thread2.IsBackground = true;
                thread2.Start( );

                thread1.Join( );
                thread2.Join( );

                Assert.AreEqual(20, values.Count);
                Assert.AreEqual(20, values.Distinct( ).Count( ));

                for (int i = 1; i <= 20; i++)
                {
                    Assert.IsTrue(values.Contains(i));
                }
            }
            finally
            {
                deletables.ForEach(e => e.Delete( ));

                definition.Delete( );
                field.Delete( );
            }
        }
Esempio n. 6
0
		protected IStorageAutoNumberField CreateEmptyAutoNumberFieldObject(AutoNumberField field)
		{
			var storageService = service.StorageService;
			return (IStorageAutoNumberField)storageService.GetObjectFactory().CreateEmptyFieldObject(field.GetType());
		}