Esempio n. 1
0
        public void BuildUpdate_Foreach_Entity_with_where()
        {
            //Arrange
            List <Entity_Lamda_To_Sql> list = new List <Entity_Lamda_To_Sql>();

            for (var i = 0; i < 2; i++)
            {
                Entity_Lamda_To_Sql entity = new Entity_Lamda_To_Sql()
                {
                    Id            = i,
                    Code          = "100" + i.ToString(),
                    TotalAmount   = 125.6m,
                    TotalQuantity = 10,
                    PaidTime      = DateTime.Parse("2018-02-02"),
                    Status        = OrderStatus.Paid
                };
                list.Add(entity);
            }

            list.ForEach(item =>
            {
                Expression <Func <Entity_Lamda_To_Sql, bool> > where = n => n.Status == OrderStatus.WaitToPay && n.Id == item.Id;
                //Action
                object args = new object();
                var actual  = _builder.BuildUpdate <Entity_Lamda_To_Sql>(new Entity_Lamda_To_Sql()
                {
                    Status = OrderStatus.Create, Code = item.Code
                }, where, out args).Trim();

                var expected = "UPDATE [Order] SET [Code] = @Code,[Total_Amount] = @Total_Amount,[TotalQuantity] = @TotalQuantity,[PaidTime] = @PaidTime,[Status] = @Status WHERE [Status] = @P1 AND [Id] = @P0";

                // Assert
                Assert.AreEqual(expected, actual);
            });
        }
Esempio n. 2
0
        public void BuildUpdate_Entity_with_where()
        {
            //Arrange
            Entity_Lamda_To_Sql entity = new Entity_Lamda_To_Sql()
            {
                Id            = 1,
                Code          = "123",
                TotalAmount   = 125.6m,
                TotalQuantity = 10,
                PaidTime      = DateTime.Parse("2018-02-02"),
                Status        = OrderStatus.Paid
            };

            Expression <Func <Entity_Lamda_To_Sql, bool> > where = n => n.Status == OrderStatus.WaitToPay && n.Id == 1;
            //Action
            object args   = new object();
            var    actual = _builder.BuildUpdate <Entity_Lamda_To_Sql>(entity, where, out args).Trim();

            var expected = "UPDATE [Order] SET [Code] = @Code,[Total_Amount] = @Total_Amount,[TotalQuantity] = @TotalQuantity,[PaidTime] = @PaidTime,[Status] = @Status WHERE [Status] = @P1 AND [Id] = @P0";

            // Assert
            Assert.AreEqual(expected, actual);
            var dd = (Dictionary <string, object>)args;

            Assert.AreEqual(1, dd["@P0"]);
            Assert.AreEqual(1, dd["@P1"]);

            Assert.AreEqual("123", dd["@Code"]);
            Assert.AreEqual(125.6m, dd["@Total_Amount"]);
            Assert.AreEqual(10, dd["@TotalQuantity"]);
            Assert.AreEqual(DateTime.Parse("2018-02-02"), dd["@PaidTime"]);
            Assert.AreEqual(2, dd["@Status"]);
        }
Esempio n. 3
0
        public void Build_One_Object_Datetime_Now()
        {
            //Arrange
            // Entity_Lamda_To_Sql model = new Entity_Lamda_To_Sql();
            Entity_Lamda_To_Sql model = new Entity_Lamda_To_Sql();
            Expression <Func <Entity_Lamda_To_Sql, bool> > predicate = i => i.PaidTime == DateTime.Now;
            Dictionary <string, object> args = new Dictionary <string, object>();
            //Action
            var actual = _builder.BuildWhere(predicate, out args).Trim();
            // Assert
            var expected = "[PaidTime] = @P0";

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ((DateTime)args["@P0"]).ToString("yyyy-MM-dd HH:mm:ss"));
        }
Esempio n. 4
0
        public void Build_One_Object_Method()
        {
            //Arrange
            // Entity_Lamda_To_Sql model = new Entity_Lamda_To_Sql();
            Entity_Lamda_To_Sql model = new Entity_Lamda_To_Sql();
            Expression <Func <Entity_Lamda_To_Sql, bool> > predicate = i => i.PaidTime == model.GetTime();
            Dictionary <string, object> args = new Dictionary <string, object>();
            //Action
            var actual = _builder.BuildWhere(predicate, out args).Trim();
            // Assert
            var expected = "[PaidTime] = @P0";

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(DateTime.Parse("2019-01-01 10:10:10"), args["@P0"]);
        }
Esempio n. 5
0
        public void Build_Same_Propiete_And_Type_Add_right()
        {
            //Arrange
            // Entity_Lamda_To_Sql model = new Entity_Lamda_To_Sql();
            Entity_Lamda_To_Sql model = new Entity_Lamda_To_Sql();

            model.Code = "No123";
            Expression <Func <Entity_Lamda_To_Sql, bool> > predicate = i => i.Code + model.Code == i.Code;
            Dictionary <string, object> args = new Dictionary <string, object>();
            //Action
            var actual = _builder.BuildWhere(predicate, out args).Trim();
            // Assert
            var expected = "[Code] + @P0 = [Code]";

            Assert.AreEqual(expected, actual);
            Assert.AreEqual("No123", args["@P0"]);
        }
Esempio n. 6
0
        public void Build_One_Object_Method_withParameter()
        {
            //Arrange
            // Entity_Lamda_To_Sql model = new Entity_Lamda_To_Sql();
            Entity_Lamda_To_Sql model = new Entity_Lamda_To_Sql();

            model.Code = "No123";
            Expression <Func <Entity_Lamda_To_Sql, bool> > predicate = i => i.Code == model.GetNewId(113).ToString();
            Dictionary <string, object> args = new Dictionary <string, object>();
            //Action
            var actual = _builder.BuildWhere(predicate, out args).Trim();
            // Assert
            var expected = "[Code] = @P0";

            Assert.AreEqual(expected, actual);
            Assert.AreEqual("123", args["@P0"]);
        }