Example #1
0
        public void BulkCopy()
        {
            Guid TempGuid = Guid.NewGuid();
            List <BulkCopyObject> Objects = new List <BulkCopyObject>();

            for (int x = 0; x < 100; ++x)
            {
                BulkCopyObject TempObject = new BulkCopyObject();
                TempObject.BigIntValue   = 12345;
                TempObject.BitValue      = true;
                TempObject.DateTimeValue = new DateTime(1999, 12, 31);
                TempObject.DecimalValue  = 1234.5678m;
                TempObject.FloatValue    = 12345.6534f;
                TempObject.GUIDValue     = TempGuid;
                TempObject.ID            = x + 1;
                TempObject.StringValue1  = "Test String";
                TempObject.StringValue2  = "Test String";
                Objects.Add(TempObject);
            }
            using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
            {
                Helper.ExecuteBulkCopy(Objects.ToDataTable(), "TestTable");
            }
            using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
            {
                Helper.ExecuteReader();
                bool Inserted = false;
                while (Helper.Read())
                {
                    Inserted = true;
                    Assert.Equal("Test String", Helper.GetParameter <string>("StringValue1", ""));
                    Assert.Equal("Test String", Helper.GetParameter <string>("StringValue2", ""));
                    Assert.Equal(12345, Helper.GetParameter <long>("BigIntValue", 0));
                    Assert.Equal(true, Helper.GetParameter <bool>("BitValue", false));
                    Assert.Equal(1234.5678m, Helper.GetParameter <decimal>("DecimalValue", 0));
                    Assert.Equal(12345.6534f, Helper.GetParameter <float>("FloatValue", 0));
                    Assert.Equal(TempGuid, Helper.GetParameter <Guid>("GUIDValue", Guid.Empty));
                    Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter <DateTime>("DateTimeValue", DateTime.Now));
                }
                if (!Inserted)
                {
                    Assert.False(true, "Nothing was inserted");
                }
            }
            using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT COUNT(*) as [ItemCount] FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
            {
                Helper.ExecuteReader();
                if (Helper.Read())
                {
                    Assert.Equal(100, Helper.GetParameter <int>("ItemCount", 0));
                }
                else
                {
                    Assert.False(true, "Nothing was inserted");
                }
            }
        }
 public void BulkCopy()
 {
     Guid TempGuid = Guid.NewGuid();
     List<BulkCopyObject> Objects = new List<BulkCopyObject>();
     for (int x = 0; x < 100; ++x)
     {
         BulkCopyObject TempObject = new BulkCopyObject();
         TempObject.BigIntValue = 12345;
         TempObject.BitValue = true;
         TempObject.DateTimeValue = new DateTime(1999, 12, 31);
         TempObject.DecimalValue = 1234.5678m;
         TempObject.FloatValue = 12345.6534f;
         TempObject.GUIDValue = TempGuid;
         TempObject.ID = x + 1;
         TempObject.StringValue1 = "Test String";
         TempObject.StringValue2 = "Test String";
         Objects.Add(TempObject);
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.ExecuteBulkCopy(Objects.ToDataTable(), "TestTable");
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.ExecuteReader();
         bool Inserted = false;
         while (Helper.Read())
         {
             Inserted = true;
             Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", ""));
             Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", ""));
             Assert.Equal(12345, Helper.GetParameter<long>("BigIntValue", 0));
             Assert.Equal(true, Helper.GetParameter<bool>("BitValue", false));
             Assert.Equal(1234.5678m, Helper.GetParameter<decimal>("DecimalValue", 0));
             Assert.Equal(12345.6534f, Helper.GetParameter<float>("FloatValue", 0));
             Assert.Equal(TempGuid, Helper.GetParameter<Guid>("GUIDValue", Guid.Empty));
             Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter<DateTime>("DateTimeValue", DateTime.Now));
         }
         if (!Inserted)
         {
             Assert.False(true, "Nothing was inserted");
         }
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT COUNT(*) as [ItemCount] FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.ExecuteReader();
         if (Helper.Read())
         {
             Assert.Equal(100, Helper.GetParameter<int>("ItemCount", 0));
         }
         else
         {
             Assert.False(true, "Nothing was inserted");
         }
     }
 }