Пример #1
0
        public void BackgroundWorker_RunWorkerAsync_CallsDoWorkAndWorkerCompleted()
        {
            var threadid = Thread.CurrentThread.ManagedThreadId;

            using (UnitTestContext context = GetContext())
            {
                bool doWorkCalled = false;

                BackgroundWorker target = new BackgroundWorker();
                target.DoWork += (o, e) =>
                {
                    doWorkCalled = true;

                    // make sure that user, clientcontext, globalcontext, currentCulture and currentUIculture are sent
                    context.Assert.IsFalse(threadid == Thread.CurrentThread.ManagedThreadId);
                    context.Assert.IsTrue(Csla.ApplicationContext.User is MyPrincipal);
                    context.Assert.AreEqual("TEST", Csla.ApplicationContext.GlobalContext["BWTEST"]);
                    context.Assert.AreEqual("TEST", Csla.ApplicationContext.ClientContext["BWTEST"]);

                    context.Assert.AreEqual("FR", Thread.CurrentThread.CurrentCulture.Name.ToUpper());
                    context.Assert.AreEqual("FR", Thread.CurrentThread.CurrentUICulture.Name.ToUpper());
                };
                target.RunWorkerCompleted += (o, e) =>
                {
                    context.Assert.IsTrue(threadid == Thread.CurrentThread.ManagedThreadId);
                    context.Assert.IsNull(e.Error);
                    context.Assert.IsTrue(doWorkCalled, "Do work has been called");
                    context.Assert.Success();
                };
                target.RunWorkerAsync(null);
                context.Complete();
            }
        }
Пример #2
0
        public void VerifyUndoableStateStackOnClone()
        {
            Csla.ApplicationContext.GlobalContext.Clear();
            using (UnitTestContext context = GetContext())
            {
                HasRulesManager2.NewHasRulesManager2((o, e) =>
                {
                    context.Assert.IsNull(e.Error);
                    HasRulesManager2 root = e.Object;

                    string expected = root.Name;
                    root.BeginEdit();
                    root.Name = "";
                    HasRulesManager2 rootClone = root.Clone();
                    rootClone.CancelEdit();

                    string actual = rootClone.Name;
                    context.Assert.AreEqual(expected, actual);
                    context.Assert.Try(rootClone.ApplyEdit);

                    context.Assert.Success();
                });
                context.Complete();
            }
        }
Пример #3
0
        public void TestCoerseValue()
        {
            UnitTestContext     context = GetContext();
            UtilitiesTestHelper helper  = new UtilitiesTestHelper();

            helper.IntProperty    = 0;
            helper.StringProperty = "1";
            helper.IntProperty    = (int)Csla.Utilities.CoerceValue(typeof(int), typeof(string), null, helper.StringProperty);
            context.Assert.AreEqual(1, helper.IntProperty, "Should have converted to int");

            helper.IntProperty    = 2;
            helper.StringProperty = "";
            helper.StringProperty = (string)Csla.Utilities.CoerceValue(typeof(string), typeof(int), null, helper.IntProperty);
            context.Assert.AreEqual("2", helper.StringProperty, "Should have converted to string");


            helper.StringProperty         = "1";
            helper.NullableStringProperty = null;
            object convertedValue = Csla.Utilities.CoerceValue(typeof(string), typeof(string), null, helper.NullableStringProperty);

            context.Assert.IsNull(helper.NullableStringProperty);
            context.Assert.IsNull(convertedValue);

            context.Assert.AreEqual(UtilitiesTestHelper.ToStringValue, (string)Csla.Utilities.CoerceValue(typeof(string), typeof(UtilitiesTestHelper), null, helper), "Should have issued ToString()");
            context.Assert.Success();
            context.Complete();
        }
