Example #1
0
        public void FetchAndSaveChild()
        {
            IChildDataPortal <Child> childDataPortal = _testDIContext.CreateChildDataPortal <Child>();
            IDataPortal <Root>       dataPortal      = _testDIContext.CreateDataPortal <Root>();

            Root root = dataPortal.Create();

            root.FetchChild(childDataPortal);

            Assert.IsFalse(root.Child.IsNew, "Child should not be new");
            Assert.IsFalse(root.Child.IsDirty, "Child should not be dirty");
            Assert.AreEqual("Fetched", root.Child.Status, "Child status incorrect after fetch");

            root.Child.Data = "b";

            Assert.IsTrue(root.Child.IsDirty, "Child should be dirty");

            root = root.Save();

            Assert.IsFalse(root.IsDirty, "Root should not be dirty");
            Assert.IsFalse(root.IsNew, "Root should not be new");
            Assert.IsFalse(root.Child.IsDirty, "Child should not be dirty");
            Assert.IsFalse(root.Child.IsNew, "Child should not be new");
            Assert.AreEqual("Updated", root.Child.Status, "Child status incorrect after Save");
        }
Example #2
0
        public async Task CreateChildNoCriteria()
        {
            var dp    = _testDIContext.CreateChildDataPortal <TestChild>();
            var child = await dp.CreateChildAsync();

            Assert.AreEqual("none", child.Name);
        }
Example #3
0
        public void Test_ChildDataPortal_Array()
        {
            IChildDataPortal <ArrayDataPortalClass> childDataPortal = _testDIContext.CreateChildDataPortal <ArrayDataPortalClass>();

            TestResults.Reinitialise();
            _ = ArrayDataPortalClass.GetChild(childDataPortal, new int[] { 1, 2, 3 });
            Assert.AreEqual("FetchChild(int[] values)", TestResults.GetResult("Method"));

            TestResults.Reinitialise();
            _ = ArrayDataPortalClass.GetChild(childDataPortal, new string[] { "a", "b", "c" });
            Assert.AreEqual("FetchChild(string[] values)", TestResults.GetResult("Method"));
        }
Example #4
0
        public async Task CreateAndSaveChildAsync()
        {
            IChildDataPortal <Child> childDataPortal = _testDIContext.CreateChildDataPortal <Child>();
            IDataPortal <Root>       dataPortal      = _testDIContext.CreateDataPortal <Root>();

            Root root = await dataPortal.CreateAsync();

            await root.FetchChildAsync(childDataPortal);

            Assert.IsFalse(root.Child.IsDirty, "Child should not be dirty");
            Assert.AreEqual("Fetched", root.Child.Status, "Child status incorrect after fetch");

            root = await root.SaveAsync();

            Assert.AreEqual("Fetched", root.Child.Status, "Child status incorrect after Save");
        }
