Exemplo n.º 1
0
        public void Blb2Loc_Remove()
        {
            IDataPortal <TestList> dataPortal = _testDIContext.CreateDataPortal <TestList>();

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

            var oldItem = synced[0];

            synced.RemoveAt(0);

            Assert.AreEqual(2, synced.Count, "synced count wrong");
            Assert.AreEqual(3, source.Count, "source count wrong");
            Assert.IsFalse(synced.Contains(oldItem), "synced should not contain item");
            Assert.IsFalse(source.Contains(oldItem), "source should not contain item");
        }
Exemplo n.º 2
0
        public void BusinessRules_MustNotCascade_WhenCanRunAsAffectedIsFalse()
        {
            IDataPortal <CascadeRoot> dataPortal = _testDIContext.CreateDataPortal <CascadeRoot>();

            var root = dataPortal.Create();

            root.CascadeOnDirtyProperties = true;
            Assert.AreEqual(0, root.Num1);
            Assert.AreEqual(0, root.Num2);
            Assert.AreEqual(0, root.Num3);
            Assert.AreEqual(0, root.Num4);
            Assert.AreEqual(0, root.Num5);
            root.Num1 = 1;
            Assert.AreEqual(1, root.Num1); // the value set by test
            Assert.AreEqual(2, root.Num2); // Num2 is set from Num1 rules
            Assert.AreEqual(3, root.Num3); // Num3 is set from Num2 rules
            Assert.AreEqual(4, root.Num4); // Num4 is set from Num3 rules when Cascade propagates down to Num3
            Assert.AreEqual(0, root.Num5); // Rule on Num4 is not allowed to run as AffectedProperty som Num5 must be unchanged.
        }
Exemplo n.º 3
0
        public void ExecuteCommandWithIntercept()
        {
            IDataPortal <InterceptorCommand> dataPortal = _testDIContext.CreateDataPortal <InterceptorCommand>();

            TestResults.Reinitialise();

            var obj = dataPortal.Create();

            TestResults.Reinitialise();
            obj = dataPortal.Execute(obj);

            Assert.AreEqual("Execute", TestResults.GetResult("InterceptorCommand"), "Execute should have run");
            Assert.AreEqual("Initialize", TestResults.GetResult("Intercept1+InterceptorCommand"), "Initialize should have run");
            Assert.AreEqual("Execute", TestResults.GetResult("InterceptOp1+InterceptorCommand"), "Initialize op should be Execute");
            Assert.AreEqual("Complete", TestResults.GetResult("Intercept2+InterceptorCommand"), "Complete should have run");
            Assert.AreEqual("Execute", TestResults.GetResult("InterceptOp2+InterceptorCommand"), "Complete op should be Execute");
            Assert.IsFalse(TestResults.ContainsResult("Activate1+InterceptorCommand"), "CreateInstance should not have run");
            Assert.AreEqual("InitializeInstance", TestResults.GetResult("Activate2+InterceptorCommand"), "InitializeInstance should have run");
        }
Exemplo n.º 4
0
        public void HigherThreshold()
        {
            IDataPortal <ShortCircuit> dataPortal = _testDIContext.CreateDataPortal <ShortCircuit>();

            ShortCircuit root = dataPortal.Create();

            root.CheckRules();
            Assert.AreEqual(1, root.BrokenRulesCollection.ErrorCount, "Only one rule should be broken");
            Assert.AreEqual("Test required", root.BrokenRulesCollection.GetFirstBrokenRule("Test").Description, "'Test required' should be broken");

            root.Threshold = 100;
            root.CheckRules();
            Assert.AreEqual(2, root.BrokenRulesCollection.ErrorCount, "Two rules should be broken after checkrules");
            root.Test = "some data";
            Assert.AreEqual(1, root.BrokenRulesCollection.ErrorCount, "One rule should be broken with data");
            Assert.AreEqual("Always error", root.BrokenRulesCollection.GetFirstBrokenRule("Test").Description, "'Always fails' should be broken");
            root.Test = "";
            Assert.AreEqual(2, root.BrokenRulesCollection.ErrorCount, "Two rules should be broken when empty");
        }
