public void CreateDefinitionWithAuditPropertiesForLibraryEntities()
        {
            // Arrange
            var db = SqlServerDatabase.CreateWithDefaults("Library");

            db.AddDefaultTypeMapFor(typeof(string), "nvarchar");

            // Act
            var book = db
                       .DefineEntity(new
            {
                Id     = 0,
                Name   = "",
                Author = "",
                Year   = (short)0
            })
                       .SetNaming("Book")
                       .SetColumnFor(e => e.Name, length: 100)
                       .SetColumnFor(e => e.Author, length: 25)
                       .SetIdentity(e => e.Id)
                       .SetPrimaryKey(e => e.Id)
            ;

            var stock = db
                        .DefineEntity(new
            {
                Id       = 0,
                BookId   = 0,
                Quantity = 0
            })
                        .SetNaming("Stock")
                        .SetIdentity(e => e.Id)
                        .SetPrimaryKey(e => e.Id)
                        .AddForeignKey(e => e.BookId, book.Table)
            ;

            db.AddColumnForTables(new Column {
                Name = "CreationUser", Type = "nvarchar", Length = 25
            });
            db.AddColumnForTables(new Column {
                Name = "CreationDate", Type = "datetime"
            });

            // Assert
            Assert.True(db.FindTable("dbo.Book").Columns.Count == 6);
            Assert.True(db.FindTable("dbo.Stock").Columns.Count == 5);
        }
Example #2
0
        public void ExportCollegeScript()
        {
            // Arrange
            var database = SqlServerDatabase.CreateWithDefaults("College");

            database.AddDefaultTypeMapFor(typeof(string), "nvarchar");

            var student = database
                          .DefineEntity(new { StudentId = 0, FirstName = "", MiddleName = "", LastName = "" })
                          .SetNaming("Student")
                          .SetColumnFor(p => p.FirstName, length: 15)
                          .SetColumnFor(p => p.MiddleName, length: 15, nullable: true)
                          .SetColumnFor(p => p.LastName, length: 15)
                          .SetIdentity(p => p.StudentId)
                          .SetPrimaryKey(e => e.StudentId)
                          .AddExtendedProperty(p => p.FirstName, "MS_Description", "First name")
                          .AddExtendedProperty(p => p.MiddleName, "MS_Description", "Middle name")
                          .AddExtendedProperty(p => p.LastName, "MS_Description", "Last name");

            student.Data.Add(new { StudentId = 0, FirstName = "Carlo", MiddleName = "H", LastName = "Herzl" });

            // todo: add sql transcriber => translate results from select to code (c#)

            var course = database
                         .DefineEntity(new { CourseId = 0, Name = "" })
                         .SetNaming("Course")
                         .SetColumnFor(e => e.Name, length: 255)
                         .SetIdentity(e => e.CourseId, seed: 1000, increment: 1000)
                         .SetPrimaryKey(e => e.CourseId)
                         .AddUnique(e => e.Name);

            var courseStudent = database
                                .DefineEntity(new { CourseStudentId = 0, CourseId = 0, StudentId = 0 })
                                .SetNaming("CourseStudent")
                                .SetIdentity(p => p.CourseStudentId)
                                .SetPrimaryKey(p => p.CourseStudentId)
                                .AddUnique(p => new { p.CourseId, p.StudentId })
                                .AddForeignKey(p => p.CourseId, course.Table)
                                .AddForeignKey(p => p.StudentId, student.Table);

            // Act

            SqlServerDatabaseScriptCodeBuilder.CreateScript(database, @"C:\Temp\CatFactory.SqlServer", true, true);

            // Assert
        }
Example #3
0
        public void CreateDefinitionForCMSEntities()
        {
            // Arrange
            var database = SqlServerDatabase.CreateWithDefaults("CMS");

            database.AddDefaultTypeMapFor(typeof(string), "nvarchar");

            // Act
            var blog = database
                       .DefineEntity(new { BlogId = (short)0, Name = "" })
                       .SetNaming("Blog", "WebSite")
                       .SetColumnFor(e => e.Name, length: 100)
                       .SetIdentity(e => e.BlogId)
                       .SetPrimaryKey(e => e.BlogId)
            ;

            var post = database
                       .DefineEntity(new { PostId = 0, BlogId = (short)0, Title = "", Content = "" })
                       .SetNaming("Post", "WebSite")
                       .SetColumnFor(e => e.Title, length: 100)
                       .SetIdentity(e => e.BlogId)
                       .SetPrimaryKey(e => e.BlogId)
                       .AddForeignKey(e => e.BlogId, blog.Table)
            ;

            // Assert
            Assert.True(database.DbObjects.Count == 2);
            Assert.True(database.Tables.Count == 2);

            Assert.True(blog.Table.Columns.Count == 2);
            Assert.False(blog.Table.PrimaryKey == null);
            Assert.False(blog.Table.Identity == null);
            Assert.True(blog.Table["Name"].Length == 100);

            Assert.True(post.Table.Columns.Count == 4);
            Assert.False(post.Table.PrimaryKey == null);
            Assert.False(post.Table.Identity == null);
            Assert.True(post.Table["Title"].Length == 100);
            Assert.True(post.Table["Content"].Length == 0);
        }
