예제 #1
0
        public void RootChildListUndoCancel()
        {
            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");

            ChildList list = root.ManagedChildList;

            Assert.AreEqual(1, list.EditLevel, "List edit level after being created");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty");
            Assert.IsFalse(list.IsDirty, "List should not be dirty");

            list.Add(EditableGetSet.NewChildObject(childDataPortal));
            Assert.AreEqual(1, list.Count, "List count should be 1");

            root.CancelEdit();
            Assert.AreEqual(0, root.EditLevel, "Root edit level after CancelEdit");
            ChildList secondList = root.ManagedChildList;

            Assert.AreEqual(0, secondList.EditLevel, "Second list edit level after CancelEdit");
            Assert.IsFalse(ReferenceEquals(list, secondList), "List objects should not be the same");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty after CancelEdit");
            Assert.IsFalse(secondList.IsDirty, "Second list should not be dirty");
        }
예제 #2
0
 private void Create([Inject] IChildDataPortal <ChildItem> childDataPortal)
 {
     using (SuppressListChangedEvents)
     {
         Add(childDataPortal.CreateChild());
     }
 }
예제 #3
0
 private void DataPortal_Fetch(object criteria, IChildDataPortal <ChildEntity> childDataPortal)
 {
     for (int i = 0; i < 10; i++)
     {
         Add(childDataPortal.CreateChild(i, "first" + i, "last" + i));
     }
 }
 private void Create([Inject] IChildDataPortal <TestItem> childDataPortal)
 {
     Add(childDataPortal.FetchChild(123, "Zebra has stripes"));
     Add(childDataPortal.FetchChild(2233, "Software is neat"));
     Add(childDataPortal.FetchChild(453, "Run, the sky is falling"));
     Add(childDataPortal.FetchChild(12, "What is new?"));
 }
예제 #5
0
        public void If_FieldBackedString_Is_Changed_On_GrandChild_List_Item_After_Root_Is_Deserialized_Then_Root_ChildChanged_Event_Fires()
        {
            IDataPortal <EditableGetSet>      dataPortal      = _testDIContext.CreateDataPortal <EditableGetSet>();
            IChildDataPortal <EditableGetSet> childDataPortal = _testDIContext.CreateChildDataPortal <EditableGetSet>();

            var root       = EditableGetSet.GetObject(dataPortal);
            var child      = EditableGetSet.NewChildObject(childDataPortal);
            var grandChild = EditableGetSet.NewChildObject(childDataPortal);

            root.ManagedChildList.Add(child);
            child.ManagedChildList.Add(grandChild);

            var             applicationContext = _testDIContext.CreateTestApplicationContext();
            MemoryStream    stream             = new MemoryStream();
            MobileFormatter formatter          = new MobileFormatter(applicationContext);

            formatter.Serialize(stream, root);
            stream.Seek(0, SeekOrigin.Begin);
            root = (EditableGetSet)formatter.Deserialize(stream);

            int changed = 0;

            root.ChildChanged += (o, e) => { changed++; };
            root.ManagedChildList[0].ManagedChildList[0].FieldBackedString = "changed";
            Assert.AreEqual(1, changed, "after MobileFormatter");

            changed            = 0;
            root               = root.Clone();
            root.ChildChanged += (o, e) => { changed++; };
            root.ManagedChildList[0].ManagedChildList[0].FieldBackedString = "changed again";
            Assert.AreEqual(1, changed, "after clone");
        }
예제 #6
0
 private void DataPortal_Fetch([Inject] IChildDataPortal <InitializeRoot> childDataPortal)
 {
     using (SuppressListChangedEvents)
     {
         Add(childDataPortal.FetchChild("abc"));
     }
 }
예제 #7
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");
        }
