예제 #1
0
        public void ListTestSaveWhileBusyNetOnly()
        {
            IDataPortal <ItemWithAsynchRuleList> dataPortal = _noCloneOnUpdateDIContext.CreateDataPortal <ItemWithAsynchRuleList>();

            TestResults.Reinitialise();

            UnitTestContext        context = GetContext();
            ItemWithAsynchRuleList items   = ItemWithAsynchRuleList.GetListWithItems(dataPortal);

            items[0].RuleField = "some value";
            context.Assert.IsTrue(items.IsBusy);
            context.Assert.IsFalse(items.IsSavable);
            bool gotError = false;

            try
            {
                items.Save();
            }
            catch (InvalidOperationException)
            {
                gotError = true;
            }
            context.Assert.IsTrue(gotError);
            context.Assert.Success();

            context.Complete();
        }
예제 #2
0
        public void NestedAddDeleteAcceptChild()
        {
            IDataPortal <Child> childDataPortal = _testDIContext.CreateDataPortal <Child>();

            TestResults.Reinitialise();
            Root root = NewRoot();

            root.BeginEdit();
            root.Children.Add(childDataPortal, "A");
            root.BeginEdit();
            root.Children.Add(childDataPortal, "B");
            root.BeginEdit();
            root.Children.Add(childDataPortal, "C");
            Child childC = root.Children[2];

            Assert.AreEqual(true, root.Children.Contains(childC), "Child should be in collection");
            root.Children.Remove(root.Children[0]);
            root.Children.Remove(root.Children[0]);
            root.Children.Remove(root.Children[0]);
            Assert.AreEqual(false, root.Children.Contains(childC), "Child should not be in collection");
            Assert.AreEqual(true, root.Children.ContainsDeleted(childC), "Deleted child should be in deleted collection");
            root.ApplyEdit();
            Assert.AreEqual(false, root.Children.ContainsDeleted(childC), "Deleted child should not be in deleted collection after first applyedit");
            root.ApplyEdit();
            Assert.AreEqual(false, root.Children.ContainsDeleted(childC), "Deleted child should not be in deleted collection after ApplyEdit");
            root.ApplyEdit();
            Assert.AreEqual(0, root.Children.Count, "No children should remain");
            Assert.AreEqual(false, root.Children.ContainsDeleted(childC), "Deleted child should not be in deleted collection after third applyedit");
        }
예제 #3
0
        public void DeletedListTestWithCancel()
        {
            IDataPortal <Child> childDataPortal = _testDIContext.CreateDataPortal <Child>();

            TestResults.Reinitialise();
            Root root = NewRoot();

            root.Children.Add(childDataPortal, "1");
            root.Children.Add(childDataPortal, "2");
            root.Children.Add(childDataPortal, "3");
            root.BeginEdit();
            root.Children.Remove(root.Children[0]);
            root.Children.Remove(root.Children[0]);

            Root copy = root.Clone();

            List <Child> deleted = (List <Child>)(root.Children.GetType().GetProperty("DeletedList", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.IgnoreCase).GetValue(copy.Children, null));

            Assert.AreEqual(2, deleted.Count);
            Assert.AreEqual("1", deleted[0].Data);
            Assert.AreEqual("2", deleted[1].Data);
            Assert.AreEqual(1, root.Children.Count);

            root.CancelEdit();

            deleted = (List <Child>)(root.Children.GetType().GetProperty("DeletedList", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.IgnoreCase).GetValue(root.Children, null));

            Assert.AreEqual(0, deleted.Count);
            Assert.AreEqual(3, root.Children.Count);
        }
