示例#1
0
        public void FetchAndSaveChildList()
        {
            IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>();

            Root root = dataPortal.Fetch();
            var  list = root.ChildList;

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

            list.Add(NewChild());

            Assert.IsTrue(root.ChildList.IsDirty, "Child list should be dirty after add");
            Assert.IsTrue(root.ChildList[0].IsDirty, "Child should be dirty after add");
            Assert.IsTrue(root.ChildList[0].IsNew, "Child should be new after add");

            root = root.Save();

            Assert.IsFalse(root.IsDirty, "Root should not be dirty after Save");
            Assert.IsFalse(root.IsNew, "Root should not be new");
            Assert.IsFalse(root.ChildList.IsDirty, "Child should not be dirty after Save");
            Assert.AreEqual("Updated", root.ChildList.Status, "Child list status incorrect after Save");
            Assert.IsFalse(root.ChildList[0].IsDirty, "Child should not be dirty after Save");
            Assert.IsFalse(root.ChildList[0].IsNew, "Child should not be new after Save");
            Assert.AreEqual("Inserted", root.ChildList[0].Status, "Child status incorrect after Save");
        }
示例#2
0
        public void Initialize_ValidRootObjectWithChild_NoExceptionRaised()
        {
            // Arrange
            bool executed = false;
            IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>();
            Root  rootObject  = dataPortal.Fetch(new Root.Criteria("Test Data"));
            Child childObject = rootObject.Children.AddNew();

            childObject.Data = "Test child data";
            ApplicationContext      applicationContext = _testDIContext.CreateTestApplicationContext();
            RevalidatingInterceptor sut  = new RevalidatingInterceptor(applicationContext);
            InterceptArgs           args = new InterceptArgs()
            {
                ObjectType = typeof(Root),
                Operation  = DataPortalOperations.Update,
                Parameter  = rootObject,
                IsSync     = true
            };

            applicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
            applicationContext.LocalContext["__logicalExecutionLocation"] = ApplicationContext.LogicalExecutionLocations.Server;

            // Act
            sut.Initialize(args);
            executed = true;

            // Assert
            Assert.IsTrue(executed);
        }
示例#3
0
        public void UpdateItem()
        {
            IDataPortal <ERlist> dataPortal     = _testDIContext.CreateDataPortal <ERlist>();
            IDataPortal <ERitem> itemDataPortal = _testDIContext.CreateDataPortal <ERitem>();

            TestResults.Reinitialise();

            _isListSaved = false;

            ERlist list = dataPortal.Create();

            list.Saved += new EventHandler <Csla.Core.SavedEventArgs>(List_Saved);
            list.Add(itemDataPortal.Fetch("test"));
            ERitem item = list[0];

            Assert.AreEqual(1, list.Count, "Incorrect count after add");
            Assert.IsFalse(list[0].IsNew, "Object should not be new");

            // simulate grid edit
            System.ComponentModel.IEditableObject obj = (System.ComponentModel.IEditableObject)item;
            obj.BeginEdit();
            item.Data = "new data";
            Assert.IsFalse(list[0].IsNew, "Object should not be new");
            Assert.IsFalse(list[0].IsDeleted, "Object should not be deleted");
            Assert.IsTrue(list[0].IsDirty, "Object should be dirty");
            obj.EndEdit();
            Assert.AreEqual(true, _isListSaved, "List saved event did not fire after save.");
            Assert.AreEqual("Update", TestResults.GetResult("DP"), "Object should have been updated");
            Assert.IsFalse(list[0].IsNew, "Object should not be new");
        }