예제 #8
0
 protected void DataPortal_Create(int criteria, [Inject] IChildDataPortal <CustomerContactList> childDataPortal)
 {
     LoadProperty(IdProperty, criteria);
     LoadProperty(NameProperty, "New Customer for Id: " + criteria.ToString());
     LoadProperty(DateCreatedProperty, new SmartDate(DateTime.Today));
     LoadProperty(DateTimeOffsetNotNullProperty, DateTimeOffset.Now);
     LoadProperty(ContactsProperty, childDataPortal.FetchChild(0));
 }
예제 #9
0
        private void Fetch([Inject] DataAccess.IPersonDal dal, [Inject] IChildDataPortal <PersonInfo> personPortal)
        {
            IsReadOnly = false;
            var data = dal.Get().Select(d => personPortal.FetchChild(d));

            AddRange(data);
            IsReadOnly = true;
        }
예제 #10
0
 private void Fetch([Inject] DataAccess.IPersonDal dal, [Inject] IChildDataPortal <PersonInfo> personInfoPortal)
 {
     using (LoadListMode)
     {
         var data = dal.Get().Select(d => personInfoPortal.FetchChild(d));
         AddRange(data);
     }
 }
예제 #11
0
 private void Fetch(bool child, [Inject] IChildDataPortal <SingleRoot> childDataPortal)
 {
     LoadProperty(ChildProperty, childDataPortal.FetchChild(true));
     if (child)
     {
         MarkAsChild();
     }
 }
예제 #12
0
 private void DataPortal_Fetch([Inject] IChildDataPortal <TestItem> childDataPortal)
 {
     Add(childDataPortal.FetchChild(123));
     Add(childDataPortal.FetchChild(2));
     Add(childDataPortal.FetchChild(13));
     Add(childDataPortal.FetchChild(23));
     Add(childDataPortal.FetchChild(3));
 }
예제 #13
0
 protected void DataPortal_Create([Inject] IChildDataPortal <EditableChild1> childDataPortal)
 {
     using (BypassPropertyChecks)
     {
         LoadProperty(ChildProperty, childDataPortal.CreateChild());
     }
     BusinessRules.CheckRules();
 }
예제 #14
0
 protected void DataPortal_Create([Inject] IChildDataPortal <ChildEntityList> childDataPortal)
 {
     SetProperty(ChildrenProperty, childDataPortal.CreateChild());
     TestResults.Reinitialise();
     TestResults.Add("ParentEntity", "Created");
     BusinessRules.CheckRules();
     Console.WriteLine("DataPortal_Create");
 }
예제 #15
0
 protected void DataPortal_Fetch(object criteria, [Inject] IChildDataPortal <ChildEntityList> dataPortal)
 {
     _children = dataPortal.CreateChild();
     Console.WriteLine("DataPortal_Fetch");
     TestResults.Reinitialise();
     TestResults.Add("ParentEntity", "Fetched");
     BusinessRules.CheckRules();
 }
예제 #16
0
        private void Create([Inject] IChildDataPortal <FakePersonEmailAddresses> dataPortal)
        {
            // Create an empty list for holding email addresses
            LoadProperty(EmailAddressesProperty, dataPortal.CreateChild());

            // Trigger object checks
            BusinessRules.CheckRules();
        }
예제 #17
0
 private void Child_Fetch(int customerID, [Inject] IChildDataPortal <CustomerContact> childDataPortal)
 {
     this.RaiseListChangedEvents = false;
     for (int i = 1; i <= customerID; i++)
     {
         Add(childDataPortal.FetchChild(customerID, i, "First Name # " + i.ToString(), "Last Name # " + i.ToString(), new DateTime(1980 + i, 1, 1)));
     }
     this.RaiseListChangedEvents = true;
 }
예제 #18
0
파일: Root.cs 프로젝트: gnilesh4/csla
 private void DataPortal_Create(Criteria criteria, [Inject] IChildDataPortal <Children> dataPortal)
 {
     using (BypassPropertyChecks)
     {
         Data     = criteria._data;
         Children = dataPortal.CreateChild();
     }
     CreatedDomain = AppDomain.CurrentDomain.Id;
 }