예제 #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();
        }
        public async Task <JsonResult> SignUpUser(OAuth2UserIdentity userIdentity)
        {
            ServiceResponse response = default(ServiceResponse);

            using (Session session = ApplicationModel.Current.CreateSession(new SecurityToken(this.HttpContext.Request.Url.Host, this.HttpContext.User.Identity.Name)))
            {
                try
                {
                    IDataPortal        portal = DependencyInjection.Get <IDataPortal>();
                    OAuth2UserIdentity value  = portal.SignUpUser(userIdentity);

                    // Set the status on HTTP and response level.
                    if (value == null)
                    {
                        HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    }
                    ResponseStatus status = value == null ? ResponseStatus.NO_DATA : ResponseStatus.OK;

                    response = new ServiceDataResponse(RestVersion0100Controller.API_VERSION, status, value);
                }
                catch (Exception ex)
                {
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    response = new ServiceErrorResponse(RestVersion0100Controller.API_VERSION, ResponseStatus.ERROR, new ServiceError(ex));
                }
            }

            return(this.Json(response));
        }
예제 #6
0
        public void TestWithoutSerializableHandler()
        {
            IDataPortal <SerializationRoot> dataPortal = _testDIContext.CreateDataPortal <SerializationRoot>();

            TestResults.Reinitialise();
            UnitTestContext             context = GetContext();
            SerializationRoot           root    = SerializationRoot.NewSerializationRoot(dataPortal);
            nonSerializableEventHandler handler = new nonSerializableEventHandler();

            handler.Reg(root);
            root.Data = "something";
            context.Assert.AreEqual("1", TestResults.GetResult("PropertyChangedFiredCount"));
            root.Data = "something else";
            context.Assert.AreEqual("2", TestResults.GetResult("PropertyChangedFiredCount"));

            //serialize an object with eventhandling objects that are nonserializable
            root      = root.Clone();
            root.Data = "something new";

            //still at 2 even though we changed the property again
            //when the clone method performs serialization, the nonserializable
            //object containing an event handler for the propertyChanged event
            //is lost
            context.Assert.AreEqual("2", TestResults.GetResult("PropertyChangedFiredCount"));
            context.Assert.Success();
        }
예제 #7
0
        public void Initialize_InvalidGrandChildObject_ExceptionRaised()
        {
            // Arrange
            IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>();
            Root  rootObject  = dataPortal.Create(new Root.Criteria("Test Data"));
            Child childObject = rootObject.Children.AddNew();

            childObject.Data = "Test child data";
            GrandChild              grandChildObject   = childObject.GrandChildren.AddNew();
            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 and Assert
            Assert.ThrowsException <Rules.ValidationException>(() => sut.Initialize(args));
        }
예제 #8
0
        public void NoFail()
        {
            IDataPortal <RollbackRoot> dataPortal = _testDIContext.CreateDataPortal <RollbackRoot>();

            TestResults.Reinitialise();
            RollbackRoot root = Csla.Test.RollBack.RollbackRoot.NewRoot(dataPortal);

            root.BeginEdit();
            root.Data = "saved";
            Assert.AreEqual("saved", root.Data, "data is 'saved'");
            Assert.AreEqual(false, root.Fail, "fail is false");
            Assert.AreEqual(true, root.IsDirty, "isdirty is true");
            Assert.AreEqual(true, root.IsValid, "isvalid is true");
            Assert.AreEqual(true, root.IsNew, "isnew is true");

            TestResults.Reinitialise();
            RollbackRoot tmp = (RollbackRoot)(root.Clone());

            root.ApplyEdit();
            root = root.Save();

            Assert.IsNotNull(root, "obj is not null");
            Assert.AreEqual("Inserted", TestResults.GetResult("Root"), "obj was inserted");
            Assert.AreEqual("saved", root.Data, "data is 'saved'");
            Assert.AreEqual(false, root.IsNew, "is new is false");
            Assert.AreEqual(false, root.IsDeleted, "isdeleted is false");
            Assert.AreEqual(false, root.IsDirty, "isdirty is false");
        }
예제 #9
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");
        }
예제 #10
0
 public PersonEditPage(ViewModel <PersonEdit> vm, IDataPortal <PersonEdit> portal)
 {
     ViewModel = vm;
     _portal   = portal;
     MainWindow.Instance.SetPageTitle("Edit person");
     InitializeComponent();
 }