示例#4
0
        public void TestBypassReadWriteWithRightsTurnNotificationBackOn()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <BypassBusinessBase> dataPortal = testDIContext.CreateDataPortal <BypassBusinessBase>();

            UnitTestContext    context = GetContext();
            bool               propertyChangedFired = false;
            BypassBusinessBase testObj = dataPortal.Fetch();

            testObj.PropertyChanged += (o, e) =>
            {
                propertyChangedFired = true;
            };
            testObj.LoadIdByPass(1);
            context.Assert.AreEqual(1, testObj.ReadIdByPass());
            context.Assert.AreEqual(false, propertyChangedFired);
            context.Assert.AreEqual(false, testObj.IsDirty);

            testObj.LoadIdByNestedPass(3);
            context.Assert.AreEqual(3, testObj.ReadIdByPass());
            context.Assert.AreEqual(false, propertyChangedFired);
            context.Assert.AreEqual(false, testObj.IsDirty);

            testObj.LoadId(2);
            context.Assert.AreEqual(true, propertyChangedFired);
            context.Assert.AreEqual(2, testObj.ReadId());
            context.Assert.AreEqual(true, testObj.IsDirty);

            context.Assert.Success();
            context.Complete();
        }
示例#5
0
        private SimpleBO Fetch()
        {
            IDataPortal <SimpleBO> dataPortal = _testDIContext.CreateDataPortal <SimpleBO>();

            var result = dataPortal.Fetch();

            void HookEvents(SimpleBO bo)
            {
                bo.PropertyChanged += Result_PropertyChanged;
                bo.ChildChanged    += Result_ChildChanged;

                if (bo.Child != null)
                {
                    bo.ChildList.ChildChanged += ChildList_ChildChanged;

                    HookEvents(bo.Child);
                    bo.ChildList.ToList().ForEach(c => HookEvents(c));
                }
            }

            HookEvents(result);

            _SequenceID = 0;
            EventDetails.Clear();

            return(result);
        }
示例#6
0
        public void SingleList_Serialized()
        {
            IDataPortal <SingleList> listDataPortal = _testDIContext.CreateDataPortal <SingleList>();
            IDataPortal <SingleRoot> dataPortal     = _testDIContext.CreateDataPortal <SingleRoot>();

            int lc = 0;
            int cc = 0;

            Csla.Core.ChildChangedEventArgs cca = null;

            var root = listDataPortal.Fetch(false);

            root.Add(dataPortal.Fetch(true));
            root = root.Clone();

            System.ComponentModel.PropertyDescriptor lcp = null;
            root.ListChanged += (o, e) =>
            {
                lc++;
                lcp = e.PropertyDescriptor;
            };
            root.ChildChanged += (o, e) =>
            {
                cc++;
                cca = e;
            };
            root[0].Name = "abc";
            Assert.AreEqual(1, lc, "ListChanged should have fired once");
            Assert.IsNotNull(lcp, "PropertyDescriptor should be provided");
            Assert.AreEqual("Name", lcp.Name, "PropertyDescriptor.Name should be Name");
            Assert.AreEqual(1, cc, "ChildChanged should have fired");
            Assert.IsTrue(ReferenceEquals(root[0], cca.ChildObject), "Ref should be equal");
        }
示例#7
0
        public void FailFetchContext()
        {
            IDataPortal <ExceptionRoot> dataPortal = _testDIContext.CreateDataPortal <ExceptionRoot>();

            TestResults.Reinitialise();
            ExceptionRoot root = null;

            try
            {
                root = dataPortal.Fetch(new ExceptionRoot.Criteria("fail"));
                Assert.Fail("Exception didn't occur");
            }
            catch (DataPortalException ex)
            {
                Assert.IsNull(ex.BusinessObject, "Business object shouldn't be returned");
                Assert.AreEqual("Fail fetch", ex.GetBaseException().Message, "Base exception message incorrect");
                Assert.IsTrue(ex.Message.StartsWith("DataPortal.Fetch failed"), "Exception message incorrect");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected exception: " + ex.ToString());
            }

            Assert.AreEqual("create", TestResults.GetResult("create"), "GlobalContext not preserved");
        }
示例#8
0
        internal static Child GetChild(IDataPortal <Child> dataPortal, IDataReader dr)
        {
            Child obj;

            obj = dataPortal.Fetch(dr);
            return(obj);
        }