Пример #4
0
        public void BackgroundWorker_CancelAsync_ThrowsInvalidOperationExceptionWhenWorkerSupportsCancellationIsFalse()
        {
            using (UnitTestContext context = GetContext())
            {
                BackgroundWorker target = new BackgroundWorker();
                target.DoWork += (o, e) =>
                {
                    for (int i = 1; i < 11; i++)
                    {
                        Thread.Sleep(10);
                    }
                };
                target.WorkerSupportsCancellation = false;
                target.RunWorkerAsync(null);

                try
                {
                    target.CancelAsync(); // this call throws exception
                }
                catch (InvalidOperationException ex)
                {
                    context.Assert.Fail(ex);
                }
                context.Complete();
            }
        }
Пример #5
0
        public void BreakLengthRuleAndClone()
        {
            Csla.ApplicationContext.GlobalContext.Clear();
            UnitTestContext context = GetContext();

            HasRulesManager.NewHasRulesManager((o, e) =>
            {
                HasRulesManager root = e.Object;
                root.Name            = "12345678901";
                context.Assert.AreEqual(false, root.IsValid, "should not be valid before clone");
                context.Assert.AreEqual(1, root.BrokenRulesCollection.Count);
                //Assert.AreEqual("Name too long", root.GetBrokenRulesCollection[0].Description;
                Assert.AreEqual("Name can not exceed 10 characters", root.BrokenRulesCollection[0].Description);

                root = (HasRulesManager)(root.Clone());
                context.Assert.AreEqual(false, root.IsValid, "should not be valid after clone");
                context.Assert.AreEqual(1, root.BrokenRulesCollection.Count);
                //Assert.AreEqual("Name too long", root.GetBrokenRulesCollection[0].Description;
                context.Assert.AreEqual("Name can not exceed 10 characters", root.BrokenRulesCollection[0].Description);

                root.Name = "1234567890";
                context.Assert.AreEqual(true, root.IsValid, "Should be valid");
                context.Assert.AreEqual(0, root.BrokenRulesCollection.Count);
                context.Assert.Success();
            });
            context.Complete();
        }
Пример #6
0
        public void ListTestSaveWhileNotBusyNetOnly()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#else
            System.Configuration.ConfigurationManager.AppSettings["CslaAutoCloneOnUpdate"] = "false";
#endif
            UnitTestContext        context = GetContext();
            ItemWithAsynchRuleList items   = ItemWithAsynchRuleList.GetListWithItems();



            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();
        }
Пример #7
0
        public void BackgroundWorker_DoWork_ThrowsInvalidOperationExcpetionWhenWorkerReportsProgressIsFalse()
        {
            UnitTestContext context = GetContext();

            int numTimesProgressCalled = 0;

            BackgroundWorker target = new BackgroundWorker();

            target.DoWork += (o, e) =>
            {
                // report progress changed 10 times
                for (int i = 1; i < 11; i++)
                {
                    target.ReportProgress(i * 10);
                }
            };
            target.WorkerReportsProgress = false;
            target.ProgressChanged      += (o, e) =>
            {
                numTimesProgressCalled++;
            };
            target.RunWorkerCompleted += (o, e) =>
            {
                //  target does not support ReportProgress we shold get a System.InvalidOperationException from DoWork
                context.Assert.IsTrue(e.Error is System.InvalidOperationException);
                context.Assert.Success();
            };
            target.RunWorkerAsync(null);
            context.Complete();
        }
Пример #8
0
        public void NullChildObject()
        {
            UnitTestContext context = GetContext();

            // Setup the customer w/ a null child object
            Customer customer = new Customer();

            customer.Name = "Test Customer";
            customer.PrimaryContact.FirstName = "John";
            customer.PrimaryContact.LastName  = "Smith";
            customer.AccountsPayableContact   = null;

            // Serialize and deserialize the customer
            var buffer = MobileFormatter.Serialize(customer);
            var deserializedCustomer = (Customer)MobileFormatter.Deserialize(buffer);

            // Verify the deserialized customer is identical to the original object
            context.Assert.AreEqual(customer.Name, deserializedCustomer.Name);
            context.Assert.AreEqual(customer.PrimaryContact.FirstName, deserializedCustomer.PrimaryContact.FirstName);
            context.Assert.AreEqual(customer.PrimaryContact.LastName, deserializedCustomer.PrimaryContact.LastName);
            context.Assert.IsNull(deserializedCustomer.AccountsPayableContact);

            context.Assert.Success();
            context.Complete();
        }
