Example #1
0
 public static SqlModelDescription <GroupUser> GroupUser()
 {
     return(SqlModelDescription <GroupUser>
            .Auto("core", "groupUsers")
            .WithPrimaryKey(p => p.GroupId)
            .WithPrimaryKey(p => p.UserId));
 }
Example #2
0
        public void Auto_Registers_Inherited_Property()
        {
            var description = SqlModelDescription <Cat> .Auto("schema", "cats");

            description.Property(c => c.Id).Should().NotBeNull();
            description.Property(c => c.Name).Should().NotBeNull();
        }
Example #3
0
        public void RegisterModelScription_Can_Register_Single_ModelDescription()
        {
            var validContext = GetValidContext();

            validContext.RegisterModelDescription(SqlModelDescription <TypeA> .Auto("schema", "typeA"));

            validContext.GetModelDescription <TypeA>().Should().NotBeNull();
        }
Example #4
0
        public void RegisterModelScription_Can_Not_Register_Duplicate_ModelDescription()
        {
            var validContext = GetValidContext();

            validContext.RegisterModelDescription(SqlModelDescription <TypeA> .Auto("schema", "typeA"));

            Assert.Throws <TypeAlreadyRegisteredException>(
                () => validContext.RegisterModelDescription(SqlModelDescription <TypeA> .Auto("schema", "typeA")));
        }
Example #5
0
 /// <summary>
 /// Registers the specified model description.
 /// </summary>
 /// <typeparam name="T">Type of the model</typeparam>
 /// <param name="modelDescription">The actual model description</param>
 public void RegisterModelDescription <T>(SqlModelDescription <T> modelDescription)
 {
     if (this.GetModelDescription <T>() == null)
     {
         this.ModelDescriptions.Add(modelDescription);
     }
     else
     {
         throw new TypeAlreadyRegisteredException(
                   $"Type {typeof(T)} is already registerd.");
     }
 }
Example #6
0
        public void SelectCommand_Can_Build_Command_With_Where_Clause()
        {
            string schema    = "core";
            string tableName = "typeCs";

            var validContext = GetValidContext();

            validContext.RegisterModelDescription(SqlModelDescription <TypeC> .Auto(schema, tableName));

            string command = validContext.SelectCommand <TypeC>("Id = @Id");

            command.Should().Be($"SELECT * FROM [{schema}].[{tableName}] WHERE Id = @Id;");
        }
Example #7
0
        public void InsertCommand_Can_Build_Command()
        {
            string tableName = "typeCs";
            string schema    = "core";

            var validContext = GetValidContext();

            validContext.RegisterModelDescription(SqlModelDescription <TypeC> .Auto(schema, tableName));

            string command = validContext.InsertCommand <TypeC>();

            command.Should().Be($"INSERT INTO [{schema}].[{tableName}] ([integer], [name]) OUTPUT inserted.id VALUES (@Integer, @Name);");
        }
Example #8
0
        public void UpdateCommand_Can_Build_Command()
        {
            string schema      = "core";
            string table       = "typeCs";
            string whereClause = "id = @Id";

            var validContext = GetValidContext();

            validContext.RegisterModelDescription(SqlModelDescription <TypeC> .Auto(schema, table));

            var command = validContext.UpdateCommand <TypeC>(whereClause);

            command.Should().Be($"UPDATE [{schema}].[{table}] SET [integer] = @Integer, [name] = @Name WHERE {whereClause};");
        }
Example #9
0
        public void GetModelDescription_Can_Find_ModelDescription()
        {
            var validContext = GetValidContext();

            var descriptionTypeA = SqlModelDescription <TypeA> .Auto("core", "typeAs");

            var descriptionTypeB = SqlModelDescription <TypeB> .Auto("core", "typeBs");

            validContext.RegisterModelDescription(descriptionTypeA);
            validContext.RegisterModelDescription(descriptionTypeB);

            validContext.GetModelDescription <TypeA>().ShouldBeEquivalentTo(descriptionTypeA);
            validContext.GetModelDescription <TypeB>().ShouldBeEquivalentTo(descriptionTypeB);
        }
Example #10
0
        public void DeleteCommand_Can_Build_Command()
        {
            string schema      = "core";
            string table       = "typeCs";
            string whereClause = "id = @Id";

            var validContext = GetValidContext();

            validContext.RegisterModelDescription(SqlModelDescription <TypeC> .Auto(schema, table));

            var command = validContext.DeleteCommand <TypeC>(whereClause);

            command.Should().BeEquivalentTo($"DELETE FROM [{schema}].[{table}] WHERE {whereClause};");
        }
Example #11
0
        public void Auto_Registers_Simple_Property()
        {
            var description = SqlModelDescription <Cat> .Auto("core", "cats");

            description.Property(c => c.Title).Should().NotBeNull();
        }
Example #12
0
 public static SqlModelDescription <User> User()
 {
     return(SqlModelDescription <User>
            .Auto("core", "users")
            .WithReadOnly(u => u.UserName));
 }
Example #13
0
 public static SqlModelDescription <BankAccount> BankAccount()
 {
     return(SqlModelDescription <BankAccount>
            .Auto("core", "bankAccounts"));
 }
Example #14
0
 public static SqlModelDescription <Transaction> Transaction()
 {
     return(SqlModelDescription <Transaction>
            .Auto("core", "transactions"));
 }
Example #15
0
        public void Auto_Ignores_ReadOnly_Properties()
        {
            var description = SqlModelDescription <Cat> .Auto("schema", "cats");

            description.Property(p => p.IsGrumpy).Should().BeNull();
        }
Example #16
0
 public static SqlModelDescription <Group> Group()
 {
     return(SqlModelDescription <Group>
            .Auto("core", "groups"));
 }
Example #17
0
 public static SqlModelDescription <Category> Category()
 {
     return(SqlModelDescription <Category>
            .Auto("core", "categories"));
 }
Example #18
0
        public void GetProperty_Finds_Property()
        {
            var description = SqlModelDescription <Cat> .Auto("core", "cats");

            description.Property(p => p.Name).Should().NotBeNull();
        }