示例#9
0
#pragma warning disable CS0436 // Type conflicts with imported type
        public static LocationBusinessBase GetLocationBusinessBase(IDataPortal <LocationBusinessBase> dataPortal)
#pragma warning restore CS0436 // Type conflicts with imported type
        {
#pragma warning disable CS0436 // Type conflicts with imported type
            return(dataPortal.Fetch());

#pragma warning restore CS0436 // Type conflicts with imported type
        }
示例#10
0
        protected void Fetch([Inject] IDataPortal <LocationBusinessBase> dataPortal)
        {
            SetProperty(DataProperty, ApplicationContext.LogicalExecutionLocation.ToString());
#pragma warning disable CS0436 // Type conflicts with imported type
            var nested = dataPortal.Fetch(123);
#pragma warning restore CS0436 // Type conflicts with imported type
            NestedData = nested.Data;
        }
示例#11
0
        protected void DataPortal_Fetch([Inject] IDataPortal <Customer> customerDataPortal)
        {
            int maxCustomer = (new Random()).Next(3, 10);

            for (int i = 1; i < maxCustomer; i++)
            {
                Add(customerDataPortal.Fetch(i));
            }
        }
示例#12
0
        public void FetchCriteria()
        {
            IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>();

            var root = dataPortal.Fetch("abc");

            Assert.AreEqual("abc", root.Data, "Data should match");
            Assert.IsFalse(root.IsNew, "Should not be new");
            Assert.IsFalse(root.IsDirty, "Should not be dirty");
        }
示例#13
0
        public void ListOfLists()
        {
            IDataPortal <ListContainerList> listContainerDataPortal = _testDIContext.CreateDataPortal <ListContainerList>();
            IDataPortal <ContainsList>      listDataPortal          = _testDIContext.CreateDataPortal <ContainsList>();
            IDataPortal <SingleRoot>        dataPortal = _testDIContext.CreateDataPortal <SingleRoot>();

            bool rcc = false;
            bool ccc = false;
            bool cc  = false;

            Csla.Core.ChildChangedEventArgs cca = null;

            var root  = listContainerDataPortal.Fetch();
            var child = listDataPortal.Fetch(true);

            root.Add(child);
            child.List.Add(dataPortal.Fetch(true));
            root.ChildChanged += (o, e) =>
            {
                rcc = true;
            };
            System.ComponentModel.PropertyDescriptor lcp = null;
            root.ListChanged += (o, e) =>
            {
                Assert.Fail("root.ListChanged should not fire");
            };
            child.ChildChanged += (o, e) =>
            {
                ccc = true;
            };
            child.PropertyChanged += (o, e) =>
            {
                Assert.IsTrue(false, "child.PropertyChanged should not fire");
            };
            bool lc = false;

            child.List.ListChanged += (o, e) =>
            {
                lc  = true;
                lcp = e.PropertyDescriptor;
            };
            child.List.ChildChanged += (o, e) =>
            {
                cc  = true;
                cca = e;
            };
            child.List[0].Name = "abc";
            Assert.IsTrue(lc, "ListChanged should have fired");
            Assert.IsNotNull(lcp, "PropertyDescriptor should be provided");
            Assert.AreEqual("Name", lcp.Name, "PropertyDescriptor.Name should be Name");
            Assert.IsTrue(rcc, "root.ChildChanged should have fired");
            Assert.IsTrue(ccc, "child.ChildChanged should have fired");
            Assert.IsTrue(cc, "list.ChildChanged should have fired");
            Assert.IsTrue(ReferenceEquals(child.List[0], cca.ChildObject), "Ref should be equal");
        }