Пример #9
0
        public void BusinessObjectWithoutChildList()
        {
            UnitTestContext context   = GetContext();
            DateTime        birthdate = new DateTime(1980, 2, 3);

            Person expected = new Person();

            expected.Name         = "test";
            expected.Unserialized = "should be null";
            expected.Birthdate    = birthdate;
            expected.DtoDate      = DateTimeOffset.Parse("1/1/2000");

            var buffer = MobileFormatter.Serialize(expected);
            var actual = (Person)MobileFormatter.Deserialize(buffer);

            context.Assert.AreEqual(expected.Name, actual.Name);
            context.Assert.AreEqual(expected.Birthdate, actual.Birthdate);
            context.Assert.AreEqual(expected.DtoDate, actual.DtoDate);
            context.Assert.AreEqual(expected.Age, actual.Age);

            context.Assert.AreEqual(actual.Unserialized, string.Empty);
            context.Assert.IsNull(actual.Addresses);
            context.Assert.IsNull(actual.PrimaryAddress);

            context.Assert.IsNotNull(expected.Unserialized);
            context.Assert.IsNull(expected.Addresses);
            context.Assert.IsNull(expected.PrimaryAddress);
            context.Assert.Success();
            context.Complete();
        }
Пример #10
0
        public void MobileDictionary_PrimitiveKey_MobileValue()
        {
            UnitTestContext context = GetContext();
            var             d       = new MobileDictionary <string, MockReadOnly>();

            d.Add("a", new MockReadOnly(1));
            d.Add("z", new MockReadOnly(2));
            d.Add("b", new MockReadOnly(3));
            d.Add("x", new MockReadOnly(4));
            d.Add("r", new MockReadOnly(5));

            byte[] buffer = MobileFormatter.Serialize(d);
            var    r      = (MobileDictionary <string, MockReadOnly>)MobileFormatter.Deserialize(buffer);

            context.Assert.IsTrue(r.ContainsKey("a"));
            context.Assert.IsTrue(r.ContainsKey("z"));
            context.Assert.IsTrue(r.ContainsKey("b"));
            context.Assert.IsTrue(r.ContainsKey("x"));
            context.Assert.IsTrue(r.ContainsKey("r"));

            context.Assert.AreEqual(d["a"].Id, r["a"].Id);
            context.Assert.AreEqual(d["z"].Id, r["z"].Id);
            context.Assert.AreEqual(d["b"].Id, r["b"].Id);
            context.Assert.AreEqual(d["x"].Id, r["x"].Id);
            context.Assert.AreEqual(d["r"].Id, r["r"].Id);
            context.Assert.Success();
            context.Complete();
        }
Пример #11
0
        public void LogicallyIdenticalChildObjects()
        {
            UnitTestContext context = GetContext();

            // Setup the customer w/ logically identical contacts
            Customer customer = new Customer();

            customer.Name = "Test Customer";
            customer.PrimaryContact.FirstName         = "John";
            customer.PrimaryContact.LastName          = "Smith";
            customer.AccountsPayableContact.FirstName = "John";
            customer.AccountsPayableContact.LastName  = "Smith";

            // Serialize and deserialize the customer
            var buffer = MobileFormatter.Serialize(customer);
            var deserializedCustomer = (Customer)MobileFormatter.Deserialize(buffer);

            // Verify the deserialized customer is identical to the original object
            context.Assert.AreEqual(customer.Name, deserializedCustomer.Name);
            context.Assert.AreEqual(customer.PrimaryContact.FirstName, deserializedCustomer.PrimaryContact.FirstName);
            context.Assert.AreEqual(customer.PrimaryContact.LastName, deserializedCustomer.PrimaryContact.LastName);
            context.Assert.AreEqual(customer.AccountsPayableContact.FirstName, deserializedCustomer.AccountsPayableContact.FirstName);
            context.Assert.AreEqual(customer.AccountsPayableContact.LastName, deserializedCustomer.AccountsPayableContact.LastName);

            //
            // The two CustomerContact objects (PrimaryContact and AccountsPayableContact) should not
            // point to the same CustomerContact instance after deserialization, even though they
            // are logically identical. They start as different objects prior to serialization and
            // they should end as different objects after.
            //
            context.Assert.IsFalse(Object.ReferenceEquals(deserializedCustomer.PrimaryContact, deserializedCustomer.AccountsPayableContact));

            context.Assert.Success();
            context.Complete();
        }
