Ejemplo n.º 1
0
        public void Build_update_statment_with_several_where()
        {
            string verify  = "UPDATE [faketable] SET [col1] = $col1, [col2] = $col2, [col3] = $col3 WHERE [col1] = $qPm0 AND [col2] >= $qPm1 OR [col3] = [col1]";
            var    columns = new List <string>()
            {
                "col1", "col2", "col3"
            };
            var parameters = new List <QueryParam>
            {
                new QueryParam("col1", null),
                new QueryParam("col2", null),
                new QueryParam("col3", null)
            };
            var builder = new UpdateSqlBuilder("faketable", session, columns, parameters);

            builder.Where("col1").EqualToValue(1)
            .And("col2").GreaterOrEqualToValue(10)
            .Or("col3").EqualTo("col1");

            var sqlBody = builder.Build();
            var res     = sqlBody.ToString(session.SessionFactory.DbSettings.SqlDialect);

            Console.WriteLine(res);
            Assert.AreEqual(verify, res);
        }
Ejemplo n.º 2
0
        public void Build_statement_with_no_where_should_throw()
        {
            var columns = new List <string>()
            {
                "col1", "col2", "col3"
            };
            var parameters = new List <QueryParam>
            {
                new QueryParam("col1", null),
                new QueryParam("col2", null),
                new QueryParam("col3", null)
            };
            var builder = new UpdateSqlBuilder("faketable", session, columns, parameters);

            Assert.Throws <DataAccessException>(() => builder.Build());
        }
Ejemplo n.º 3
0
        public void Load_should_load_all_properties_even_parent_class()
        {
            Monkey monkey = new Monkey()
            {
                Id          = 1,
                Name        = "shaker",
                Age         = 2,
                Family      = "unknown",
                CanDoTricks = true,
                Location    = "XER3",
                ReceivedOn  = DateTime.Now
            };

            UpdateSqlBuilder <Monkey> builder = new UpdateSqlBuilder <Monkey>(session, monkey);
            var build = builder.Build();

            Assert.AreEqual(2, build.Statements.Count);
        }