示例#14
0
        public void TestDpFetch()
        {
            IDataPortal <MultipleDataAccess> dataPortal = _testDIContext.CreateDataPortal <MultipleDataAccess>();

            TestResults.Reinitialise();

            var result = dataPortal.Fetch(1);

            Assert.AreEqual(1, result.Id);
            Assert.AreEqual("abc", result.Name);

            result = dataPortal.Fetch();
            Assert.AreEqual(int.MaxValue, result.Id);
            Assert.AreEqual(string.Empty, result.Name);

            result = dataPortal.Fetch(new List <int?>());
            Assert.AreEqual("Fetch(List<int?> values)", TestResults.GetResult("Method"));

            result = dataPortal.Fetch(new List <DateTime?>());
            Assert.AreEqual("Fetch(List<DateTime?> values)", TestResults.GetResult("Method"));
        }
示例#15
0
        public void SimpleTest()
        {
            IDataPortal <SimpleRoot> dataPortal = _testDIContext.CreateDataPortal <SimpleRoot>();

            // TODO: How do we do this test in Csla 6?
            TestResults.Reinitialise();
            //ApplicationContext.ClientContext["v1"] = "client";

            SimpleRoot root = dataPortal.Fetch(new SimpleRoot.Criteria("data"));

            //Assert.AreEqual("client", ApplicationContext.ClientContext["v1"], "client context didn't roundtrip");
            Assert.AreEqual("Fetched", TestResults.GetResult("Root"), "global context missing server value");
        }
示例#16
0
        public void MultipleMetaRules()
        {
            IDataPortal <MultipleMeta> dataPortal = _testDIContext.CreateDataPortal <MultipleMeta>();

            var obj = dataPortal.Fetch();

            var typeRules = obj.GetRegisteredRules();

            // 4 rules from metadatacalss and 1 rule from autogenerated class.
            Assert.AreEqual(5, typeRules.Rules.Count);
            Assert.AreEqual(3, typeRules.Rules.Where(p => p.PrimaryProperty == MultipleMeta.AmountProperty).Count());
            Assert.AreEqual(2, typeRules.Rules.Where(p => p.PrimaryProperty == MultipleMeta.QuantityProperty).Count());
        }
示例#17
0
        public void TestDpFetchNullable()
        {
            IDataPortal <MultipleDataAccess> dataPortal = _testDIContext.CreateDataPortal <MultipleDataAccess>();

            try
            {
                var result = dataPortal.Fetch(1, default(bool?));
            }
            catch (DataPortalException ex)
            {
                throw ex.GetBaseException();
            }
        }
示例#18
0
        public void FetchLoadProperty()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(
                options => options.DataPortal(
                    dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactory3> >()))
                );
            IDataPortal <Root> dataPortal = testDIContext.CreateDataPortal <Root>();

            var root = dataPortal.Fetch();

            Assert.AreEqual("Fetch", root.Data, "Data should match");
            Assert.IsFalse(root.IsNew, "Should not be new");
            Assert.IsFalse(root.IsDirty, "Should not be dirty");
        }
示例#19
0
        public void Update()
        {
            IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>();

            var root = dataPortal.Fetch();

            root.Data = "abc";

            root = dataPortal.Update(root);
            Assert.AreEqual(TransactionalTypes.Manual, root.TransactionalType, "Transactional type should match");
            Assert.AreEqual("Update", root.Data, "Data should match");
            Assert.IsFalse(root.IsNew, "Should not be new");
            Assert.IsFalse(root.IsDirty, "Should not be dirty");
        }
示例#20
0
        public void FactoryIsBusyFails()
        {
            IDataPortal <FactoryBusy> dataPortal = _testDIContext.CreateDataPortal <FactoryBusy>();

            try
            {
                var obj = dataPortal.Fetch();
            }
            catch (DataPortalException ex)
            {
                Assert.IsInstanceOfType(ex.InnerException, typeof(InvalidOperationException));
                return;
            }
            Assert.Fail("Expected exception");
        }