Пример #12
0
        public void MobileDictionary_PrimitiveKey_PrimitiveValue_BF()
        {
            UnitTestContext context = GetContext();
            var             d       = new MobileDictionary <string, int>();

            d.Add("a", 12343);
            d.Add("z", 943204);
            d.Add("b", 77878);
            d.Add("x", 42343);
            d.Add("r", 45345);

            var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            var buffer    = new System.IO.MemoryStream();

            formatter.Serialize(buffer, d);
            buffer.Position = 0;
            var r = (MobileDictionary <string, int>)formatter.Deserialize(buffer);

            context.Assert.IsTrue(r.ContainsKey("a"));
            context.Assert.IsTrue(r.ContainsKey("z"));
            context.Assert.IsTrue(r.ContainsKey("b"));
            context.Assert.IsTrue(r.ContainsKey("x"));
            context.Assert.IsTrue(r.ContainsKey("r"));

            context.Assert.AreEqual(d["a"], r["a"]);
            context.Assert.AreEqual(d["z"], r["z"]);
            context.Assert.AreEqual(d["b"], r["b"]);
            context.Assert.AreEqual(d["x"], r["x"]);
            context.Assert.AreEqual(d["r"], r["r"]);
            context.Assert.Success();
            context.Complete();
        }
Пример #13
0
        public void MobileDictionary_PrimitiveKey_PrimitiveValue()
        {
            UnitTestContext context = GetContext();
            var             d       = new MobileDictionary <string, int>();

            d.Add("a", 12343);
            d.Add("z", 943204);
            d.Add("b", 77878);
            d.Add("x", 42343);
            d.Add("r", 45345);

            byte[] buffer = MobileFormatter.Serialize(d);
            var    r      = (MobileDictionary <string, int>)MobileFormatter.Deserialize(buffer);

            context.Assert.IsTrue(r.ContainsKey("a"));
            context.Assert.IsTrue(r.ContainsKey("z"));
            context.Assert.IsTrue(r.ContainsKey("b"));
            context.Assert.IsTrue(r.ContainsKey("x"));
            context.Assert.IsTrue(r.ContainsKey("r"));

            context.Assert.AreEqual(d["a"], r["a"]);
            context.Assert.AreEqual(d["z"], r["z"]);
            context.Assert.AreEqual(d["b"], r["b"]);
            context.Assert.AreEqual(d["x"], r["x"]);
            context.Assert.AreEqual(d["r"], r["r"]);
            context.Assert.Success();
            context.Complete();
        }
Пример #14
0
        public void LoadRuleSets()
        {
            UnitTestContext context = GetContext();

            ApplicationContext.GlobalContext.Clear();

            var root = new HasRuleSetRules();

            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();
        }
Пример #15
0
        public void TestBusy()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#else
            System.Configuration.ConfigurationManager.AppSettings["CslaAutoCloneOnUpdate"] = "false";
#endif
            UnitTestContext    context = GetContext();
            ItemWithAsynchRule item;
            ItemWithAsynchRule.GetItemWithAsynchRule("an id", (o, e) =>
            {
                try
                {
                    item = e.Object;
                    context.Assert.IsNull(e.Error, "Error should be null");
                    context.Assert.IsNotNull(item, "item should not be null");

                    item.RuleField = "some value";
                    context.Assert.IsTrue(item.IsBusy, "Should be busy");
                    context.Assert.IsFalse(item.IsSavable, "Should not be savable");
                }
                catch (Exception ex)
                {
                    context.Assert.Fail(ex.ToString());
                }
                context.Assert.Success();
            });
            context.Complete();
        }
