Ejemplo n.º 1
0
        public void Update_WithIdentity_Test()
        {
            var compiler         = new SqlServerCompiler();
            var builder          = new QueryBuilder <EmployeeWithAttributes>(compiler);
            var employeeToUpdate = new EmployeeWithAttributes()
            {
                Id = 1, Name = "test"
            };

            var result = builder.Update(employeeToUpdate) as DbCompileResult;

            Assert.NotNull(result);
            Assert.Equal(2, result.QueryParameters.Count);
            Assert.Equal("test", result.QueryParameters["@P0"]);
            Assert.Equal(1, result.QueryParameters["@P1"]);
            Assert.Equal("UPDATE dbo.employee SET [name] = @P0 WHERE [Id] = @P1", result.SqlQuery);
        }
Ejemplo n.º 2
0
        public void Delete_WithWhereExpression_Test()
        {
            var compiler         = new SqlServerCompiler();
            var builder          = new QueryBuilder <EmployeeWithAttributes>(compiler);
            var employeeToUpdate = new EmployeeWithAttributes()
            {
                Name = "test"
            };

            var result = builder.Update(employeeToUpdate, e => e.Id == 1) as DbCompileResult;

            Assert.NotNull(result);
            Assert.Equal(2, result.QueryParameters.Count);
            Assert.Equal("test", result.QueryParameters["@P0"]);
            Assert.Equal(1, result.QueryParameters["@P1"]);
            Assert.Equal("UPDATE dbo.employee SET [name] = @P0 WHERE ([Id] = @P1)", result.SqlQuery);
        }
Ejemplo n.º 3
0
        public void Insert_WithColumOrAttribute_Test()
        {
            var compiler = new MySqlCompiler();
            var builder  = new QueryBuilder <EmployeeWithAttributes>(compiler);

            var employee = new EmployeeWithAttributes()
            {
                Id   = 1,
                Name = "Employee Name"
            };

            var result = builder.Insert(employee) as DbCompileResult;

            Assert.NotNull(result.QueryParameters);
            Assert.Equal(1, result.QueryParameters.Count);
            Assert.Equal(result.QueryParameters["@P0"], employee.Name);
            Assert.Equal("INSERT INTO dbo.employee (`name`) VALUES (@P0)", result.SqlQuery);
        }