예제 #11
0
        public void EditParentEntity()
        {
            IDataPortal <DataBinding.ParentEntity> dataPortal = _testDIContext.CreateDataPortal <DataBinding.ParentEntity>();

            Csla.Test.DataBinding.ParentEntity p = Csla.Test.DataBinding.ParentEntity.NewParentEntity(dataPortal);
            p.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(p_PropertyChanged);

            p.BeginEdit();
            p.Data = "something";
            p.BeginEdit();
            p.CancelEdit();
            p.CancelEdit();

            Assert.AreEqual(string.Empty, p.Data);

            p.BeginEdit();
            p.BeginEdit();
            p.Data = "data";
            p.ApplyEdit();
            p.CancelEdit();

            Assert.AreEqual(string.Empty, p.Data);

            p.Data = "data";
            p.BeginEdit();
            p.Data += " more data";
            p.ApplyEdit();
            p.CancelEdit();

            Assert.AreEqual("data more data", p.Data);
        }
        public void Blb2Loc_RemoveOriginal()
        {
            IDataPortal <TestList> dataPortal = _testDIContext.CreateDataPortal <TestList>();

            // TODO: I don't understand why some types need a public constructor and others don't?
            var source = dataPortal.Create();
            var query  = from r in source
                         where r.Id > 100
                         select r;
            var synced = source.ToSyncList(query);
            int count  = 0;

            foreach (var item in synced)
            {
                count++;
            }
            Assert.AreEqual(3, count, "Calculated count wrong (br)");
            Assert.AreEqual(3, synced.Count, "Synced count wrong (br)");
            Assert.AreEqual(4, source.Count, "source count wrong (br)");
            Assert.AreEqual(0, synced.Where(_ => _.Id == 12).Count(), "synced contains 12");

            source.RemoveAt(3);

            count = 0;
            foreach (var item in synced)
            {
                count++;
            }

            Assert.AreEqual(3, count, "Calculated count wrong");
            Assert.AreEqual(3, synced.Count, "Synced count wrong");
            Assert.AreEqual(3, source.Count, "source count wrong");
            Assert.AreEqual(0, synced.Where(_ => _.Id == 12).Count(), "synced contains 12");
        }
예제 #13
0
        public async Task TestSaveWhileBusy()
        {
            IDataPortal <ItemWithAsynchRule> dataPortal = _testDIContext.CreateDataPortal <ItemWithAsynchRule>();

            TestResults.Reinitialise();

            UnitTestContext context = GetContext();
            var             item    = await dataPortal.FetchAsync("an id");

            item.RuleField = "some value";
            context.Assert.IsTrue(item.IsBusy);
            context.Assert.IsFalse(item.IsSavable);

            try
            {
                await item.SaveAsync();
            }
            catch (Exception ex)
            {
                var error = ex as InvalidOperationException;
                context.Assert.IsNotNull(error);
                context.Assert.IsTrue(error.Message.ToLower().Contains("busy"));
                context.Assert.IsTrue(error.Message.ToLower().Contains("save"));
                context.Assert.Success();
            }
            context.Complete();
        }
예제 #14
0
        public void ListTestSaveWhileNotBusyNetOnly()
        {
            IDataPortal <ItemWithAsynchRuleList> dataPortal = _noCloneOnUpdateDIContext.CreateDataPortal <ItemWithAsynchRuleList>();

            TestResults.Reinitialise();

            UnitTestContext        context = GetContext();
            ItemWithAsynchRuleList items   = ItemWithAsynchRuleList.GetListWithItems(dataPortal);



            items[0].ValidationComplete += (o2, e2) =>
            {
                context.Assert.IsFalse(items.IsBusy);
                context.Assert.IsTrue(items.IsSavable);
                items = items.Save();
                context.Assert.AreEqual("DataPortal_Update", items[0].OperationResult);
                context.Assert.Success();
            };

            items[0].RuleField = "some value";
            context.Assert.IsTrue(items.IsBusy);
            context.Assert.IsFalse(items.IsSavable);

            context.Complete();
        }
