Example #1
0
        public void QueryBuilder_ShouldMapProperty()
        {
            var builder = new MockSqlQueryBuilder <Customer>();

            builder.MapProperty(c => c.FirstName, "FName");
            builder.GetResult();
            Assert.True(builder.InternalProps.PropertyMappings.First(pm => pm.PropertyName == "FirstName").ColumnName == "FName");
        }
Example #2
0
        public void QueryBuilder_ShouldSetIgnoreDataColumnNotFound()
        {
            var builder = new MockSqlQueryBuilder <Customer>();

            builder.SetIgnoreDataColumnNotFound(false);
            builder.GetResult();
            Assert.False(builder.InternalProps.IgnoreDataColumnNotFound);
        }
Example #3
0
        public void QueryBuilder_ShouldSetCommandTimeout()
        {
            var builder = new MockSqlQueryBuilder <Customer>();

            builder.SetCommandTimeout(300);
            builder.GetResult();
            Assert.True(builder.InternalProps.CommandTimeout == 300);
        }
Example #4
0
        public void QueryBuilder_ShouldAddParameterWithDirection()
        {
            var builder = new MockSqlQueryBuilder <Customer>();

            builder.AddParameter("@test", "testValue", QueryParameterDirectionEnum.Output);
            builder.GetResult();
            Assert.True(builder.InternalProps.Parameters.Cast <QueryParameter>().First(p => p.Name == "@test").Direction == QueryParameterDirectionEnum.Output);
        }
Example #5
0
        public void QueryBuilder_ShouldAddParameterWhenConditionIsTrue()
        {
            var builder = new MockSqlQueryBuilder <Customer>();

            builder.AddParameter(() => true, "@test", "testValue");
            builder.GetResult();
            Assert.True(builder.InternalProps.Parameters.Cast <QueryParameter>().First(p => p.Name == "@test").Value == "testValue");
        }
Example #6
0
        public void QueryBuilder_ShouldSetConnectionString()
        {
            var connString = "Some Connection String";
            var builder    = new MockSqlQueryBuilder <Customer>();

            builder.SetConnectionString(connString);
            builder.GetResult();
            Assert.True(builder.InternalProps.ConnString == connString);
        }
Example #7
0
        public void QueryBuilder_ShouldNotAddParameterWhenConditionIsFalse()
        {
            var builder = new MockSqlQueryBuilder <Customer>();

            builder.AddParameter(() => true, "@testTrue", "testValue");
            builder.AddParameter(() => false, "@testFalse", "testValue");
            builder.GetResult();
            Assert.True(builder.InternalProps.Parameters.Cast <QueryParameter>().Any(p => p.Name == "@testFalse") == false);
        }
Example #8
0
        public void QueryBuilder_ShouldSetStoredProcedure()
        {
            var storedProcName = "someStoredProc";
            var builder        = new MockSqlQueryBuilder <Customer>();

            builder.SetStoredProcedure(storedProcName);
            builder.GetResult();
            Assert.True(builder.InternalProps.CommandType == CommandType.StoredProcedure);
            Assert.True(builder.InternalProps.CommandText == storedProcName);
        }
Example #9
0
        public void QueryBuilder_ShouldSetSql()
        {
            var sql     = "select someThing from someTable";
            var builder = new MockSqlQueryBuilder <Customer>();

            builder.SetSql(sql);
            builder.GetResult();
            Assert.True(builder.InternalProps.CommandType == CommandType.Text);
            Assert.True(builder.InternalProps.CommandText == sql);
        }
Example #10
0
        public void QueryBuilder_ShouldAddQueryParameter_Char()
        {
            var builder = new MockSqlQueryBuilder <Customer>();

            builder.AddParameter(new QueryParameter {
                Name = "@test", Value = "testValue", DataType = DataTypeEnum.Char, Size = 10
            });
            builder.GetResult();
            Assert.True(builder.InternalProps.Parameters.Cast <QueryParameter>().First(p => p.Name == "@test" && p.DataType == DataTypeEnum.Char && p.Size == 10).Value == "testValue");
        }
Example #11
0
        public void QueryBuilder_ShouldMapPropertyFunction()
        {
            var dataRow = new DataValueList();

            dataRow.Add(new DataValue
            {
                ColumnName = "FName",
                Value      = "Joe"
            });
            var builder = new MockSqlQueryBuilder <Customer>();

            builder.MapProperty(c => c.FirstName, row => row.GetString("FName"));
            builder.GetResult();
            Assert.True(builder.InternalProps.PropertyMappings.First(pm => pm.PropertyName == "FirstName").PropertyMapperDataRow(dataRow) == "Joe");
        }
Example #12
0
        public void QueryBuilder_ShouldMapObject()
        {
            var dataRow = new DataValueList();

            dataRow.Add(new DataValue
            {
                ColumnName = "FName",
                Value      = "Joe"
            });
            var builder = new MockSqlQueryBuilder <Customer>();

            builder.MapObject(row => new Customer {
                FirstName = row.GetString("FName")
            });
            builder.GetResult();
            Assert.True(builder.InternalProps.DataRowMapper(dataRow).FirstName == "Joe");
        }