Exemplo n.º 5
0
        public void TestAuthExecute()
        {
            IDataPortal <PermissionsRoot> dataPortal = _adminDIContext.CreateDataPortal <PermissionsRoot>();

            TestResults.Reinitialise();

            PermissionsRoot pr = dataPortal.Create();

            //should work, because we are now logged in as an admin
            pr.DoWork();

            Assert.AreEqual(true, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin"));

            // TODO: This no longer makes sense; can't do this anymore?
            //set to null so the other testmethods continue to throw exceptions
            //Csla.ApplicationContext.User = new ClaimsPrincipal();

            Assert.AreEqual(false, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin"));
        }
Exemplo n.º 6
0
        public void AppDomainTestIsCalled()
        {
            IDataPortal <Basic.Root> dataPortal = _testDIContext.CreateDataPortal <Basic.Root>();

            TestResults.Reinitialise();
            int local = AppDomain.CurrentDomain.Id;

            Basic.Root r      = dataPortal.Create(new Basic.Root.Criteria());
            int        remote = r.CreatedDomain;

            if (System.Configuration.ConfigurationManager.AppSettings["CslaDataPortalProxy"] == null)
            {
                Assert.AreEqual(local, remote, "Local and Remote AppDomains should be the same");
            }
            else
            {
                Assert.IsFalse((local == remote), "Local and Remote AppDomains should be different");
            }
        }
Exemplo n.º 7
0
        public void CreateLocal()
        {
            // TODO: What proxy can we use for this test? Old one was Remoting, now retired
            //TestDIContext testDIContext = TestDIContextFactory.CreateContext(
            //  options => options.Services.AddTransient<DataPortalClient.IDataPortalProxy, Testing.Business.TestProxies.AppDomainProxy>(),
            //);
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(
                opts => opts.DataPortal(dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactoryC> >()))
                );

            IDataPortal <Root> dataPortal = testDIContext.CreateDataPortal <Root>();

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

            Assert.AreEqual("Create abc", root.Data, "Data should match");
            Assert.AreEqual(Csla.ApplicationContext.ExecutionLocations.Client, root.Location, "Location should match");
            Assert.IsTrue(root.IsNew, "Should be new");
            Assert.IsTrue(root.IsDirty, "Should be dirty");
        }
Exemplo n.º 8
0
        public void NoDoubleInit()
        {
            IDataPortal <HasPerTypeRules2> dataPortal = _testDIContext.CreateDataPortal <HasPerTypeRules2>();

            UnitTestContext context = GetContext();

            TestResults.Reinitialise();
            TestResults.Add("Shared", "0");

            HasPerTypeRules2 root = dataPortal.Create();

            int expected = (_initialized ? 0 : 1);
            int actual   = int.Parse(TestResults.GetResult("Shared"));

            context.Assert.AreEqual(expected, actual, "Rules should init just once");

            _initialized = true;
            context.Assert.Success();
            context.Complete();
        }
Exemplo n.º 9
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");
        }
Exemplo n.º 10
0
        public void MergeNewChildUpdate()
        {
            ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();
            IDataPortal <Foo>  dataPortal         = _testDIContext.CreateDataPortal <Foo>();

            var obj = dataPortal.Create();

            obj.Name = "1";
            obj.MockUpdated();
            var cloned = obj.Clone();

            cloned.AddChild(dataPortal);
            cloned.Child.Name = "42";
            cloned.MockUpdated();

            new GraphMerger(applicationContext).MergeGraph(obj, cloned);

            Assert.IsTrue(ReferenceEquals(obj.Child, cloned.Child), "ref");
            Assert.IsTrue(ReferenceEquals(obj, obj.Child.Parent));
        }
Exemplo n.º 11
0
        public void CreateMissing()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(
                // TODO: What proxy can we use for this test? Old one was Remoting, now retired
                //  options => options.Services.AddTransient<DataPortalClient.IDataPortalProxy, Testing.Business.TestProxies.AppDomainProxy>(),
                opts => opts.DataPortal(dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactory1> >())),
                new System.Security.Claims.ClaimsPrincipal()
                );

            IDataPortal <Root> dataPortal = testDIContext.CreateDataPortal <Root>();

            try
            {
                var root = dataPortal.Create("abc", 123);
            }
            catch (DataPortalException ex)
            {
                throw ex.BusinessException;
            }
        }