Example #4
0
        public void CreateDefinitionForCollegeEntities()
        {
            // Arrange
            var database = SqlServerDatabase.CreateWithDefaults("College");

            database.AddDefaultTypeMapFor(typeof(string), "nvarchar");

            // Act
            var student = database
                          .DefineEntity(new { StudentId = 0, FirstName = "", MiddleName = "", LastName = "", Gender = "" })
                          .SetNaming("Student")
                          .SetColumnFor(e => e.FirstName, length: 10)
                          .SetColumnFor(e => e.MiddleName, length: 10, nullable: true)
                          .SetColumnFor(e => e.LastName, length: 10)
                          .SetColumnFor(e => e.Gender, length: 1)
                          .SetIdentity(e => e.StudentId)
                          .SetPrimaryKey(e => e.StudentId)
            ;

            student
            .AddExtendedProperty(e => e.FirstName, "MS_Description", "First name")
            .AddExtendedProperty(e => e.MiddleName, "MS_Description", "Middle name")
            .AddExtendedProperty(e => e.LastName, "MS_Description", "Last name")
            ;

            var course = database
                         .DefineEntity(new { CourseId = 0, Name = "" })
                         .SetNaming("Course")
                         .SetColumnFor(e => e.Name, type: "nvarchar", length: 255)
                         .SetIdentity(e => e.CourseId)
                         .SetPrimaryKey(e => e.CourseId)
                         .AddUnique(e => e.Name)
            ;

            course
            .AddExtendedProperty(e => e.Name, "MS_Description", "Course name")
            ;

            var courseStudent = database
                                .DefineEntity(new { CourseStudentId = 0, CourseId = 0, StudentId = 0 })
                                .SetNaming("CourseStudent")
                                .SetIdentity(e => e.CourseStudentId)
                                .SetPrimaryKey(e => e.CourseStudentId)
                                .AddUnique(e => new { e.CourseId, e.StudentId })
                                .AddForeignKey(e => e.CourseId, course.Table)
                                .AddForeignKey(e => e.StudentId, student.Table)
            ;

            courseStudent
            .AddExtendedProperty(e => e.CourseId, "MS_Description", "Course Id")
            .AddExtendedProperty(e => e.CourseId, "MS_Description", "Student Id")
            ;

            // Assert
            Assert.True(database.DbObjects.Count == 3);
            Assert.True(database.Tables.Count == 3);

            Assert.True(database.DbObjects[0].FullName == "dbo.Student");
            Assert.True(database.DbObjects[1].FullName == "dbo.Course");
            Assert.True(database.DbObjects[2].FullName == "dbo.CourseStudent");

            Assert.True(database.FindTable("dbo.Student").Columns.Count == 5);
            Assert.False(database.FindTable("dbo.Student").Identity == null);
            Assert.False(database.FindTable("dbo.Student").PrimaryKey == null);
            Assert.True(database.FindTable("dbo.Student")["MiddleName"].ImportBag.ExtendedProperties.Count == 1);

            Assert.True(database.FindTable("dbo.Course").Columns.Count == 2);
            Assert.False(database.FindTable("dbo.Course").Identity == null);
            Assert.False(database.FindTable("dbo.Course").PrimaryKey == null);
            Assert.True(database.FindTable("dbo.Course").Uniques.Count == 1);

            Assert.True(database.FindTable("dbo.CourseStudent").Columns.Count == 3);
            Assert.False(database.FindTable("dbo.CourseStudent").Identity == null);
            Assert.False(database.FindTable("dbo.CourseStudent").PrimaryKey == null);

            Assert.True(student.Table.Columns.Count == 5);
            Assert.False(student.Table.PrimaryKey == null);
            Assert.False(student.Table.Identity == null);

            Assert.True(course.Table.Columns.Count == 2);
            Assert.False(course.Table.PrimaryKey == null);
            Assert.False(course.Table.Identity == null);

            Assert.True(courseStudent.Table.Columns.Count == 3);
            Assert.False(courseStudent.Table.PrimaryKey == null);
            Assert.False(courseStudent.Table.PrimaryKey.Key.Count == 2);
            Assert.False(courseStudent.Table.Identity == null);
        }