Пример #16
0
        public void TestBypassReadWriteWithRightsTurnNotificationBackOn()
        {
            UnitTestContext context = GetContext();

            Csla.ApplicationContext.User = GetPrincipal("Admin", "Random");
            bool propertyChangedFired  = false;
            BypassBusinessBase testObj = new BypassBusinessBase();

            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();
            Csla.ApplicationContext.User = new System.Security.Claims.ClaimsPrincipal();
            context.Complete();
        }
Пример #17
0
        public void TestSaveWhileNotBusyNetOnly()
        {
            UnitTestContext context = GetContext();

            System.Configuration.ConfigurationManager.AppSettings["CslaAutoCloneOnUpdate"] = "false";
            ItemWithAsynchRule item;

            ItemWithAsynchRule.GetItemWithAsynchRule("an id", (o, e) =>
            {
                item = e.Object;
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(item);


                item.RuleField = "some value";
                context.Assert.IsTrue(item.IsBusy);
                context.Assert.IsFalse(item.IsSavable);
                item.ValidationComplete += (o2, e2) =>
                {
                    context.Assert.IsFalse(item.IsBusy);
                    context.Assert.IsTrue(item.IsSavable);
                    item = item.Save();
                    context.Assert.AreEqual("DataPortal_Update", item.OperationResult);
                    context.Assert.Success();
                };
            });
            context.Complete();
        }
Пример #18
0
        public async Task TestValidationRulesWithPrivateMember()
        {
            //works now because we are calling ValidationRules.CheckRules() in DataPortal_Create
            UnitTestContext context = GetContext();

            TestResults.Reinitialise();
            var root = await CreateHasRulesManagerAsync();

            context.Assert.AreEqual("<new>", root.Name);
            context.Assert.AreEqual(true, root.IsValid, "should be valid on create");
            context.Assert.AreEqual(0, root.BrokenRulesCollection.Count);

            root.BeginEdit();
            root.Name = "";
            root.CancelEdit();

            context.Assert.AreEqual("<new>", root.Name);
            context.Assert.AreEqual(true, root.IsValid, "should be valid after CancelEdit");
            context.Assert.AreEqual(0, root.BrokenRulesCollection.Count);

            root.BeginEdit();
            root.Name = "";
            root.ApplyEdit();

            context.Assert.AreEqual("", root.Name);
            context.Assert.AreEqual(false, root.IsValid);
            context.Assert.AreEqual(1, root.BrokenRulesCollection.Count);
            context.Assert.AreEqual("Name required", root.BrokenRulesCollection[0].Description);
            context.Assert.Success();

            context.Complete();
        }
Пример #19
0
        public void TestSaveWhileBusy()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#endif
            UnitTestContext    context = GetContext();
            ItemWithAsynchRule item;
            ItemWithAsynchRule.GetItemWithAsynchRule("an id", (o, e) =>
            {
                item = e.Object;
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(item);


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

                item.BeginSave((o1, e1) =>
                {
                    var error = e1.Error as InvalidOperationException;
                    context.Assert.IsNotNull(error);
                    if (error != null)
                    {
                        context.Assert.IsTrue(error.Message.ToLower().Contains("busy"));
                    }
                    context.Assert.IsTrue(error.Message.ToLower().Contains("save"));
                    context.Assert.Success();
                });
            });
            context.Complete();
        }
Пример #20
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();
        }