示例#21
0
        public void ObjectNotDirtyWhenOutputValueDoNotChangePropertyValue()
        {
            IDataPortal <DirtyAfterOutValueChangesProperty> dataPortal = _testDIContext.CreateDataPortal <DirtyAfterOutValueChangesProperty>();

            var context = GetContext();

            var root = dataPortal.Fetch("CSLA ROCKS");

            context.Assert.IsFalse(root.IsDirty);
            context.Assert.AreEqual("CSLA ROCKS", root.Value1);
            root.CheckRules();
            context.Assert.IsFalse(root.IsDirty);
            context.Assert.AreEqual("CSLA ROCKS", root.Value1);
            context.Assert.Success();
            context.Complete();
        }
示例#22
0
        private void Fetch([Inject] DisposableClass disposable, [Inject] IDataPortal <ClassB> classBDataPortal)
        {
            DisposableClass = disposable;

            if (disposable.IsDisposed)
            {
                throw new ObjectDisposedException(nameof(disposable));
            }

            ChildB = classBDataPortal.Fetch();

            if (disposable.IsDisposed)
            {
                throw new ObjectDisposedException(nameof(disposable));
            }
        }
示例#23
0
        public void FetchLoadProperty()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateDefaultContext();
            // TODO: Not sure how to have a generic factory loader now an ApplicationContext is required on the class :-(
            //TestDIContext testDIContext = TestDIContextFactory.CreateContext(
            //  options => options.DataPortal(
            //    dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterObjectFactoryLoader<ObjectFactoryLoader<RootFactory3>>()))
            //  );
            IDataPortal <Root> dataPortal = testDIContext.CreateDataPortal <Root>();

            var root = dataPortal.Fetch();

            Assert.AreEqual("Fetch", root.Data, "Data should match");
            Assert.IsFalse(root.IsNew, "Should not be new");
            Assert.IsFalse(root.IsDirty, "Should not be dirty");
        }
示例#24
0
        public void Test_Scope_DoesNotDispose()
        {
            // CSLA should not dispose of the default service provider.
            IServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped <DisposableClass>();
            serviceCollection.AddCsla();

            var services = serviceCollection.BuildServiceProvider();
            IDataPortal <ClassA> dataPortal = services.GetRequiredService <IDataPortal <ClassA> >();

            var classA = dataPortal.Fetch();
            var classB = classA.ChildB;

            Assert.AreEqual(classA.DisposableClass.Id, classB.DisposableClass.Id, "Ids must be the same");
            Assert.IsFalse(classA.DisposableClass.IsDisposed, "Object must not be disposed");
        }
示例#25
0
        public void TestNameValueList()
        {
            IDataPortal <NameValueListObj> dataPortal = _testDIContext.CreateDataPortal <NameValueListObj>();

            NameValueListObj nvList = dataPortal.Fetch();

            Assert.AreEqual("Fetched", TestResults.GetResult("NameValueListObj"));

            Assert.AreEqual("element_1", nvList[1].Value);

            //won't work, because IsReadOnly is set to true after object is populated in the for
            //loop in DataPortal_Fetch
            //NameValueListObj.NameValuePair newPair = new NameValueListObj.NameValuePair(45, "something");

            //nvList.Add(newPair);

            //Assert.AreEqual("something", nvList[45].Value);
        }
示例#26
0
        public void TestBypassWriteNoRightsDoNotBypassBackingField()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <BypassBusinessBase> dataPortal = testDIContext.CreateDataPortal <BypassBusinessBase>();

            UnitTestContext    context = GetContext();
            BypassBusinessBase testObj = dataPortal.Fetch();
            bool propertyChangedFired  = false;

            testObj.PropertyChanged += (o, e) =>
            {
                propertyChangedFired = true;
            };
            testObj.LoadId4(1);
            context.Assert.AreEqual(true, testObj.IsDirty);
            context.Assert.AreEqual(1, testObj.ReadId4ByPass());
            context.Assert.AreEqual(true, propertyChangedFired);
            context.Assert.Success();
            context.Complete();
        }
