Esempio n. 1
0
        public void SQLServerConnectorCRUD()
        {
            using (var connection = new SQLServer(_msSqlConnection))
            {
                try
                {
                    var datas = new List <TestTable>();
                    connection.CreateTable <TestTable>();
                    for (var iter = 0; iter < 10; iter++)
                    {
                        TestTable testTable = new TestTable()
                        {
                            id = iter, value = $"test"
                        };
                        datas.Add(testTable);
                        var affectedCreate = connection.Insert(testTable);
                        Assert.AreEqual(affectedCreate, 1);
                        var selectedById = connection.Query <TestTable>(primaryKey: iter);
                        Assert.AreEqual(selectedById.id, iter);
                        Assert.AreEqual(selectedById.value, "test");
                        var selectedByIdLambda = connection.Query <TestTable>(x => x.id == iter).First();
                        Assert.AreEqual(selectedByIdLambda.id, iter);
                        Assert.AreEqual(selectedByIdLambda.value, "test");
                        var selectedAll = connection.Query <TestTable>().First();
                        Assert.AreEqual(selectedAll.id, iter);
                        Assert.AreEqual(selectedAll.value, "test");
                        var selectFirst = connection.QueryFirst <TestTable>();
                        Assert.AreEqual(selectFirst.id, iter);
                        Assert.AreEqual(selectFirst.value, "test");
                        testTable.value = null;//"updated";
                        var affectedUpdate = connection.Update(testTable);
                        Assert.AreEqual(affectedUpdate, 1);
                        var affectedDeleteLambdaInvalid = connection.Delete <TestTable>(x => x.id == iter + 1);
                        Assert.AreEqual(affectedDeleteLambdaInvalid, 0);
                        var affectedDelete = connection.Delete(testTable);
                        Assert.AreEqual(affectedDelete, 1);
                    }
                    var affectedSelectScalar = connection.Query <TestTable>();
                    Assert.AreEqual(affectedSelectScalar.Count(), 0);

                    Assert.AreEqual(datas.Count(), connection.InsertMany(datas));
                    Assert.Pass();
                }
                finally
                {
                    connection.ExecuteNonQuery("DROP TABLE [TestTable]");
                }
            }
        }
Esempio n. 2
0
 public void SQLServerConnectorCRUD()
 {
     using (var connection = new SQLServer(_msSqlConnection))
     {
         try
         {
             connection.ExecuteNonQuery($@"CREATE TABLE [dbo].[TestTable]([id] int primary key,[value] nvarchar(255))");
             for (var iter = 0; iter < 10; iter++)
             {
                 TestTable testTable = new TestTable()
                 {
                     id = iter, value = $"test"
                 };
                 var affectedCreate = connection.Insert(testTable);
                 Assert.AreEqual(affectedCreate, 1);
                 var selectedById = connection.Select <TestTable>(iter);
                 Assert.AreEqual(selectedById.id, iter);
                 Assert.AreEqual(selectedById.value, "test");
                 var selectedByIdLambda = connection.Select <TestTable>(x => x.id == iter);
                 Assert.AreEqual(selectedByIdLambda.First().id, iter);
                 Assert.AreEqual(selectedByIdLambda.First().value, "test");
                 var selectedAll = connection.Select <TestTable>();
                 Assert.AreEqual(selectedAll.First().id, iter);
                 Assert.AreEqual(selectedAll.First().value, "test");
                 testTable.value = "updated";
                 var affectedUpdate = connection.Update(testTable);
                 Assert.AreEqual(affectedUpdate, 1);
                 var affectedUpdateLambdaValid = connection.Update(testTable, x => x.id == iter);
                 Assert.AreEqual(affectedUpdateLambdaValid, 1);
                 var affectedUpdateLambdaInvalid = connection.Update(testTable, x => x.id == iter + 1);
                 Assert.AreEqual(affectedUpdateLambdaInvalid, 0);
                 var affectedDeleteLambdaInvalid = connection.Delete <TestTable>(x => x.id == iter + 1);
                 Assert.AreEqual(affectedDeleteLambdaInvalid, 0);
                 var affectedDelete = connection.Delete(testTable);
                 Assert.AreEqual(affectedDelete, 1);
             }
             var affectedSelectScalar = connection.Select <TestTable>();
             Assert.AreEqual(affectedSelectScalar.Count(), 0);
             Assert.Pass();
         }
         finally
         {
             connection.ExecuteNonQuery($@"DROP TABLE [dbo].[TestTable]");
         }
     }
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("oRACLE");
            IDataSpace db;

            db = new Oracle();
            db.Selecct();
            db.Insert();
            db.Delete();
            db.Update();

            Console.WriteLine("SQL sERVER");
            IDataSpace sqlserver;

            sqlserver = new SQLServer();
            sqlserver.Selecct();
            sqlserver.Insert();
            sqlserver.Delete();
            sqlserver.Update();
        }