Example #1
0
        public static void DeleteShouldDeleteChildren()
        {
            SqlClientRegistrar.Register <DaoReferenceObject>();

            DaoReferenceObject parent = new DaoReferenceObject();

            parent.StringProperty = "Parent_".RandomString(3);

            parent.Commit();

            var d1 = parent.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.AddNew();

            d1.Name = "".RandomString(3);

            var d2 = parent.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.AddNew();

            d2.Name = "".RandomString(3);

            parent.Commit();

            Expect.IsNotNull(d2.Id);

            DaoReferenceObject check = DaoReferenceObject.OneWhere(c => c.Id == parent.Id);
            DaoReferenceObjectWithForeignKey check2 = DaoReferenceObjectWithForeignKey.OneWhere(c => c.Id == d2.Id);

            Expect.AreEqual(2, check.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.Count);
            Expect.IsNotNull(check2);

            check.Delete();

            check2 = DaoReferenceObjectWithForeignKey.OneWhere(c => c.Id == d2.Id);
            Expect.IsNull(check2);
        }
Example #2
0
        public static void ChildCollectionShouldHaveCorrectValues()
        {
            SqlClientRegistrar.Register <DaoReferenceObject>();

            string childName = "Name_".RandomString(3);

            DaoReferenceObject d = new DaoReferenceObject();

            d.StringProperty = "".RandomString(8);
            d.Commit();

            var child = d.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.AddNew();

            child.Name = childName;

            d.Commit();

            d = DaoReferenceObject.OneWhere(f => f.Id == d.Id);

            Expect.AreEqual(1, d.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.Count);
            Expect.AreEqual(child.Name, d.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId[0].Name);

            child = DaoReferenceObjectWithForeignKey.OneWhere(f => f.Id == d.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId[0].Id);

            Expect.AreEqual(childName, child.Name);
            Expect.IsNotNull(child.DaoReferenceObjectOfDaoReferenceObjectId);
            Expect.AreEqual(child.DaoReferenceObjectOfDaoReferenceObjectId.Id, d.Id);
        }
Example #3
0
        public static void UpdateShouldOnlyUpdateOne()
        {
            SqlClientRegistrar.Register <DaoReferenceObject>();
            string             first  = "".RandomString(8);
            string             second = "".RandomString(4);
            DaoReferenceObject test   = new DaoReferenceObject();

            test.BoolProperty   = true;
            test.StringProperty = first;
            Expect.IsTrue(test.IsNew);
            test.Commit();

            DaoReferenceObject one = DaoReferenceObject.OneWhere(f => f.StringProperty == test.StringProperty);

            one.StringProperty = second;

            Expect.IsFalse(one.IsNew);
            one.Commit();

            DaoReferenceObjectCollection results = new DaoReferenceObjectCollection(
                Select <DaoReferenceObjectColumns>
                .From <DaoReferenceObject>()
                .Where(f => f.StringProperty == second));

            Expect.IsTrue(results.Count == 1);
        }
Example #4
0
        public static void QuerySetShouldFillIHasDataTableList()
        {
            SqlClientRegistrar.Register <DaoReferenceObject>();
            QuerySet testQuerySet = new QuerySet();

            Expect.IsNull(testQuerySet.DataSet);
            DaoReferenceObject test = new DaoReferenceObject();

            test.StringProperty = "".RandomString(8);
            test.Commit();

            testQuerySet.Select <DaoReferenceObjectColumns, DaoReferenceObject>(f => f.Id == test.Id);

            DaoReferenceObject dao = new DaoReferenceObject();

            dao.StringProperty = "".RandomString(5);

            testQuerySet.Insert <DaoReferenceObject>(dao);

            testQuerySet.Execute(Db.For <DaoReferenceObject>());

            Expect.IsNotNull(testQuerySet.DataSet);
            Expect.IsTrue(testQuerySet.DataSet.Tables.Count == 2);
            Expect.IsGreaterThan(testQuerySet.Results.Count, 0);
            Expect.AreEqual(2, testQuerySet.Results.Count);

            DaoReferenceObject d = testQuerySet.Results.ToDao <DaoReferenceObject>(1);

            Expect.AreEqual(dao.StringProperty, d.StringProperty);

            DaoReferenceObjectCollection coll = testQuerySet.Results.As <DaoReferenceObjectCollection>(0);

            Expect.IsNotNull(coll);
            Expect.IsGreaterThan(coll.Count, 0);
        }
Example #5
0
        private static DaoReferenceObject Create()
        {
            DaoReferenceObject test = new DaoReferenceObject();

            test.StringProperty = "".RandomString(8);
            test.Commit();
            return(test);
        }
Example #6
0
        public static void CommitOnCollectionShouldUpdateIds()
        {
            SqlClientRegistrar.Register <DaoReferenceObject>();

            string childName = "Name_".RandomString(3);

            DaoReferenceObject d = new DaoReferenceObject();

            d.StringProperty = "".RandomString(8);
            d.Commit();

            var child = d.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.AddNew();

            child.Name = childName;

            d.Commit();

            Expect.IsNotNull(child.IdValue);
        }
Example #7
0
        public static void ChildSetsShouldBeFull()
        {
            SqlClientRegistrar.Register <DaoReferenceObject>();
            DaoReferenceObject parent = new DaoReferenceObject();

            parent.StringProperty = "Parent";
            parent.Commit();

            DaoReferenceObjectWithForeignKey child = parent.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.AddNew();

            child.Name = "Monkey";

            parent.Commit();

            Expect.IsNotNull(child.Id);

            DaoReferenceObject check = DaoReferenceObject.OneWhere(c => c.Id == parent.Id);

            Expect.IsNotNull(check);
            Expect.AreEqual(1, check.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.Count);
        }