Exemplo n.º 12
0
        public void TestAuthExecute()
        {
            TestDIContext customDIContext                    = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <PermissionsRoot> dataPortal         = customDIContext.CreateDataPortal <PermissionsRoot>();
            ApplicationContext            applicationContext = customDIContext.CreateTestApplicationContext();

            TestResults.Reinitialise();

            PermissionsRoot pr = dataPortal.Create();

            //should work, because we are now logged in as an admin
            pr.DoWork();

            Assert.AreEqual(true, applicationContext.Principal.IsInRole("Admin"));

            //set to null so the other testmethods continue to throw exceptions
            applicationContext.User = new ClaimsPrincipal();

            Assert.AreEqual(false, applicationContext.Principal.IsInRole("Admin"));
        }
Exemplo n.º 13
0
        public void Initialize_InvalidRootObject_ExceptionRaised()
        {
            // Arrange
            IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>();
            Root rootObject = dataPortal.Create(new Root.Criteria(""));
            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));
        }
Exemplo n.º 14
0
        public void AllThree()
        {
            IDataPortal <SeverityRoot> dataPortal = _testDIContext.CreateDataPortal <SeverityRoot>();

            SeverityRoot root = dataPortal.Create();

            root.Validate();

            Assert.AreEqual(3, root.BrokenRulesCollection.Count, "3 rules should be broken (total)");

            Assert.IsFalse(root.IsValid, "Object should not be valid");

            Assert.AreEqual(1, root.BrokenRulesCollection.ErrorCount, "Only one rule should be broken");
            Assert.AreEqual("Always error", root.BrokenRulesCollection.GetFirstBrokenRule("Test").Description, "'Always error' should be broken (GetFirstBrokenRule)");
            Assert.AreEqual("Always error", root.BrokenRulesCollection.GetFirstMessage("Test", Csla.Rules.RuleSeverity.Error).Description, "'Always error' should be broken");

            Assert.AreEqual(1, root.BrokenRulesCollection.WarningCount, "Only one warning should be broken");
            Assert.AreEqual("Always warns", root.BrokenRulesCollection.GetFirstMessage("Test", Csla.Rules.RuleSeverity.Warning).Description, "'Always warns' should be broken");

            Assert.AreEqual(1, root.BrokenRulesCollection.InformationCount, "Only one info should be broken");
            Assert.AreEqual("Always info", root.BrokenRulesCollection.GetFirstMessage("Test", Csla.Rules.RuleSeverity.Information).Description, "'Always info' should be broken");
        }
Exemplo n.º 15
0
        public void FailCreateContext()
        {
            IDataPortal <ExceptionRoot> dataPortal = _testDIContext.CreateDataPortal <ExceptionRoot>();

            TestResults.Reinitialise();

            ExceptionRoot root;

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

            Assert.AreEqual("create", TestResults.GetResult("create"), "GlobalContext not preserved");
        }
Exemplo n.º 16
0
        public void TestAuthorizationAfterEditCycle()
        {
            IDataPortal <PermissionsRoot> dataPortal = _adminDIContext.CreateDataPortal <PermissionsRoot>();

            TestResults.Reinitialise();

            PermissionsRoot pr = dataPortal.Create();

            pr.FirstName = "something";

            pr.BeginEdit();
            pr.FirstName = "ba";
            pr.CancelEdit();

            // TODO: This test no longer makes any sense; can't do this can we?
            // Csla.ApplicationContext.User = new ClaimsPrincipal();

            PermissionsRoot prClone = pr.Clone();

            // Csla.ApplicationContext.User = GetPrincipal("Admin");
            prClone.FirstName = "somethiansdfasdf";
        }
Exemplo n.º 17
0
        public void CreateAndSaveChild()
        {
            IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>();

            Root root = dataPortal.Create();

            root.Data       = "a";
            root.Child.Data = "b";

            Assert.IsTrue(root.IsDirty, "Root should be dirty");
            Assert.IsTrue(root.Child.IsNew, "Child should be new");
            Assert.IsTrue(root.Child.IsDirty, "Child should be dirty");
            Assert.AreEqual("Created", root.Child.Status, "Child status incorrect after create");

            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("Inserted", root.Child.Status, "Child status incorrect after Save");
        }
