예제 #1
0
        private static void ClearDatabase()
        {
            using (SqlConnection conn = getConnection())
            {
                conn.Open();
                DatabaseManager mgr = new DatabaseManager(conn);
                mgr.LoadSchema();
                while (mgr.Tables.Count > 0)
                    mgr.DropTable(mgr.Tables[0], true);

                mgr.LoadSchema();
                Assert.AreEqual(0, mgr.Tables.Count);
            }
        }
예제 #2
0
        public void Test_DomainModelService_Merge()
        {
            var dm = new DomainModel();
            ModelBuilder ba = new ModelBuilder("Author");
            ba.AddIdentity("Id");
            ba.AddString("FirstName", 128);
            ba.AddString("LastName", 128);
            ba.AddComputed("FullName", "[LastName]+N', '+[FirstName]");
            ba.AddBoolean("IsAlive", true);
            ba.AddInteger("NumberOfAwards");
            ba.AddDateTime("Born");
            ba.AddDecimal("Rating");

            ModelBuilder bb = new ModelBuilder("Book");
            bb.AddIdentity("Id");
            bb.AddString("Title", 256);
            bb.AddString("ISBN", 20);
            bb.AddDecimal("Price");
            bb.AddEnum<Genre>("Genre", Genre.Fantasy);

            bb.Rules.AddRequired("title");
            bb.Rules.AddUnique("ISBN");

            ba.AddRelationTo(bb.EntityModel, RelationType.OneToMany, "Author");

            dm.Entities.Add(ba.EntityModel);
            dm.Entities.Add(bb.EntityModel);

            svc.Save(dm);
            using (var conn = new TestDatabaseService().GetSqlConnection())
            {
                conn.Open();
                DatabaseManager dbm = new DatabaseManager(conn);
                dbm.LoadSchema();
                var tableA = dbm.Tables.Find(t => t.Name == "Author");
                Assert.IsNotNull(tableA);
                var fnCol = tableA.Columns.Find(c => c.Name.Equals("FullName", StringComparison.InvariantCultureIgnoreCase));
                Assert.IsNotNull(fnCol);
            }

            ModelBuilder bo = new ModelBuilder("Order");
            bo.AddDecimal("Total");
            bo.AddBoolean("Paid");
            bo.AddDateTime("CreatedOn");
            bo.AddDateTime("ShipmentDate");
            bo.AddRelationTo(dm.Entities["book"], RelationType.ManyToMany, "Ordered");
            dm.Entities.Add(bo.EntityModel);

            ba.EntityModel.Properties.Remove(ba.EntityModel.Properties["IsAlive"]);
            (ba.EntityModel.Properties["LastName"] as StringPropertyModel).Length = 256;
            (ba.EntityModel.Properties["firstName"] as StringPropertyModel).Length = 256;
            (bb.EntityModel.Properties["genre"] as EnumPropertyModel).DefaultValue = Genre.Horror;
            ba.AddString("Nickname", 256);

            svc.Merge(dm);

            Assert.AreEqual(3, svc.Domain.Entities.Count);
            //foreach (var em1 in dm.Entities)
            //{
            //    var em2 = svc.Domain.Entities[em1.Name];
            //    Assert.AreEqual(em1.Properties.Count, em2.Properties.Count);
            //}
            //TODO-tests:finish domainmodelservice_merge test

            //Computed columns are droped and recreated when upgrading the columns in their computed definition
            using (var conn = new TestDatabaseService().GetSqlConnection())
            {
                conn.Open();
                DatabaseManager dbm = new DatabaseManager(conn);
                dbm.LoadSchema();
                var tableA = dbm.Tables.Find(t => t.Name == "Author");
                Assert.IsNotNull(tableA);
                var fnCol = tableA.Columns.Find(c => c.Name.Equals("FullName", StringComparison.InvariantCultureIgnoreCase));
                Assert.IsNotNull(fnCol);
            }
        }
예제 #3
0
        private static void ClearDatabase()
        {
            SqlConnectionStringBuilder b = new SqlConnectionStringBuilder();
            b.DataSource = "localhost";
            b.InitialCatalog = "TestingNbuLib";
            b.IntegratedSecurity = true;

            using (SqlConnection conn = new SqlConnection(b.ConnectionString))
            {
                conn.Open();
                DatabaseManager mgr = new DatabaseManager(conn);
                mgr.LoadSchema();
                while (mgr.Tables.Count > 0)
                    mgr.DropTable(mgr.Tables[0], true);

                mgr.LoadSchema();
                Assert.AreEqual(0, mgr.Tables.Count);
            }
        }
예제 #4
0
        public void Prepare()
        {
            SqlConnectionStringBuilder b = new SqlConnectionStringBuilder();
            b.DataSource = "localhost";
            b.InitialCatalog = "TestingNbuLib";
            b.IntegratedSecurity = true;

            using (SqlConnection conn = new SqlConnection(b.ConnectionString))
            {
                conn.Open();
                DatabaseManager mgr = new DatabaseManager(conn);
                mgr.LoadSchema();
                while (mgr.Tables.Count > 0)
                    mgr.DropTable(mgr.Tables[0], true);

                mgr.LoadSchema();
                Assert.AreEqual(0, mgr.Tables.Count);
            }

            svc = new DomainModelService(new TestDatabaseService(), new IDomainChangeListener[] { new EntityRepositoryDomainListener() });
            svc.Save(new DomainModel());
        }