Пример #1
0
        public void Delete_Wrong_Context()
        {
            TestObjClass obj = GetContext().Find <TestObjClass>(1);

            ctx.Delete(obj);
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Deleted));
        }
Пример #2
0
        public void GetList_GetListOf()
        {
            List <TestObjClass> list = ctx.GetQuery <TestObjClass>().ToList();

            Assert.That(list, Is.Not.Null);
            Assert.That(list.Count, Is.AtLeast(2));

            TestObjClass        obj    = ctx.Find <TestObjClass>(1);
            List <TestObjClass> listOf = ctx.GetListOf <TestObjClass>(obj, "Children");

            Assert.That(listOf, Is.Not.Null);
            Assert.That(listOf.Count, Is.AtLeast(2));

            TestObjClass obj_list = list.Single(o => o.ID == 3);

            Assert.That(obj_list, Is.Not.Null);
            Assert.That(obj_list.ID, Is.EqualTo(3));

            TestObjClass obj_listOf = listOf.Single(o => o.ID == 3);

            Assert.That(obj_listOf, Is.Not.Null);
            Assert.That(obj_listOf.ID, Is.EqualTo(3));

            Assert.That(object.ReferenceEquals(obj_list, obj_listOf), "obj_list & obj_listOf are different Objects");
        }
Пример #3
0
 public override void SetUp()
 {
     base.SetUp();
     ctx = GetContext();
     obj = ctx.Create<TestObjClass>();
     obj.StringProp = "Some String";
 }
Пример #4
0
        public void Delete()
        {
            TestObjClass obj = ctx.GetQuery <TestObjClass>().First();

            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Unmodified));
            ctx.Delete(obj);
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Deleted));
        }
Пример #5
0
 public void Create_ObjectType()
 {
     using (IZetboxContext ctx = GetContext())
     {
         TestObjClass newObj = ctx.Create(iftFactory(typeof(TestObjClass))) as TestObjClass;
         Assert.That(newObj, Is.Not.Null);
         Assert.That(newObj.Context, Is.Not.Null);
     }
 }
Пример #6
0
        public void Create_T()
        {
            TestObjClass obj = ctx.Create <TestObjClass>();

            Assert.That(obj, Is.Not.Null);
            Assert.That(obj.ID, Is.LessThan(Helper.INVALIDID));
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.New));
            Assert.That(obj.Context, Is.EqualTo(ctx));
        }
Пример #7
0
        public void Create_ObjectType()
        {
            TestObjClass obj = ctx.Create(_iftFactory(typeof(TestObjClass))) as TestObjClass;

            Assert.That(obj, Is.Not.Null);
            Assert.That(obj.ID, Is.LessThan(Helper.INVALIDID));
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.New));
            Assert.That(obj.Context, Is.EqualTo(ctx));
        }
Пример #8
0
 public void Detach_IDataObject()
 {
     using (IZetboxContext ctx = GetContext())
     {
         TestObjClass obj = ctx.GetQuery <TestObjClass>().First();
         ctx.Detach(obj);
         Assert.That(((TestObjClassEfImpl)obj).EntityState, Is.EqualTo(EntityState.Detached));
     }
 }
Пример #9
0
 public void Find_ObjectType_returns_right_object()
 {
     using (IZetboxContext ctx = GetContext())
     {
         TestObjClass obj = (TestObjClass)ctx.Find(iftFactory(typeof(TestObjClass)), firstId);
         Assert.That(obj, Is.Not.Null);
         Assert.That(obj.ID, Is.EqualTo(firstId));
         Assert.That(obj.TestEnumProp, Is.EqualTo(TestEnum.First));
     }
 }
Пример #10
0
 public void Find_T_returns_right_object()
 {
     using (IZetboxContext ctx = GetContext())
     {
         TestObjClass obj = ctx.Find <TestObjClass>(firstId);
         Assert.That(obj, Is.Not.Null);
         Assert.That(obj.ID, Is.EqualTo(firstId));
         Assert.That(obj.TestEnumProp, Is.EqualTo(TestEnum.First));
     }
 }
Пример #11
0
        public void GetListOf()
        {
            TestObjClass        o    = (TestObjClass)ctx.Find(_iftFactory(typeof(TestObjClass)), 1);
            List <TestObjClass> list = ctx.GetListOf <TestObjClass>(o, "Children");

            Assert.That(list, Is.Not.Null);
            Assert.That(list.Count, Is.AtLeast(2));
            list.ForEach(obj => Assert.That(obj, Is.Not.Null));
            list.ForEach(obj => Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Unmodified)));
            list.ForEach(obj => Assert.That(obj.Context, Is.EqualTo(ctx)));
        }