Exemplo n.º 18
0
        public void BusinessRules_MustRecalculateSumAfterCaclulateFraction_WhenCascadeOnDirtyPropertiesIsTrue()
        {
            // calculate sum of Ca, Cb, Cc and Cd to Ce
            // calculate fraction of Ce to Cd
            // must then recalculate sum again as Cd was changed.
            IDataPortal <CascadeRoot> dataPortal = _testDIContext.CreateDataPortal <CascadeRoot>();

            var root = dataPortal.Create();

            root.CascadeOnDirtyProperties = true;
            root.CheckRules();
            Assert.AreEqual(0, root.ValueCa);
            Assert.AreEqual(0, root.ValueCb);
            Assert.AreEqual(0, root.ValueCc);
            Assert.AreEqual(0, root.ValueCd);
            Assert.AreEqual(0, root.ValueCe);

            root.ValueCa = 5;
            Assert.AreEqual(5, root.ValueCa);
            Assert.AreEqual(0, root.ValueCb);
            Assert.AreEqual(0, root.ValueCc);
            Assert.AreEqual(1.67m, root.ValueCd);
            Assert.AreEqual(6.67m, root.ValueCe);

            root.ValueCb = 15;
            Assert.AreEqual(5, root.ValueCa);
            Assert.AreEqual(15, root.ValueCb);
            Assert.AreEqual(0, root.ValueCc);
            Assert.AreEqual(6.67m, root.ValueCd);
            Assert.AreEqual(26.67m, root.ValueCe);

            root.ValueCc = 25;
            Assert.AreEqual(5, root.ValueCa);
            Assert.AreEqual(15, root.ValueCb);
            Assert.AreEqual(25, root.ValueCc);
            Assert.AreEqual(15.00m, root.ValueCd);
            Assert.AreEqual(60.00m, root.ValueCe);
        }
Exemplo n.º 19
0
        public void MergeListNewChild()
        {
            ApplicationContext    applicationContext = _testDIContext.CreateTestApplicationContext();
            IDataPortal <FooList> dataPortal         = _testDIContext.CreateDataPortal <FooList>();

            var obj      = dataPortal.Create();
            var original = obj;
            var newChild = obj.AddNew();

            newChild.Name = "new";

            var bo = (IBusinessObject)newChild;

            Assert.IsTrue(bo.Identity >= 0, "bo needs identity");

            var saved = obj.Save();

            Assert.AreEqual(((IBusinessObject)newChild).Identity, ((IBusinessObject)saved[0]).Identity, "identity should survive save");

            Assert.IsTrue(!ReferenceEquals(obj[0], saved[0]), "saved object is not original");

            new GraphMerger(applicationContext).MergeBusinessListGraph <FooList, Foo>(obj, saved);

            Assert.AreEqual(((IBusinessObject)newChild).Identity, ((IBusinessObject)obj[0]).Identity);
            Assert.AreEqual(((IBusinessObject)newChild).Identity, ((IBusinessObject)saved[0]).Identity);
            Assert.AreEqual(((IBusinessObject)obj[0]).Identity, ((IBusinessObject)saved[0]).Identity);

            Assert.AreEqual(obj[0].IsNew, saved[0].IsNew);

            Assert.IsFalse(ReferenceEquals(original, saved));
            Assert.IsTrue(ReferenceEquals(original, obj));

            Assert.IsTrue(ReferenceEquals(original[0], obj[0]));
            Assert.IsTrue(ReferenceEquals(newChild, obj[0]));

            obj[0].Name = "changed";
            Assert.AreEqual(original[0].Name, obj[0].Name);
        }
Exemplo n.º 20
0
        public void TestAuthorizationAfterEditCycle()
        {
            TestDIContext customDIContext                    = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <PermissionsRoot> dataPortal         = customDIContext.CreateDataPortal <PermissionsRoot>();
            ApplicationContext            applicationContext = customDIContext.CreateTestApplicationContext();

            TestResults.Reinitialise();

            PermissionsRoot pr = dataPortal.Create();

            pr.FirstName = "something";

            pr.BeginEdit();
            pr.FirstName = "ba";
            pr.CancelEdit();

            applicationContext.User = new ClaimsPrincipal();

            PermissionsRoot prClone = pr.Clone();

            applicationContext.User = GetPrincipal("Admin");
            prClone.FirstName       = "somethiansdfasdf";
        }