示例#27
0
        public void UpdateTransactionScope()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(
                opts => opts.DataPortal(dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactory1> >()))
                );
            IDataPortal <Root> dataPortal = testDIContext.CreateDataPortal <Root>();

            var root = dataPortal.Fetch();

            root.Data = "abc";

            root = dataPortal.Update(root);
            Assert.AreEqual(TransactionalTypes.TransactionScope, root.TransactionalType, "Transactional type should match");
            Assert.AreEqual("Serializable", root.IsolationLevel, "Transactional isolation should match");
            Assert.AreEqual(30, root.TransactionTimeout, "Transactional timeout should match");

            Assert.AreEqual("Update", root.Data, "Data should match");
            Assert.IsFalse(root.IsNew, "Should not be new");
            Assert.IsFalse(root.IsDirty, "Should not be dirty");
        }
示例#28
0
        public void SingleChild()
        {
            IDataPortal <SingleChild> dataPortal = _testDIContext.CreateDataPortal <SingleChild>();

            bool pc = false;
            bool cc = false;

            var root = dataPortal.Fetch(false);

            root.PropertyChanged += (o, e) =>
            {
                pc = true;
            };
            root.ChildChanged += (o, e) =>
            {
                cc = true;
            };
            root.Child.Name = "abc";
            Assert.IsFalse(pc, "PropertyChanged should not have fired");
            Assert.IsTrue(cc, "ChildChanged should have fired");
        }
示例#29
0
        public void DataPortalEvents()
        {
            IDataPortal <Basic.Root> dataPortal = _testDIContext.CreateDataPortal <Basic.Root>();

            TestResults.Reinitialise();
            TestResults.Add("global", "global");

            //dataPortal.DataPortalInvoke += new Action<DataPortalEventArgs>(OnDataPortaInvoke);
            //dataPortal.DataPortalInvokeComplete += new Action<DataPortalEventArgs>(OnDataPortalInvokeComplete);

            Basic.Root root = dataPortal.Fetch(new Basic.Root.Criteria("testing"));

            //dataPortal.DataPortalInvoke -= new Action<DataPortalEventArgs>(OnDataPortaInvoke);
            //dataPortal.DataPortalInvokeComplete -= new Action<DataPortalEventArgs>(OnDataPortalInvokeComplete);

            //Populated in the handlers below
            Assert.AreEqual("global", TestResults.GetResult("ClientInvoke"), "Client invoke incorrect");
            Assert.AreEqual("global", TestResults.GetResult("ClientInvokeComplete"), "Client invoke complete");

            //populated in the Root Dataportal handlers.
            Assert.AreEqual("global", TestResults.GetResult("dpinvoke"), "Server invoke incorrect");
            Assert.AreEqual("global", TestResults.GetResult("dpinvokecomplete"), "Server invoke compelte incorrect");
        }
示例#30
0
        public void GrandChild()
        {
            IDataPortal <Grandchild> dataPortal = _testDIContext.CreateDataPortal <Grandchild>();

            bool pc  = false;
            bool cc  = false;
            bool cpc = false;
            bool ccc = false;

            Csla.Core.ChildChangedEventArgs cca = null;

            var root = dataPortal.Fetch();

            root.PropertyChanged += (o, e) =>
            {
                pc = true;
            };
            root.ChildChanged += (o, e) =>
            {
                cc = true;
            };
            root.Child.PropertyChanged += (o, e) =>
            {
                cpc = true;
            };
            root.Child.ChildChanged += (o, e) =>
            {
                ccc = true;
                cca = e;
            };
            root.Child.Child.Name = "abc";
            Assert.IsFalse(cpc, "C PropertyChanged should not have fired");
            Assert.IsTrue(ccc, "C ChildChanged should have fired");
            Assert.IsFalse(pc, "PropertyChanged should not have fired");
            Assert.IsTrue(cc, "ChildChanged should have fired");
            Assert.IsTrue(ReferenceEquals(root.Child.Child, cca.ChildObject), "Ref should be equal");
        }