Пример #12
0
        public void Find_ObjectType_should_return_correct_item()
        {
            int          targetId = 1;
            TestObjClass obj      = (TestObjClass)ctx.Find(_iftFactory(typeof(TestObjClass)), targetId);

            Assert.That(obj, Is.Not.Null);
            Assert.That(obj, Is.InstanceOf(typeof(TestObjClass)));
            Assert.That(obj.ID, Is.EqualTo(targetId));
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Unmodified));
            Assert.That(obj.Context, Is.EqualTo(ctx));
        }
Пример #13
0
        public void should_not_change_on_First()
        {
            TestObjClass obj = ctx.GetQuery <TestObjClass>().First(i => i.ID == 1);

            Assert.That(obj.StringProp, Is.EqualTo("String 1"));
            obj.StringProp = "Changed";
            TestObjClass obj_test = ctx.GetQuery <TestObjClass>().First(i => i.ID == 1);

            Assert.That(obj_test.StringProp, Is.EqualTo("Changed"));
            Assert.That(obj.StringProp, Is.EqualTo("Changed"));
            Assert.That(obj, Is.SameAs(obj_test));
        }
Пример #14
0
        public void should_not_change_on_Find()
        {
            TestObjClass obj = ctx.Find <TestObjClass>(1);

            Assert.That(obj.StringProp, Is.EqualTo("String 1"));
            obj.StringProp = "Changed";
            TestObjClass obj_test = ctx.Find <TestObjClass>(1);

            Assert.That(obj_test.StringProp, Is.EqualTo("Changed"));
            Assert.That(obj.StringProp, Is.EqualTo("Changed"));
            Assert.That(obj, Is.SameAs(obj_test));
        }
Пример #15
0
        public void SubmitChanges_Nothing()
        {
            TestObjClass obj = ctx.Find <TestObjClass>(1);

            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Unmodified));

            int result = ctx.SubmitChanges();

            Assert.That(result, Is.EqualTo(0));
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Unmodified));
            Assert.That(obj.Context, Is.EqualTo(ctx));
        }
Пример #16
0
        public void SubmitChanges_New()
        {
            TestObjClass obj = ctx.Create <TestObjClass>();

            obj.StringProp = "Test";
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.New));

            int result = ctx.SubmitChanges();

            Assert.That(result, Is.EqualTo(1));
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Unmodified));
            Assert.That(obj.Context, Is.EqualTo(ctx));
        }
Пример #17
0
        public void should_change_on_GetList()
        {
            TestObjClass obj = ctx.GetQuery <TestObjClass>().First(i => i.ID == 1);

            Assert.That(obj.StringProp, Is.EqualTo("String 1"));
            obj.StringProp = "Changed";
            var          lst      = ctx.GetQuery <TestObjClass>().ToList();
            TestObjClass obj_test = ctx.Find <TestObjClass>(1);

            Assert.That(lst.Count, Is.GreaterThan(0));
            Assert.That(obj.StringProp, Is.EqualTo("String 1"));
            Assert.That(obj_test.StringProp, Is.EqualTo("String 1"));
            Assert.That(obj, Is.SameAs(obj_test));
        }
Пример #18
0
        public void SubmitChanges_Delete()
        {
            TestObjClass obj = ctx.Find <TestObjClass>(1);

            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Unmodified));
            ctx.Delete(obj);
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Deleted));

            int result = ctx.SubmitChanges();

            Assert.That(result, Is.EqualTo(1));
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Deleted));
            Assert.That(obj.Context, Is.Null);
        }
Пример #19
0
        public void Create_T_Twice()
        {
            TestObjClass obj1 = ctx.Create <TestObjClass>();

            Assert.That(obj1, Is.Not.Null);
            Assert.That(obj1.ID, Is.LessThan(Helper.INVALIDID));
            Assert.That(obj1.Context, Is.EqualTo(ctx));

            TestObjClass obj2 = ctx.Create <TestObjClass>();

            Assert.That(obj2, Is.Not.Null);
            Assert.That(obj2.ID, Is.LessThan(Helper.INVALIDID));
            Assert.That(obj2.Context, Is.EqualTo(ctx));

            Assert.That(obj1, Is.Not.EqualTo(obj2));
        }
Пример #20
0
        public void Create_Generic()
        {
            using (IZetboxContext ctx = GetContext())
            {
                bool hasCreated = false;
                GenericEventHandler <IPersistenceObject> createdHandler = new GenericEventHandler <IPersistenceObject>(delegate(object obj, GenericEventArgs <IPersistenceObject> e) { hasCreated = true; });
                ctx.ObjectCreated += createdHandler;

                TestObjClass newObj = ctx.Create <TestObjClass>();
                Assert.That(newObj, Is.Not.Null);
                Assert.That(newObj.Context, Is.Not.Null);
                Assert.That(hasCreated, Is.True);

                ctx.ObjectCreated -= createdHandler;
            }
        }