Example #5
0
        public void RootChangedMetastateEventsChild()
        {
            IChildDataPortal <Child> childDataPortal = _testDIContext.CreateChildDataPortal <Child>();

            Csla.ApplicationContext.PropertyChangedMode = ApplicationContext.PropertyChangedModes.Xaml;
            var graph   = NewRoot();
            var changed = new List <string>();

            graph.PropertyChanged += (o, e) =>
            {
                changed.Add(e.PropertyName);
            };
            graph.Name = "abc";
            changed.Clear();
            graph.Children.Add(childDataPortal.FetchChild(123, "xyz"));

            Assert.IsTrue(graph.IsDirty, "IsDirty should be true");

            Assert.IsFalse(changed.Contains("Children"), "Children after add");
            Assert.IsTrue(changed.Contains("IsDirty"), "IsDirty after add");
            Assert.IsFalse(changed.Contains("IsSelfDirty"), "IsSelfDirty after add");
            Assert.IsTrue(changed.Contains("IsValid"), "IsValid after add");
            Assert.IsFalse(changed.Contains("IsSelfValid"), "IsSelfValid after add");
            Assert.IsTrue(changed.Contains("IsSavable"), "IsSavable after add");
            Assert.IsFalse(changed.Contains("IsNew"), "IsNew after add");
            Assert.IsFalse(changed.Contains("IsDeleted"), "IsDeleted after add");

            graph = graph.Save();
            changed.Clear();
            graph.PropertyChanged += (o, e) =>
            {
                changed.Add(e.PropertyName);
            };

            Assert.IsFalse(graph.IsDirty, "IsDirty should be false");

            graph.Children[0].Name = "mnop";

            Assert.IsTrue(graph.IsDirty, "IsDirty should be true");

            Assert.IsFalse(changed.Contains("Children"), "Children after add");
            Assert.IsTrue(changed.Contains("IsDirty"), "IsDirty after add");
            Assert.IsFalse(changed.Contains("IsSelfDirty"), "IsSelfDirty after add");
            Assert.IsTrue(changed.Contains("IsValid"), "IsValid after add");
            Assert.IsFalse(changed.Contains("IsSelfValid"), "IsSelfValid after add");
            Assert.IsTrue(changed.Contains("IsSavable"), "IsSavable after add");
            Assert.IsFalse(changed.Contains("IsNew"), "IsNew after add");
            Assert.IsFalse(changed.Contains("IsDeleted"), "IsDeleted after add");
        }
Example #6
0
        public void Blb2Loc_Add()
        {
            IDataPortal <TestList>      dataPortal      = _testDIContext.CreateDataPortal <TestList>();
            IChildDataPortal <TestItem> childDataPortal = _testDIContext.CreateChildDataPortal <TestItem>();

            var source = dataPortal.Create();
            var query  = from r in source
                         where r.Id > 100
                         select r;
            var synced = source.ToSyncList(query);

            var newItem = childDataPortal.FetchChild(432, "New item");

            synced.Add(newItem);

            Assert.AreEqual(4, synced.Count, "synced should have item");
            Assert.AreEqual(5, source.Count, "source should have item");
            Assert.IsTrue(synced.Contains(newItem), "synced should contain new item");
            Assert.IsTrue(source.Contains(newItem), "source should contain new item");
        }
Example #7
0
        public void SerializedEditLevel()
        {
            IDataPortal <EditableGetSet>      dataPortal      = _testDIContext.CreateDataPortal <EditableGetSet>();
            IChildDataPortal <EditableGetSet> childDataPortal = _testDIContext.CreateChildDataPortal <EditableGetSet>();

            EditableGetSet root = EditableGetSet.GetObject(dataPortal);

            Assert.AreEqual(0, root.EditLevel, "Root edit level before BeginEdit");
            root.BeginEdit();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after BeginEdit");
            Assert.AreEqual(1, root.ManagedChild.EditLevel, "Child edit level after BeginEdit");
            Assert.AreEqual(1, root.ManagedChildList.EditLevel, "List edit level after BeginEdit");
            root.ManagedChildList.Add(EditableGetSet.NewChildObject(childDataPortal));
            Assert.AreEqual(1, root.ManagedChildList[0].EditLevel, "List child edit level after BeginEdit");

            root = root.Clone();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after Clone");
            Assert.AreEqual(1, root.ManagedChild.EditLevel, "Child edit level after Clone");
            Assert.AreEqual(1, root.ManagedChildList.EditLevel, "List edit level after Clone");
            Assert.AreEqual(1, root.ManagedChildList[0].EditLevel, "List child edit level after Clone");

            Assert.IsTrue(root.IsDirty, "Root should be dirty");
        }
Example #8
0
        private T CreateChildWithoutCriteria <T>()
        {
            IChildDataPortal <T> dataPortal = _testDIContext.CreateChildDataPortal <T>();

            return(dataPortal.CreateChild());
        }
Example #9
0
        private ChildList CreateChildList()
        {
            IChildDataPortal <ChildList> childDataPortal = _testDIContext.CreateChildDataPortal <ChildList>();

            return(childDataPortal.CreateChild());
        }