예제 #15
0
        public void TestNullableAfterEditCycle()
        {
            IDataPortal <NullableObject> dataPortal = _testDIContext.CreateDataPortal <NullableObject>();

            TestResults.Reinitialise();
            NullableObject nullRoot = NullableObject.NewNullableObject(dataPortal);

            nullRoot.NullableInteger    = null;
            nullRoot._nullableIntMember = null;

            nullRoot.BeginEdit();
            nullRoot.NullableInteger    = 45;
            nullRoot._nullableIntMember = 32;
            nullRoot.ApplyEdit();

            Assert.AreEqual(45, nullRoot.NullableInteger);
            Assert.AreEqual(32, nullRoot._nullableIntMember);

            nullRoot.BeginEdit();
            nullRoot.NullableInteger    = null;
            nullRoot._nullableIntMember = null;
            nullRoot.ApplyEdit();

            Assert.AreEqual(null, nullRoot.NullableInteger);
            Assert.AreEqual(null, nullRoot._nullableIntMember);

            nullRoot.BeginEdit();
            nullRoot.NullableInteger    = 444;
            nullRoot._nullableIntMember = 222;
            nullRoot.CancelEdit();

            Assert.AreEqual(null, nullRoot.NullableInteger);
            Assert.AreEqual(null, nullRoot._nullableIntMember);
        }
예제 #16
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");
        }
예제 #17
0
        public void SerializeCommand()
        {
            IDataPortal <TestCommand> dataPortal         = _testDIContext.CreateDataPortal <TestCommand>();
            ApplicationContext        applicationContext = _testDIContext.CreateTestApplicationContext();

            var cmd = dataPortal.Create();

            cmd.Name = "test data";

            // TODO: Not sure how to replicate the object cloner in Csla 6
            var buffer = new MemoryStream();

            //  var bf = (TestCommand)Csla.Core.ObjectCloner.Clone(cmd);
            //  Assert.AreEqual(cmd.Name, bf.Name, "after BinaryFormatter");

            //  var ndcs = new System.Runtime.Serialization.NetDataContractSerializer();
            //  ndcs.Serialize(buffer, cmd);
            //  buffer.Position = 0;
            //  var n = (TestCommand)ndcs.Deserialize(buffer);
            //  Assert.AreEqual(cmd.Name, n.Name, "after NDCS");

            buffer = new MemoryStream();
            var mf = new MobileFormatter(applicationContext);

            mf.Serialize(buffer, cmd);
            buffer.Position = 0;
            var m = (TestCommand)mf.Deserialize(buffer);

            Assert.AreEqual(cmd.Name, m.Name, "after MobileFormatter");
        }
예제 #18
0
        public void CheckInnerExceptionsOnDelete()
        {
            IDataPortal <DataPortal.TransactionalRoot> dataPortal = _testDIContext.CreateDataPortal <DataPortal.TransactionalRoot>();

            TestResults.Reinitialise();

            string baseException           = string.Empty;
            string baseInnerException      = string.Empty;
            string baseInnerInnerException = string.Empty;

            try
            {
                //this will throw an exception
                Csla.Test.DataPortal.TransactionalRoot.DeleteTransactionalRoot(13, dataPortal);
            }
            catch (Csla.DataPortalException ex)
            {
                baseException           = ex.Message;
                baseInnerException      = ex.InnerException.Message;
                baseInnerInnerException = ex.InnerException.InnerException.Message;
            }

            Assert.IsTrue(baseException.StartsWith("DataPortal.Delete failed"), "Should start with 'DataPortal.Delete failed'");
            Assert.IsTrue(baseException.Contains("DataPortal_Delete: you chose an unlucky number"));
            Assert.AreEqual("TransactionalRoot.DataPortal_Delete method call failed", baseInnerException);
            Assert.AreEqual("DataPortal_Delete: you chose an unlucky number", baseInnerInnerException);

            //verify that the implemented method, DataPortal_OnDataPortal
            //was called for the business object that threw the exception
            Assert.AreEqual("Called", TestResults.GetResult("OnDataPortalException"));
        }
