示例#1
0
 public void Attach_IDataObject_Existing_Twice()
 {
     using (IZetboxContext ctx = GetContext())
     {
         TestObjClass obj = new TestObjClassEfImpl(null)
         {
             ID = 3, ClientObjectState = DataObjectState.Unmodified
         };
         Assert.That(((TestObjClassEfImpl)obj).EntityState, Is.EqualTo(EntityState.Detached));
         ctx.Attach(obj);
         Assert.That(((TestObjClassEfImpl)obj).EntityState, Is.EqualTo(EntityState.Unchanged));
         ctx.Attach(obj);
         Assert.That(((TestObjClassEfImpl)obj).EntityState, Is.EqualTo(EntityState.Unchanged));
     }
 }
示例#2
0
        protected ValueCollectionWrapper(IZetboxContext ctx, TParent parent, Action parentNotifier, TEntryCollection collection)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            // may be null: if (parentNotifier == null) { throw new ArgumentNullException("parentNotifier"); }
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            this.ctx                  = ctx;
            this.parent               = parent;
            this.parentNotifier       = parentNotifier;
            this.collection           = collection;
            this.tEntryImplementation = ctx.GetImplementationType(typeof(TEntry));
            this.tEntryInterface      = tEntryImplementation.ToInterfaceType();

            // may be necessary on (lazy) initialisation
            foreach (var item in this.collection)
            {
                if (item.Context != this.ctx)
                {
                    ctx.Attach(item);
                }
            }
        }
示例#3
0
 protected virtual TEntry InitialiseEntry(TEntry e, TValue value)
 {
     e.UpdateParent("Parent", parent);
     e.Value = value;
     ctx.Attach(e);
     return(e);
 }
示例#4
0
 public override void AttachToContext(IZetboxContext ctx)
 {
     base.AttachToContext(ctx);
     if (_PhoneNumbersOtherCollection != null)
     {
         _PhoneNumbersOtherCollection.ForEach <IPersistenceObject>(i => ctx.Attach(i));
     }
 }
示例#5
0
 public override void SetUp()
 {
     base.SetUp();
     _iftFactory = scope.Resolve <InterfaceType.Factory>();
     ctx         = GetContext();
     obj         = new TestObjClassImpl();
     ctx.Attach(obj);
 }
示例#6
0
 public override void AttachToContext(IZetboxContext ctx)
 {
     base.AttachToContext(ctx);
     if (ctx.ContainsObject(ctx.GetInterfaceType(this), this.ID) == null)
     {
         // Object is not in this Context present
         // -> Attach it. Attach will call this Method again!
         ctx.Attach(this);
     }
 }
示例#7
0
        public void AttachedObjects()
        {
            using (IZetboxContext ctx = GetContext())
            {
                TestObjClass obj = new TestObjClassEfImpl(null);
                ctx.Attach(obj);
                ctx.Create <TestObjClass>();

                Assert.That(ctx.AttachedObjects.Count(), Is.EqualTo(2));
            }
        }
示例#8
0
        public void ContainsObject()
        {
            using (IZetboxContext ctx = GetContext())
            {
                TestObjClass obj = new TestObjClassEfImpl(null)
                {
                    ID = 10
                };
                ctx.Attach(obj);
                ctx.Create <TestObjClass>();
                Assert.That(ctx.AttachedObjects.Count(), Is.EqualTo(2));

                Assert.That(ctx.ContainsObject(ctx.GetInterfaceType(obj), obj.ID), Is.EqualTo(obj));
            }
        }
示例#9
0
        public void DetachFromContext()
        {
            Assert.That(obj.Context, Is.Null);
            obj.SetPrivatePropertyValue <int>("ID", 10);
            using (IZetboxContext ctx = GetContext())
            {
                ctx.Attach(obj);
                Assert.That(obj.Context, Is.Not.Null);

                obj.DetachFromContext(ctx);
                Assert.That(obj.Context, Is.Null);
                Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Unmodified));
                Assert.That(PropertyChangedCalled, Is.True);
            }
        }
示例#10
0
 public void InitialiseObject(IZetboxContext ctx, ObjectClass obj)
 {
     ctx.Attach(obj);
     obj.BaseObjectClass = null;
     obj.Name            = "testclassname";
     obj.DefaultIcon     = null;
     obj.Description     = "testclassdescription";
     obj.ImplementsInterfaces.Clear();
     obj.IsFrozenObject = false;
     obj.IsSimpleObject = false;
     obj.Methods.Clear();
     obj.Module = ctx.GetQuery <Zetbox.App.Base.Module>().First();
     obj.Properties.Clear();
     obj.SubClasses.Clear();
     obj.TableName = "testtablename";
 }
示例#11
0
        public void FromStream_creates_correct_Object()
        {
            var typeMap = scope.Resolve <TypeMap>();
            var ms      = new MemoryStream();
            var sw      = new ZetboxStreamWriter(typeMap, new BinaryWriter(ms));
            var sr      = new ZetboxStreamReader(typeMap, new BinaryReader(ms));

            TestObjClassSerializationMock.ToStream <TestObjClass, TestEnum>(sw, _iftFactory);
            sw.Flush();

            Assert.That(ms.Length, Is.GreaterThan(0));
            ms.Seek(0, SeekOrigin.Begin);

            var t = sr.ReadSerializableType();

            Assert.That(t.GetSystemType().IsAssignableFrom(typeof(TestObjClass)), string.Format("{0} not assignable to {1}", typeof(TestObjClass), t));

            var obj = new TestObjClassImpl();

            obj.FromStream(sr);
            ctx.Attach(obj);

            TestObjClassSerializationMock.AssertCorrectContentsEnum <TestObjClass>(obj);
        }
示例#12
0
 public override void SetUp()
 {
     base.SetUp();
     _iftFactory = scope.Resolve<InterfaceType.Factory>();
     ctx = GetContext();
     obj = new TestObjClassImpl();
     ctx.Attach(obj);
 }
示例#13
0
 public void AttachToContext(IZetboxContext ctx)
 {
     OnCollectionResetting();
     collection = new List <T>(collection.Select(i => ctx.Attach(i)).Cast <T>());
     OnCollectionReset();
 }
示例#14
0
 public override void AttachToContext(IZetboxContext ctx, Func<IFrozenContext> lazyFrozenContext)
 {
     base.AttachToContext(ctx, lazyFrozenContext);
     if (ctx.ContainsObject(ctx.GetInterfaceType(this), this.ID) == null)
     {
         // Object is not in this Context present
         // -> Attach it. Attach will call this Method again!
         ctx.Attach(this);
     }
 }
示例#15
0
 public void Attach_IDataObject_Null()
 {
     ctx.Attach((IDataObject)null);
 }
 public override void AttachToContext(IZetboxContext ctx)
 {
     base.AttachToContext(ctx);
     if (_PhoneNumbersOther != null)
         PhoneNumbersOtherImpl.ForEach<IPersistenceObject>(i => ctx.Attach(i));
 }
示例#17
0
 public override void SetUp()
 {
     base.SetUp();
     ctx = GetContext();
     ctx.Attach(obj);
 }
示例#18
0
 public override void AttachToContext(IZetboxContext ctx)
 {
     base.AttachToContext(ctx);
     if (_EMails != null)
         EMailsImpl.ForEach<IPersistenceObject>(i => ctx.Attach(i));
 }