Пример #21
0
        public void SubmitChanges()
        {
            int    testId     = 1;
            string testString = "Test";

            TestObjClass obj = ctx.Find <TestObjClass>(testId);

            obj.StringProp = testString;
            Assert.That(obj.ID, Is.EqualTo(testId));
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Modified));

            int result = ctx.SubmitChanges();

            Assert.That(result, Is.EqualTo(1));
            Assert.That(obj.ObjectState, Is.EqualTo(DataObjectState.Unmodified));
            Assert.That(obj.Context, Is.EqualTo(ctx));
            Assert.That(obj.StringProp, Is.EqualTo(testString));
        }
Пример #22
0
        public void FromStream_Attached()
        {
            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));

            obj.ToStream(sw, null, false);

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

            ms.Seek(0, SeekOrigin.Begin);

            var          ctxMock = GetContext();
            TestObjClass result  = ctxMock.Create <TestObjClass>();

            Assert.That(result.IsAttached, Is.True);
            Assert.That(() => result.FromStream(sr), Throws.InstanceOf <InvalidOperationException>());
        }
Пример #23
0
        public void UpdateSomeData_SubmitChanges()
        {
            using (IZetboxContext ctx = GetContext())
            {
                TestObjClass obj = ctx.Find <TestObjClass>(firstId);
                Assert.That(obj, Is.Not.Null);
                Assert.That(obj.StringProp, Is.EqualTo("First"));

                obj.StringProp = "Test";
                ctx.SubmitChanges();
            }

            using (IZetboxContext ctx = GetContext())
            {
                TestObjClass obj = ctx.Find <TestObjClass>(firstId);
                Assert.That(obj, Is.Not.Null);
                Assert.That(obj.StringProp, Is.EqualTo("Test"));
            }
        }
Пример #24
0
        public void GetObject_GetList()
        {
            TestObjClass obj = ctx.Find <TestObjClass>(1);

            Assert.That(obj, Is.Not.Null);
            Assert.That(obj.ID, Is.EqualTo(1));

            List <TestObjClass> list = ctx.GetQuery <TestObjClass>().ToList();

            Assert.That(list, Is.Not.Null);
            Assert.That(list.Count, Is.AtLeast(2));

            TestObjClass obj_list = list.Single(o => o.ID == 1);

            Assert.That(obj_list, Is.Not.Null);
            Assert.That(obj_list.ID, Is.EqualTo(1));

            Assert.That(object.ReferenceEquals(obj, obj_list), "obj & obj_list are different Objects");
        }
Пример #25
0
        public static void ServerObjParameter(MethodTest obj, MethodReturnEventArgs<TestObjClass> e, TestObjClass input)
        {
            var ctx = obj.Context;

            var newA = ctx.Create<TestObjClass>();
            newA.StringProp = "A";
            var kundeA = ctx.Create<Kunde>();
            kundeA.Kundenname = "Kunde A";
            kundeA.PLZ = "1210";
            newA.ObjectProp = kundeA;

            var newB = ctx.Create<TestObjClass>();
            newB.StringProp = "B";
            var kundeB = ctx.Create<Kunde>();
            kundeB.Kundenname = "Kunde";
            kundeB.PLZ = "1210";
            newB.ObjectProp = kundeB;

            e.Result = input ?? newA;
        }
Пример #26
0
        public void GetListOf_Twice()
        {
            TestObjClass        o     = (TestObjClass)ctx.Find(_iftFactory(typeof(TestObjClass)), 1);
            List <TestObjClass> list1 = ctx.GetListOf <TestObjClass>(o, "Children");

            Assert.That(list1, Is.Not.Null);
            Assert.That(list1.Count, Is.AtLeast(2));
            list1.ForEach(obj => Assert.That(o, Is.Not.Null));

            List <TestObjClass> list2 = ctx.GetListOf <TestObjClass>(o, "Children");

            Assert.That(list2, Is.Not.Null);
            Assert.That(list2.Count, Is.EqualTo(list1.Count));
            list2.ForEach(obj => Assert.That(o, Is.Not.Null));

            for (int i = 0; i < list1.Count; i++)
            {
                Assert.That(list1[i], Is.EqualTo(list2[i]));
            }
        }
Пример #27
0
 public TestObjClassViewModel(
     IViewModelDependencies appCtx, IZetboxContext dataCtx, ViewModel parent,
     TestObjClass obj)
     : base(appCtx, dataCtx, parent, obj)
 {
 }
Пример #28
0
 public static void get_CalculatedEnumeration(TestObjClass obj, PropertyGetterEventArgs<TestEnum> e)
 {
     e.Result = obj.ID % 2 == 0
         ? TestEnum.First
         : TestEnum.Second;
 }