예제 #19
0
        public void UpdateTransactionScopeUsingDefaultTransactionLevelAndTimeout()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(
                options => options
                .Data(
                    cfg => cfg
                    .DefaultTransactionIsolationLevel(TransactionIsolationLevel.RepeatableRead)
                    .DefaultTransactionTimeoutInSeconds(45)
                    )
                .DataPortal(
                    dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactory5> >()))
                );
            IDataPortal <Root> dataPortal = testDIContext.CreateDataPortal <Root>();

            var root = dataPortal.Create();

            root.Data = "abc";


            root = dataPortal.Update(root);
            Assert.AreEqual(TransactionalTypes.TransactionScope, root.TransactionalType, "Transactional type should match");
            Assert.AreEqual("RepeatableRead", root.IsolationLevel, "Transactional isolation should match");
            Assert.AreEqual(45, 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");
        }
예제 #20
0
        public void TestAsyncRulesAndSyncRulesValid()
        {
            IDataPortal <AsyncRuleRoot> dataPortal = _testDIContext.CreateDataPortal <AsyncRuleRoot>();

            UnitTestContext context = GetContext();

            var har = dataPortal.Create();

            context.Assert.IsTrue(string.IsNullOrEmpty(har.CustomerNumber));
            context.Assert.IsTrue(string.IsNullOrEmpty(har.CustomerName));
            context.Assert.IsFalse(har.IsValid, "IsValid 1");


            har.ValidationComplete += (o, e) =>
            {
                context.Assert.IsFalse(string.IsNullOrEmpty(har.CustomerNumber));
                context.Assert.IsFalse(string.IsNullOrEmpty(har.CustomerName));

                context.Assert.IsTrue(har.IsValid, "IsValid 2");
                context.Assert.Success();
            };
            har.CustomerNumber = "123456";

            context.Complete();
        }
예제 #21
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);
        }
예제 #22
0
        public void ClientContext()
        {
            IDataPortal <Basic.Root> dataPortal         = _testDIContext.CreateDataPortal <Basic.Root>();
            ApplicationContext       applicationContext = _testDIContext.CreateTestApplicationContext();

            TestResults.Reinitialise();

            applicationContext.ClientContext.Add("clientcontext", "client context data");
            Assert.AreEqual("client context data", applicationContext.ClientContext["clientcontext"], "Matching data not retrieved");

            Basic.Root root = dataPortal.Create(new Basic.Root.Criteria());
            root.Data = "saved";
            Assert.AreEqual("saved", root.Data, "Root data should be 'saved'");
            Assert.AreEqual(true, root.IsDirty, "Object should be dirty");
            Assert.AreEqual(true, root.IsValid, "Object should be valid");

            TestResults.Reinitialise();
            root = root.Save();

            Assert.IsNotNull(root, "Root object should not be null");
            Assert.AreEqual("Inserted", TestResults.GetResult("Root"), "Object not inserted");
            Assert.AreEqual("saved", root.Data, "Root data should be 'saved'");
            Assert.AreEqual(false, root.IsNew, "Object should not be new");
            Assert.AreEqual(false, root.IsDeleted, "Object should not be deleted");
            Assert.AreEqual(false, root.IsDirty, "Object should not be dirty");

            //TODO: Is there a modern equivalent of this?
            //Assert.AreEqual("client context data", Csla.ApplicationContext.ClientContext["clientcontext"], "Client context data lost");
            Assert.AreEqual("client context data", TestResults.GetResult("clientcontext"), "Global context data lost");
            Assert.AreEqual("new global value", TestResults.GetResult("globalcontext"), "New global value lost");
        }
예제 #23
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");
        }