예제 #19
0
파일: Root.cs 프로젝트: gnilesh4/csla
 protected void DataPortal_Fetch(Criteria criteria, [Inject] IChildDataPortal <Children> dataPortal)
 {
     using (BypassPropertyChecks)
     {
         Data     = criteria._data;
         Children = dataPortal.CreateChild();
     }
     MarkOld();
 }
예제 #20
0
            private void DataPortal_Fetch([Inject] IChildDataPortal <SimpleBO> simpleBOPortal, [Inject] IChildDataPortal <SimpleBOList> simpleBOListPortal)
            {
                Depth = 0;
                LoadProperty(NameProperty, "Jupiter");
                LoadProperty(ChildProperty, simpleBOPortal.FetchChild(Depth + 1));
                LoadProperty(ChildListProperty, simpleBOListPortal.FetchChild(Depth + 1));

                BusinessRules.CheckRules();
            }
예제 #21
0
파일: ArrayTests.cs 프로젝트: gnilesh4/csla
        public void Test_ChildDataPortal_Params()
        {
            IChildDataPortal <ArrayDataPortalClass> childDataPortal = _testDIContext.CreateChildDataPortal <ArrayDataPortalClass>();

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

            TestResults.Reinitialise();
            _ = ArrayDataPortalClass.GetChildParams(childDataPortal, "a", "b", "c");
            Assert.AreEqual("FetchChild(string[] values)", TestResults.GetResult("Method"));
        }
예제 #22
0
            private void Child_Fetch(int depth, [Inject] IChildDataPortal <SimpleBO> simpleBOPortal, [Inject] IChildDataPortal <SimpleBOList> simpleBOListPortal)
            {
                Depth = depth;
                LoadProperty(NameProperty, "Saturn");

                if (depth < 4)
                {
                    LoadProperty(ChildProperty, simpleBOPortal.FetchChild(Depth + 1));
                    LoadProperty(ChildListProperty, simpleBOListPortal.FetchChild(Depth + 1));
                }

                BusinessRules.CheckRules();
            }
예제 #23
0
        protected void DataPortal_Fetch(int criteria, [Inject] IChildDataPortal <CustomerContactList> childDataPortal)
        {
            LoadProperty(IdProperty, criteria);
            LoadProperty(NameProperty, "Customer Name for Id: " + criteria.ToString());
            LoadProperty(DateCreatedProperty, new SmartDate(new DateTime(2000 + criteria, 1, 1)));
            LoadProperty(ContactsProperty, childDataPortal.FetchChild(criteria));
            LoadProperty(DateTimeOffsetNotNullProperty, DateTimeOffset.Now);
            LoadProperty(TypeProperty, CustomeType.Inactive);

            if (criteria == customerIDThrowsException)
            {
                throw new ApplicationException("Test for Silverlight DataSource Error!");
            }
        }
예제 #24
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");
        }
예제 #25
0
        public async Task CreateAndSaveAnyChildAsync()
        {
            IChildDataPortal <Child>            childDataPortal = _testDIContext.CreateChildDataPortal <Child>();
            IDataPortal <RootUpdateAllChildren> dataPortal      = _testDIContext.CreateDataPortal <RootUpdateAllChildren>();

            var 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("Updated", root.Child.Status, "Child status incorrect after Save");
        }
예제 #26
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");
        }
예제 #27
0
        public void If_FieldBackedString_Property_Is_Changed_On_Child_After_CancelEdit_Then_ChildChanged_Fires_On_Root()
        {
            IDataPortal <EditableGetSet>      dataPortal      = _testDIContext.CreateDataPortal <EditableGetSet>();
            IChildDataPortal <EditableGetSet> childDataPortal = _testDIContext.CreateChildDataPortal <EditableGetSet>();

            var root       = EditableGetSet.GetObject(dataPortal);
            var child      = EditableGetSet.NewChildObject(childDataPortal);
            var grandChild = EditableGetSet.NewChildObject(childDataPortal);

            root.ManagedChildList.Add(child);
            child.ManagedChildList.Add(grandChild);

            root.BeginEdit();
            root.CancelEdit();

            int changed = 0;

            root.ChildChanged      += (o, e) => { changed++; };
            child.FieldBackedString = "changed";

            Assert.AreEqual(1, changed);
        }