Пример #21
0
        public void BackgroundWorker_CancelAsync_ReportsCancelledWhenWorkerSupportsCancellationIsTrue()
        {
            UnitTestContext context = GetContext();

            BackgroundWorker target = new BackgroundWorker();

            target.DoWork += (o, e) =>
            {
                // report progress changed 10 times
                for (int i = 1; i < 11; i++)
                {
                    Thread.Sleep(100);
                    if (target.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
            };
            target.WorkerSupportsCancellation = true;
            target.RunWorkerCompleted        += (o, e) =>
            {
                //  target does not support ReportProgress we shold get a System.InvalidOperationException from DoWork
                context.Assert.IsNull(e.Error);
                context.Assert.IsTrue(e.Cancelled);
                context.Assert.Success();
            };
            target.RunWorkerAsync(null);
            target.CancelAsync();
            context.Complete();
        }
Пример #22
0
        public void ListTestSaveWhileBusy()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#else
            System.Configuration.ConfigurationManager.AppSettings["CslaAutoCloneOnUpdate"] = "false";
#endif
            UnitTestContext        context = GetContext();
            ItemWithAsynchRuleList items   = ItemWithAsynchRuleList.GetListWithItems();
            items[0].RuleField = "some value";
            context.Assert.IsTrue(items.IsBusy);
            context.Assert.IsFalse(items.IsSavable);

            items.BeginSave((o1, e1) =>
            {
                var error = e1.Error as InvalidOperationException;
                context.Assert.IsNotNull(error);
                if (error != null)
                {
                    context.Assert.IsTrue(error.Message.ToLower().Contains("busy"));
                }
                context.Assert.IsTrue(error.Message.ToLower().Contains("save"));
                context.Assert.Success();
            });

            context.Complete();
        }
Пример #23
0
        public void TestValidationRulesAfterClone()
        {
            //this test uses HasRulesManager2, which assigns criteria._name to its public
            //property in DataPortal_Create.  If it used HasRulesManager, it would fail
            //the first assert, but pass the others
            Csla.ApplicationContext.GlobalContext.Clear();
            UnitTestContext context = GetContext();

            HasRulesManager2.NewHasRulesManager2((o, e) =>
            {
                context.Assert.Try(() =>
                {
                    HasRulesManager2 root = e.Object;
                    context.Assert.AreEqual(true, root.IsValid);
                    root.BeginEdit();
                    root.Name = "";
                    root.ApplyEdit();

                    context.Assert.AreEqual(false, root.IsValid);
                    HasRulesManager2 rootClone = root.Clone();
                    context.Assert.AreEqual(false, rootClone.IsValid);

                    rootClone.Name = "something";
                    context.Assert.AreEqual(true, rootClone.IsValid);
                    context.Assert.Success();
                });
            });
            context.Complete();
        }
Пример #24
0
        public void TestNotBusy()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#endif
            UnitTestContext    context = GetContext();
            ItemWithAsynchRule item;
            ItemWithAsynchRule.GetItemWithAsynchRule("an id", (o, e) =>
            {
                item = e.Object;
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(item);


                item.RuleField = "some value";
                context.Assert.IsTrue(item.IsBusy);
                context.Assert.IsFalse(item.IsSavable);
                item.ValidationComplete += (o2, e2) =>
                {
                    context.Assert.IsFalse(item.IsBusy);
                    context.Assert.IsTrue(item.IsSavable);
                    context.Assert.Success();
                };
            });
            context.Complete();
        }
Пример #25
0
        public void TestValidationRulesWithPrivateMember()
        {
            //works now because we are calling ValidationRules.CheckRules() in DataPortal_Create
            UnitTestContext context = GetContext();

            Csla.ApplicationContext.GlobalContext.Clear();
            HasRulesManager.NewHasRulesManager((o, e) =>
            {
                HasRulesManager root = e.Object;
                context.Assert.AreEqual("<new>", root.Name);
                context.Assert.AreEqual(true, root.IsValid, "should be valid on create");
                context.Assert.AreEqual(0, root.BrokenRulesCollection.Count);

                root.BeginEdit();
                root.Name = "";
                root.CancelEdit();

                context.Assert.AreEqual("<new>", root.Name);
                context.Assert.AreEqual(true, root.IsValid, "should be valid after CancelEdit");
                context.Assert.AreEqual(0, root.BrokenRulesCollection.Count);

                root.BeginEdit();
                root.Name = "";
                root.ApplyEdit();

                context.Assert.AreEqual("", root.Name);
                context.Assert.AreEqual(false, root.IsValid);
                context.Assert.AreEqual(1, root.BrokenRulesCollection.Count);
                context.Assert.AreEqual("Name required", root.BrokenRulesCollection[0].Description);
                context.Assert.Success();
            });

            context.Complete();
        }