Exemplo n.º 21
0
        public void OnlySharedRules()
        {
            IDataPortal <HasOnlyPerTypeRules> dataPortal = _testDIContext.CreateDataPortal <HasOnlyPerTypeRules>();

            UnitTestContext context = GetContext();

            TestResults.Reinitialise();
            TestResults.Add("Shared", "0");

            HasOnlyPerTypeRules root = dataPortal.Create();

            root.Validate();
            context.Assert.AreEqual(string.Empty, root.Test, "Test string should be empty");
            context.Assert.AreEqual(1, root.BrokenRulesCollection.Count, "Broken rule count should be 1 first");
            root.Test = "test";
            context.Assert.AreEqual("test", root.Test, "Test string should be 'test'");
            context.Assert.AreEqual(0, root.BrokenRulesCollection.Count, "Broken rule count should be 0");
            root.Test = "big test";
            context.Assert.AreEqual("big test", root.Test, "Test string should be 'big test'");
            context.Assert.AreEqual(1, root.BrokenRulesCollection.Count, "Broken rule count should be 1 last");
            context.Assert.Success();
            context.Complete();
        }
Exemplo n.º 22
0
        public void MergeList()
        {
            ApplicationContext    applicationContext = _testDIContext.CreateTestApplicationContext();
            IDataPortal <FooList> dataPortal         = _testDIContext.CreateDataPortal <FooList>();

            var obj = dataPortal.Create();

            obj.AddNew().Name = "existing";
            obj[0].MockUpdated();
            obj.AddNew().Name = "to be deleted";
            obj.Remove(obj[1]);
            obj.AddNew().Name = "new";
            obj.AddNew().Name = "remove in clone";
            Assert.AreEqual(3, obj.Count, "preclone count");
            var cloned = obj.Clone();

            Assert.AreEqual(3, cloned.Count, "postclone count");
            cloned.Remove(cloned.Where(_ => _.Name == "remove in clone").First());
            Assert.AreEqual(2, cloned.Count, "postclone count after removed obj");
            Assert.AreEqual(cloned[0].Name, obj[0].Name, "postclone [0]");
            Assert.AreEqual(cloned[1].Name, obj[1].Name, "postclone [1]");
            cloned[0].Name = "existing (cloned)";
            cloned[1].Name = "new (cloned)";
            cloned.AddNew().Name = "new in clone";
            cloned.MockUpdated();

            var merger = new GraphMerger(applicationContext);

            merger.MergeBusinessListGraph <FooList, Foo>(obj, cloned);
            Assert.AreEqual(cloned.Count, obj.Count, "count");
            Assert.AreEqual(3, obj.Count, "count 3");
            Assert.AreEqual(cloned[0].Name, obj[0].Name, "[0]");
            Assert.AreEqual(cloned[1].Name, obj[1].Name, "[1]");
            Assert.AreEqual(cloned[2].Name, obj[2].Name, "[2]");
            Assert.AreEqual(cloned.IsDirty, obj.IsDirty);
            Assert.IsFalse(obj.IsDirty);
        }
Exemplo n.º 23
0
        public void NonGenericLoadProperty()
        {
            IDataPortal <EditableGetSet> dataPortal = _testDIContext.CreateDataPortal <EditableGetSet>();

            EditableGetSet root = EditableGetSet.GetObject(dataPortal);

            root.LoadM02(123);
            Assert.AreEqual(123, root.M02);

            root.LoadInternalAndPrivate("Test");
            Assert.AreEqual("Test", root.M08);

            IDataPortal <Command> commandDataPortal = _testDIContext.CreateDataPortal <Command>();
            var cmd = commandDataPortal.Create();

            cmd.Load("abc");
            Assert.AreEqual("abc", cmd.Name);

            IDataPortal <ReadOnly> roDataPortal = _testDIContext.CreateDataPortal <ReadOnly>();
            var ro = roDataPortal.Fetch();

            ro.Load("abc");
            Assert.AreEqual("abc", ro.Name);
        }