예제 #28
0
        public void If_FieldBackedString_Property_Changes_On_Item_In_ManagedChildList_Then_ChildChanged_Fires_On_Root_And_On_ManagedChildList()
        {
            IDataPortal <EditableGetSet>      dataPortal      = _testDIContext.CreateDataPortal <EditableGetSet>();
            IChildDataPortal <EditableGetSet> childDataPortal = _testDIContext.CreateChildDataPortal <EditableGetSet>();

            int rootChanged = 0;
            int listChanged = 0;

            EditableGetSet root = EditableGetSet.GetObject(dataPortal);

            root.ChildChanged += (o, e) => { rootChanged++; };

            var list = root.ManagedChildList;

            list.ChildChanged += (o, e) => { listChanged++; };

            list.Add(EditableGetSet.NewChildObject(childDataPortal));
            list[0].FieldBackedString = "child change";

            Assert.AreEqual(4, rootChanged);//this event fires 4 times: lazy load of the child list, Item[], Count and property change on item in the list
            Assert.AreEqual(1, listChanged);
        }
예제 #29
0
        public void If_FieldBackedString_Changes_On_GrandChild_Then_ChildChanged_Fires_On_GrandChild_Child_and_Root()
        {
            IDataPortal <EditableGetSet>      dataPortal      = _testDIContext.CreateDataPortal <EditableGetSet>();
            IChildDataPortal <EditableGetSet> childDataPortal = _testDIContext.CreateChildDataPortal <EditableGetSet>();

            int rootChanged               = 0;
            int childListChanged          = 0;
            int grandChildListChanged     = 0;
            int childChanged              = 0;
            int grandChildPropertyChanged = 0;

            EditableGetSet root = EditableGetSet.GetObject(dataPortal);

            root.PropertyChanged += (o, e) => { throw new InvalidOperationException(); };
            root.ChildChanged    += (o, e) => { rootChanged++; };
            root.ManagedChildList.ChildChanged += (o, e) => { childListChanged++; };

            var child = EditableGetSet.NewChildObject(childDataPortal);

            child.PropertyChanged += (o, e) => { throw new InvalidOperationException(); };
            child.ChildChanged    += (o, e) => { childChanged++; };
            child.ManagedChildList.ChildChanged += (o, e) => { grandChildListChanged++; };

            var grandChild = EditableGetSet.NewChildObject(childDataPortal);

            grandChild.ChildChanged    += (o, e) => { throw new InvalidOperationException(); }; // ChildChange only fires when child of self changes
            grandChild.PropertyChanged += (o, e) => { grandChildPropertyChanged++; };

            root.ManagedChildList.Add(child);
            child.ManagedChildList.Add(grandChild);
            root.ManagedChildList[0].ManagedChildList[0].FieldBackedString = "child change"; // or c2.FieldBackedString = "child change";

            Assert.AreEqual(7, rootChanged);                                                 //Child, and GrandChild lists lazy loaded + Property changed on GrandChildList Item
            Assert.AreEqual(4, childChanged);                                                //GrandChild lists lazy loaded + Property changed on GrandChildList Item
            Assert.AreEqual(4, childListChanged);                                            //GrandChild lists lazy loaded + Property changed on GrandChildList Item
            Assert.AreEqual(1, grandChildListChanged);                                       //Property changed on GrandChildList Item
            Assert.AreEqual(1, grandChildPropertyChanged);                                   //Property changed on GrandChildList Item
        }
예제 #30
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");
        }