예제 #24
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");
        }
예제 #25
0
파일: SplitTest.cs 프로젝트: gnilesh4/csla
        public void TestDpDelete()
        {
            IDataPortal <Split> dataPortal = _testDIContext.CreateDataPortal <Split>();

            Split.DeleteObject(5, dataPortal);
            Assert.AreEqual("Deleted", TestResults.GetResult("Split"));
        }
예제 #26
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");
        }
예제 #27
0
        public void ChildEquality()
        {
            IDataPortal <Child> childDataPortal = _testDIContext.CreateDataPortal <Child>();

            TestResults.Reinitialise();
            Root root = NewRoot();

            root.Children.Add(childDataPortal, "abc");
            root.Children.Add(childDataPortal, "xyz");
            root.Children.Add(childDataPortal, "123");
            Child c1 = root.Children[0];
            Child c2 = root.Children[1];
            Child c3 = root.Children[2];

            root.Children.Remove(c3);

            Assert.AreEqual(true, c1.Equals(c1), "objects should be equal");
            Assert.AreEqual(true, Equals(c1, c1), "objects should be equal");

            Assert.AreEqual(false, c1.Equals(c2), "objects should not be equal");
            Assert.AreEqual(false, Equals(c1, c2), "objects should not be equal");

            Assert.AreEqual(false, c1.Equals(null), "objects should not be equal");
            Assert.AreEqual(false, Equals(c1, null), "objects should not be equal");
            Assert.AreEqual(false, Equals(null, c2), "objects should not be equal");

            Assert.AreEqual(true, root.Children.Contains(c1), "Collection should contain c1");
            Assert.AreEqual(true, root.Children.Contains(c2), "collection should contain c2");
            Assert.AreEqual(false, root.Children.Contains(c3), "collection should not contain c3");
            Assert.AreEqual(true, root.Children.ContainsDeleted(c3), "Deleted collection should contain c3");
        }
예제 #28
0
        public async Task CleanupWhenAddBusinessRulesThrowsException()
        {
            IDataPortal <RootThrowsException> dataPortal = _testDIContext.CreateDataPortal <RootThrowsException>();

            RootThrowsException.Counter = 0;

            // AddBusinessRules throw an ArgumentException
            // In .NET the exception will occur serverside and returned i DatPortalEventArgs
            try
            {
                await dataPortal.CreateAsync();
            }
            catch (DataPortalException ex)
            {
                Assert.IsTrue(ex.InnerException is ArgumentException);
            }

            // should fail again as type rules should be cleaned up
            // AddBusinessRules throw an ArgumentException
            try
            {
                await dataPortal.CreateAsync();
            }
            catch (DataPortalException ex)
            {
                Assert.IsTrue(ex.InnerException is ArgumentException);
            }
        }
예제 #29
0
        internal static Child GetChild(IDataPortal <Child> dataPortal, IDataReader dr)
        {
            Child obj;

            obj = dataPortal.Fetch(dr);
            return(obj);
        }
예제 #30
0
        public async Task ListTestSaveWhileBusy()
        {
            IDataPortal <ItemWithAsynchRuleList> dataPortal = _noCloneOnUpdateDIContext.CreateDataPortal <ItemWithAsynchRuleList>();

            TestResults.Reinitialise();

            UnitTestContext        context = GetContext();
            ItemWithAsynchRuleList items   = ItemWithAsynchRuleList.GetListWithItems(dataPortal);

            items[0].RuleField = "some value";
            context.Assert.IsTrue(items.IsBusy);
            context.Assert.IsFalse(items.IsSavable);

            try
            {
                await items.SaveAsync();
            }
            catch (Exception ex)
            {
                var error = ex as InvalidOperationException;
                context.Assert.IsNotNull(error);
                context.Assert.IsTrue(error.Message.ToLower().Contains("busy"));
                context.Assert.IsTrue(error.Message.ToLower().Contains("save"));
                context.Assert.Success();
            }
            context.Complete();
        }