Пример #26
0
        public void TestSaveWhileBusyNetOnly()
        {
            UnitTestContext    context = GetContext();
            ItemWithAsynchRule item;

            ItemWithAsynchRule.GetItemWithAsynchRule("an id", (o, e) =>
            {
                item = e.Object;
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(item);


                item.RuleField = "some value";
                context.Assert.IsTrue(item.IsBusy);
                context.Assert.IsFalse(item.IsSavable);
                bool gotError = false;
                try
                {
                    item.Save();
                }
                catch (InvalidOperationException EX)
                {
                    gotError = true;
                }
                context.Assert.IsTrue(gotError);
                context.Assert.Success();
            });
            context.Complete();
        }
Пример #27
0
        public void ListChangedEventTrigger()
        {
            Csla.ApplicationContext.GlobalContext.Clear();
            UnitTestContext context = GetContext();

            HasChildren.NewObject((o, e) =>
            {
                try
                {
                    HasChildren root = e.Object;
                    context.Assert.AreEqual(false, root.IsValid);
                    root.BeginEdit();
                    root.ChildList.Add(Csla.DataPortal.CreateChild <Child>());
                    context.Assert.AreEqual(true, root.IsValid);

                    root.CancelEdit();
                    context.Assert.AreEqual(false, root.IsValid);

                    context.Assert.Success();
                }
                finally
                {
                    context.Complete();
                }
            });
        }
Пример #28
0
        public void ListTestSaveWhileBusyNetOnly()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#else
            System.Configuration.ConfigurationManager.AppSettings["CslaAutoCloneOnUpdate"] = "false";
#endif
            UnitTestContext        context = GetContext();
            ItemWithAsynchRuleList items   = ItemWithAsynchRuleList.GetListWithItems();

            items[0].RuleField = "some value";
            context.Assert.IsTrue(items.IsBusy);
            context.Assert.IsFalse(items.IsSavable);
            bool gotError = false;
            try
            {
                items.Save();
            }
            catch (InvalidOperationException EX)
            {
                gotError = true;
            }
            context.Assert.IsTrue(gotError);
            context.Assert.Success();

            context.Complete();
        }
Пример #29
0
        public void UndoChildSuccess()
        {
            UnitTestContext context = GetContext();
            Person          p       = new Person();

            p.Addresses = new AddressList();
            Address a = new Address();

            p.Addresses.Add(a);

            int    age1  = p.Age = 1;
            string city1 = a.City = "one";

            p.BeginEdit();

            int    age2  = p.Age = 2;
            string city2 = a.City = "two";

            a.BeginEdit();

            string city3 = a.City = "three";

            a.CancelEdit();

            context.Assert.AreEqual(age2, p.Age);
            context.Assert.AreEqual(city2, a.City);
            p.CancelEdit();

            context.Assert.AreEqual(age1, p.Age);
            context.Assert.AreEqual(city1, a.City);
            context.Assert.Success();
            context.Complete();
        }
Пример #30
0
        public void BackgroundWorker_RunWorkerAsync_ReportsProgress()
        {
            var threadid = Thread.CurrentThread.ManagedThreadId;

            using (UnitTestContext context = GetContext())
            {
                int numTimesProgressCalled = 0;

                BackgroundWorker target = new BackgroundWorker();
                target.DoWork += (o, e) =>
                {
                    // report progress changed 10 times
                    for (int i = 1; i < 11; i++)
                    {
                        target.ReportProgress(i * 10);
                    }
                    e.Result = new object();
                };
                target.WorkerReportsProgress = true;
                target.ProgressChanged      += (o, e) =>
                {
                    numTimesProgressCalled++;
                    context.Assert.IsTrue(threadid == Thread.CurrentThread.ManagedThreadId);
                };
                target.RunWorkerCompleted += (o, e) =>
                {
                    context.Assert.IsTrue(threadid == Thread.CurrentThread.ManagedThreadId);
                    context.Assert.IsNull(e.Error);
                    context.Assert.IsTrue(numTimesProgressCalled == 10, "ReportProgress has been called 10 times");
                    context.Assert.Success();
                };
                target.RunWorkerAsync(null);
                context.Complete();
            }
        }