Example #5
0
        public void ExportDefinitionForRothschildHouseEntities()
        {
            // Arrange
            var database = SqlServerDatabase.CreateWithDefaults("RothschildHouse");

            database.ExtendedProperties.Add(new ExtendedProperty("MS_Description", "Database to storage RothschildHouse payments"));

            database.AddDefaultTypeMapFor(typeof(string), "nvarchar");

            var person = database
                         .DefineEntity(new
            {
                PersonID   = Guid.Empty,
                GivenName  = "",
                MiddleName = "",
                FamilyName = "",
                FullName   = "",
                BirthDate  = DateTime.Now
            })
                         .SetNaming("Person", "People")
                         .SetColumnFor(p => p.GivenName, length: 10)
                         .SetColumnFor(p => p.MiddleName, length: 10, nullable: true)
                         .SetColumnFor(p => p.FamilyName, length: 10)
                         .SetColumnFor(p => p.FullName, length: 30)
                         .SetPrimaryKey(p => p.PersonID)
                         .AddExtendedProperty("MS_Description", "Person catalog")
                         .AddExtendedProperty(p => p.GivenName, "MS_Description", "Given name")
                         .AddExtendedProperty(p => p.MiddleName, "MS_Description", "Middle name")
                         .AddExtendedProperty(p => p.FamilyName, "MS_Description", "Family name")
                         .AddExtendedProperty(p => p.FullName, "MS_Description", "Full name")
                         .AddExtendedProperty(p => p.BirthDate, "MS_Description", "Birth date");

            var creditCard = database
                             .DefineEntity(new
            {
                CreditCardID   = Guid.Empty,
                PersonID       = Guid.Empty,
                CardType       = "",
                CardNumber     = "",
                Last4Digits    = "",
                ExpirationDate = DateTime.Now,
                Cvv            = ""
            })
                             .SetNaming("CreditCard", "Payment")
                             .SetColumnFor(p => p.CardType, type: "nvarchar", length: 20)
                             .SetColumnFor(p => p.CardNumber, type: "nvarchar", length: 20)
                             .SetColumnFor(p => p.Last4Digits, type: "nvarchar", length: 4)
                             .SetColumnFor(p => p.Cvv, type: "nvarchar", length: 4)
                             .SetPrimaryKey(p => p.CreditCardID)
                             .AddUnique(p => p.CardNumber)
                             .AddForeignKey(p => p.PersonID, person.Table)
                             .AddExtendedProperty(p => p.PersonID, "MS_Description", "Person Identifier")
                             .AddExtendedProperty(p => p.CardType, "MS_Description", "Card type")
                             .AddExtendedProperty(p => p.CardNumber, "MS_Description", "Card number")
                             .AddExtendedProperty(p => p.Last4Digits, "MS_Description", "Last 4 Digits")
                             .AddExtendedProperty(p => p.ExpirationDate, "MS_Description", "Expiration Date")
                             .AddExtendedProperty(p => p.Cvv, "MS_Description", "Card Verification Value");

            var paymentTransaction = database
                                     .DefineEntity(new
            {
                PaymentTransactionID = Guid.Empty,
                CreditCardID         = Guid.Empty,
                ConfirmationID       = Guid.Empty,
                Amount          = 0m,
                PaymentDateTime = DateTime.Now
            })
                                     .SetNaming("PaymentTransaction", "Payment")
                                     .SetColumnFor(p => p.Amount, prec: 10, scale: 4)
                                     .SetPrimaryKey(p => p.CreditCardID)
                                     .AddForeignKey(p => p.CreditCardID, creditCard.Table)
                                     .AddExtendedProperty(p => p.PaymentTransactionID, "MS_Description", "Payment Transaction Identifier")
                                     .AddExtendedProperty(p => p.CreditCardID, "MS_Description", "Credit Card Identifier")
                                     .AddExtendedProperty(p => p.ConfirmationID, "MS_Description", "Confirmation Identifier")
                                     .AddExtendedProperty(p => p.Amount, "MS_Description", "Transaction Amount")
                                     .AddExtendedProperty(p => p.PaymentDateTime, "MS_Description", "Payment Date time");

            // Act

            SqlServerDatabaseScriptCodeBuilder.CreateScript(database, @"C:\Temp\CatFactory.SqlServer", true);
        }