Example #8
0
        public static void WhereShortCutShouldWork()
        {
            SqlClientRegistrar.Register(Db.For <DaoReferenceObject>().ServiceProvider);

            DaoReferenceObject test = new DaoReferenceObject();

            test.StringProperty = "".RandomString(8);
            test.Commit();

            DaoReferenceObjectCollection checking = DaoReferenceObject.Where(c => c.StringProperty == test.StringProperty);

            Expect.IsTrue(checking.Count == 1);
        }
Example #9
0
        public static void CommitParentShouldCallCommitOnCollections()
        {
            SqlClientRegistrar.Register <DaoReferenceObject>();
            DaoReferenceObject d = new DaoReferenceObject();

            d.StringProperty = "".RandomString(8);
            d.Commit();

            var child = d.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.AddNew();

            child.Name = "Name_".RandomString(3);

            bool?handled = false;

            child.BeforeWriteCommit += (a, i) =>
            {
                handled = true;
            };

            d.Commit();
            Expect.IsTrue(handled.Value);
        }
Example #10
0
        public static void ParentOfCollectionShouldBeRootDao()
        {
            SqlClientRegistrar.Register(Db.For <DaoReferenceObject>().ServiceProvider);

            DaoReferenceObject d = new DaoReferenceObject();

            d.StringProperty = "".RandomString(8);
            d.Commit();

            DaoReferenceObjectWithForeignKey dfk = d.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.AddNew();

            Expect.AreSame(d, d.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.Parent);
        }
Example #11
0
        public static void ShortcutShouldWorkLikeLongcut()
        {
            SqlClientRegistrar.Register(Db.For <DaoReferenceObject>().ServiceProvider);

            DaoReferenceObject test = new DaoReferenceObject();
            string             val  = "".RandomString(8);

            test.StringProperty = val;
            test.Commit();
            DaoReferenceObjectCollection results = DaoReferenceObject.Where(f => f.Id == test.Id);

            Expect.IsTrue(results.Count > 0);
            Expect.IsTrue(results[0].StringProperty.Equals(val));
        }
Example #12
0
        public static void CommitShouldSetId()
        {
            SqlClientRegistrar.Register(Db.For <DaoReferenceObject>().ServiceProvider);

            DaoReferenceObject test = new DaoReferenceObject();

            test.BoolProperty    = true;
            test.DecimalProperty = (decimal)10.00;
            test.StringProperty  = "".RandomString(8);

            Expect.IsNull(test.Id);
            test.Commit();
            Expect.IsNotNull(test.Id);
            OutFormat("The id was {0}", test.Id);
        }
Example #13
0
        public static void AddShouldSetAssociation()
        {
            SqlClientRegistrar.Register(Db.For <DaoReferenceObject>().ServiceProvider);

            DaoReferenceObject d = new DaoReferenceObject();

            d.StringProperty = "".RandomString(8);
            d.Commit();

            DaoReferenceObjectWithForeignKey test = new DaoReferenceObjectWithForeignKey();

            Expect.IsNull(test.DaoReferenceObjectId);
            d.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.Add(test);
            Expect.IsNotNull(test.DaoReferenceObjectId);

            Expect.AreEqual(test.DaoReferenceObjectId, d.Id);
        }
Example #14
0
        public static void DeleteShouldWork()
        {
            SqlClientRegistrar.Register(Db.For <DaoReferenceObject>().ServiceProvider);

            DaoReferenceObject test = new DaoReferenceObject();

            test.StringProperty = "".RandomString(8);
            test.Commit();

            DaoReferenceObject d = DaoReferenceObject.OneWhere(c => c.Id == test.Id);

            Expect.IsNotNull(d);
            Expect.AreEqual(test.StringProperty, d.StringProperty);

            d.Delete();

            d = DaoReferenceObject.OneWhere(c => c.StringProperty == test.StringProperty);
            Expect.IsNull(d);
        }
Example #15
0
        public static void ShouldBeAbleToQueryById()
        {
            SqlClientRegistrar.Register(Db.For <DaoReferenceObject>().ServiceProvider);

            DaoReferenceObject test = new DaoReferenceObject();

            string val = "".RandomString(8);

            test.StringProperty = val;
            test.Commit();

            DaoCollection <DaoReferenceObjectColumns, DaoReferenceObject> results = new DaoCollection <DaoReferenceObjectColumns, DaoReferenceObject>(
                Select <DaoReferenceObjectColumns>
                .From <DaoReferenceObject>()
                .Where((c) => c.Id == test.Id)
                );

            Expect.IsNotNull(results);
            Expect.IsTrue(results.Count == 1);
            Expect.AreEqual(results[0].StringProperty, val);
        }
Example #16
0
        public static void UnCommittedParentShouldThrowOnChildAdd()
        {
            bool thrown = false;

            try
            {
                SqlClientRegistrar.Register <DaoReferenceObject>();
                DaoReferenceObject parent = new DaoReferenceObject();
                parent.StringProperty = "Parent";
                DaoReferenceObjectWithForeignKey child = parent.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.AddNew();
                child.Name = "".RandomString(8);

                parent.Commit();
            }
            catch (InvalidOperationException ioe)
            {
                thrown = true;
                Out(ioe.Message, ConsoleColor.Cyan);
            }

            Expect.IsTrue(thrown);
        }