Exemplo n.º 24
0
        public void InsertItem()
        {
            IDataPortal <ERlist> dataPortal = _testDIContext.CreateDataPortal <ERlist>();

            TestResults.Reinitialise();

            _isListSaved = false;

            ERlist list = dataPortal.Create();

            list.Saved += new EventHandler <Csla.Core.SavedEventArgs>(List_Saved);
            ERitem item = list.AddNew();

            Assert.AreEqual(1, list.Count, "Incorrect count after add");

            // simulate grid edit
            System.ComponentModel.IEditableObject obj = (System.ComponentModel.IEditableObject)item;
            obj.BeginEdit();
            list[0].Data = "test";
            obj.EndEdit();
            Assert.AreEqual(true, _isListSaved, "List saved event did not fire after save.");
            Assert.AreEqual("Insert", TestResults.GetResult("DP"), "Object should have been inserted");
            Assert.IsFalse(list[0].IsNew, "Object should not be new");
        }
Exemplo n.º 25
0
        public void RemoveOldItem()
        {
            IDataPortal <ERlist> dataPortal     = _testDIContext.CreateDataPortal <ERlist>();
            IDataPortal <ERitem> itemDataPortal = _testDIContext.CreateDataPortal <ERitem>();

            TestResults.Reinitialise();
            _isListSaved = false;

            ERlist list = dataPortal.Create();

            list.Add(itemDataPortal.Fetch("test"));
            ERitem item = list[0];

            item.Saved += new EventHandler <Csla.Core.SavedEventArgs>(item_Saved);
            list.Saved += new EventHandler <Csla.Core.SavedEventArgs>(List_Saved);
            Assert.AreEqual(1, list.Count, "Incorrect count after add");
            Assert.IsFalse(list[0].IsNew, "Object should not be new");

            list.RemoveAt(0);
            Assert.AreEqual(true, _isListSaved, "List saved event did not fire after save.");
            Assert.AreEqual(0, list.Count, "Incorrect count after remove");
            Assert.AreEqual("DeleteSelf", TestResults.GetResult("DP"), "Object should have deleted itself");
            Assert.IsTrue(_itemIsNew, "Object should be new after delete");
        }
Exemplo n.º 26
0
        public void LoadRuleSets()
        {
            IDataPortal <HasRuleSetRules> dataPortal = _testDIContext.CreateDataPortal <HasRuleSetRules>();

            UnitTestContext context = GetContext();

            TestResults.Reinitialise();

            var root = dataPortal.Create();

            var d = root.GetDefaultRules();

            context.Assert.AreEqual(1, d.Length);

            root.Name = "abc";
            context.Assert.IsTrue(root.IsValid, "valid with name");
            root.Name = "123456";
            context.Assert.IsTrue(root.IsValid, "valid with long name");
            root.Name = "";
            context.Assert.IsFalse(root.IsValid, "not valid with empty name");


            var t = root.GetTestRules();

            context.Assert.AreEqual(2, t.Length);

            root.Name = "abc";
            context.Assert.IsTrue(root.IsValid, "valid with name");
            root.Name = "123456";
            context.Assert.IsFalse(root.IsValid, "not valid with too long name");
            root.Name = "";
            context.Assert.IsFalse(root.IsValid, "not valid with empty name");

            context.Assert.Success();
            context.Complete();
        }
Exemplo n.º 27
0
        private SimpleType CreateSimpleType(IServiceProvider serviceProvider)
        {
            IDataPortal <SimpleType> dataPortal = serviceProvider.GetRequiredService <IDataPortal <SimpleType> >();

            return(dataPortal.Create());
        }
Exemplo n.º 28
0
 internal static Child NewChild(IDataPortal <Child> dataPortal, string data)
 {
     return(dataPortal.Create(data));
 }
Exemplo n.º 29
0
        private Legacy NewLegacy()
        {
            IDataPortal <Legacy> dataPortal = _testDIContext.CreateDataPortal <Legacy>();

            return(dataPortal.Create());
        }
Exemplo n.º 30
0
 public static SerializationRoot NewSerializationRoot(IDataPortal <SerializationRoot> dataPortal)
 {
     return(dataPortal.Create());
 }