public void ContentNullTest()
        {
            var target = new EnglishSentences();
            target.Content = null;

            Assert.AreEqual(null, target.Content);
        }
        public void IDNullTest()
        {
            var target = new EnglishSentences();
            target.ID = null;

            Assert.AreEqual(null, target.ID);
        }
Esempio n. 3
0
        /// <summary>
        /// Retrieves the first set of items specified by count by Level
        /// </summary>
        /// <param name="Level">Level value</param>
        /// <param name="count">Number of records to be retrieved</param>
        public System.Collections.Generic.List <EnglishSentences> SelectByLevel(System.Int32?Level, int count)
        {
            var list = new System.Collections.Generic.List <EnglishSentences>();

            using (var command = EntityBase.CreateCommand(Transaction))
            {
                if (Level != null)
                {
                    command.CommandText = "SELECT TOP(" + count + ") * FROM EnglishSentences WHERE Level=@Level";
                    command.Parameters.Add("@Level", System.Data.SqlDbType.Int);
                    command.Parameters["@Level"].Value = Level != null ? (object)Level : System.DBNull.Value;
                }
                else
                {
                    command.CommandText = "SELECT TOP(" + count + ") * FROM EnglishSentences WHERE Level IS NULL";
                }

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var item = new EnglishSentences();
                        item.ID      = (System.Int32?)(reader.IsDBNull(0) ? null : reader["ID"]);
                        item.Content = (reader.IsDBNull(1) ? null : reader["Content"] as System.String);
                        item.Level   = (System.Int32?)(reader.IsDBNull(2) ? null : reader["Level"]);
                        list.Add(item);
                    }
                }
            }
            return(list.Count > 0 ? list : null);
        }
        public void ContentTest()
        {
            var value = string.Empty;
            var target = new EnglishSentences();
            target.Content = value;

            Assert.AreEqual(value, target.Content);
        }
        public void ContentMaxLengthTest()
        {
            var value = RandomGenerator.GenerateString(100);
            var target = new EnglishSentences();
            target.Content = value;

            Assert.AreEqual(value, target.Content);
        }
        public void IDTest()
        {
            var value = new System.Int32();
            var target = new EnglishSentences();
            target.ID = value;

            Assert.AreEqual(value, target.ID);
        }
 public void CreateTest()
 {
     PurgeTest();
     IEnglishSentencesRepository target = new EnglishSentencesRepository();
     var actual = new EnglishSentences
     {
         Content = RandomGenerator.GenerateString(100),
         Level = new System.Random().Next(1, 1000)
     };
     target.Create(actual);
 }
Esempio n. 8
0
        /// <summary>
        /// Deletes the item
        /// </summary>
        /// <param name="item">Item to delete</param>
        public void Delete(EnglishSentences item)
        {
            using (var command = EntityBase.CreateCommand(Transaction))
            {
                command.CommandText = "DELETE FROM [EnglishSentences] WHERE ID = @ID";

                command.Parameters.Add("@ID", System.Data.SqlDbType.Int);
                command.Parameters["@ID"].Value = item.ID != null ? (object)item.ID : System.DBNull.Value;
                command.ExecuteNonQuery();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Updates the item
        /// </summary>
        /// <param name="item">Item to update</param>
        public void Update(EnglishSentences item)
        {
            using (var command = EntityBase.CreateCommand(Transaction))
            {
                command.CommandText = "UPDATE [EnglishSentences] SET Content = @Content, Level = @Level WHERE ID = @ID";

                command.Parameters.Add("@ID", System.Data.SqlDbType.Int);
                command.Parameters["@ID"].Value = item.ID != null ? (object)item.ID : System.DBNull.Value;
                command.Parameters.Add("@Content", System.Data.SqlDbType.NVarChar);
                command.Parameters["@Content"].Value = item.Content != null ? (object)item.Content : System.DBNull.Value;
                command.Parameters.Add("@Level", System.Data.SqlDbType.Int);
                command.Parameters["@Level"].Value = item.Level != null ? (object)item.Level : System.DBNull.Value;
                command.ExecuteNonQuery();
            }
        }
 public void ContentMaxLengthArgumentExceptionTest()
 {
     try
     {
         var value = RandomGenerator.GenerateString(101);
         var target = new EnglishSentences();
         target.Content = value;
         Assert.IsTrue(false, "ArgumentException expected");
     }
     catch (System.ArgumentException) { }
     catch (System.Exception)
     {
         Assert.IsTrue(false, "ArgumentException expected");
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Retrieves the first set of items specified by count as a generic collection
        /// </summary>
        /// <param name="count">Number of records to be retrieved</param>
        public System.Collections.Generic.List <EnglishSentences> ToList(int count)
        {
            var list = new System.Collections.Generic.List <EnglishSentences>();

            using (var command = EntityBase.CreateCommand(Transaction))
            {
                command.CommandText = string.Format("SELECT TOP({0}) * FROM EnglishSentences", count);
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var item = new EnglishSentences();
                        item.ID      = (System.Int32?)(reader.IsDBNull(0) ? null : reader["ID"]);
                        item.Content = (reader.IsDBNull(1) ? null : reader["Content"] as System.String);
                        item.Level   = (System.Int32?)(reader.IsDBNull(2) ? null : reader["Level"]);
                        list.Add(item);
                    }
                }
            }
            return(list.Count > 0 ? list : null);
        }
Esempio n. 12
0
 /// <summary>
 /// Inserts the item to the table
 /// </summary>
 /// <param name="item">Item to insert to the database</param>
 public void Create(EnglishSentences item)
 {
     Create(item.Content, item.Level);
 }
 /// <summary>
 /// Inserts the item to the table
 /// </summary>
 /// <param name="item">Item to insert to the database</param>
 public void Create(EnglishSentences item)
 {
     Create(item.Content, item.Level);
 }
 public void Delete(EnglishSentences item)
 {
     mockDataSource.Remove(item);
 }
 public void Create(EnglishSentences item)
 {
     mockDataSource.Add(item);
 }
 public void Update(EnglishSentences item)
 {
     for (int i = 0; i < mockDataSource.Count; i++)
     {
         if (mockDataSource[i].ID == item.ID)
             mockDataSource[i] = item;
     }
 }
Esempio n. 17
0
 private void btQuickAdd_Click(object sender, EventArgs e)
 {
     try
     {
         if (target.ToList().Any(o => o.Content.ToUpper().Contains(txtSentence.Text.ToUpper())))
         {
             MessageBox.Show("'" + txtSentence.Text+"'" + " is exist on db");
         }
         else
         {
             EnglishSentences form = new EnglishSentences();
             form.Content = txtSentence.Text;
             target.Create(form);
             MessageBox.Show("Quick add :'" + txtSentence.Text + "' to db");
         }
     }catch(Exception ex)
     {
         MessageBox.Show("Not that easy :" + ex.Message);
     }
 }
        /// <summary>
        /// Retrieves the first set of items specified by count by Level
        /// </summary>
        /// <param name="Level">Level value</param>
        /// <param name="count">Number of records to be retrieved</param>
        public System.Collections.Generic.List<EnglishSentences> SelectByLevel(System.Int32? Level, int count)
        {
            var list = new System.Collections.Generic.List<EnglishSentences>();
            using (var command = EntityBase.CreateCommand(Transaction))
            {
            if (Level != null)
            {
                command.CommandText = "SELECT TOP(" + count + ") * FROM EnglishSentences WHERE Level=@Level";
                command.Parameters.Add("@Level", System.Data.SqlDbType.Int);
                command.Parameters["@Level"].Value = Level != null ? (object)Level : System.DBNull.Value;
            }
            else
                command.CommandText = "SELECT TOP(" + count + ") * FROM EnglishSentences WHERE Level IS NULL";

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var item = new EnglishSentences();
                        item.ID = (System.Int32?) (reader.IsDBNull(0) ? null : reader["ID"]);
                        item.Content = (reader.IsDBNull(1) ? null : reader["Content"] as System.String);
                        item.Level = (System.Int32?) (reader.IsDBNull(2) ? null : reader["Level"]);
                        list.Add(item);
                    }
                }
            }
            return list.Count > 0 ? list : null;
        }
        public void UpdateTest()
        {
            IEnglishSentencesRepository target = new EnglishSentencesRepository();
            var actual = new EnglishSentences
            {
                Content = RandomGenerator.GenerateString(100),
                Level = new System.Random().Next(1, 1000)
            };
            target.Create(actual);

            var actual2 = target.ToList();
            var item = actual2[0];
            item.Content = RandomGenerator.GenerateString(100);
            target.Update(item);
        }
 /// <summary>
 /// Retrieves the first set of items specified by count as a generic collection
 /// </summary>
 /// <param name="count">Number of records to be retrieved</param>
 public System.Collections.Generic.List<EnglishSentences> ToList(int count)
 {
     var list = new System.Collections.Generic.List<EnglishSentences>();
     using (var command = EntityBase.CreateCommand(Transaction))
     {
         command.CommandText = string.Format("SELECT TOP({0}) * FROM EnglishSentences", count);
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 var item = new EnglishSentences();
                 item.ID = (System.Int32?) (reader.IsDBNull(0) ? null : reader["ID"]);
                 item.Content = (reader.IsDBNull(1) ? null : reader["Content"] as System.String);
                 item.Level = (System.Int32?) (reader.IsDBNull(2) ? null : reader["Level"]);
                 list.Add(item);
             }
         }
     }
     return list.Count > 0 ? list : null;
 }
        /// <summary>
        /// Updates the item
        /// </summary>
        /// <param name="item">Item to update</param>
        public void Update(EnglishSentences item)
        {
            using (var command = EntityBase.CreateCommand(Transaction))
            {
                command.CommandText = "UPDATE [EnglishSentences] SET Content = @Content, Level = @Level WHERE ID = @ID";

                command.Parameters.Add("@ID", System.Data.SqlDbType.Int);
                command.Parameters["@ID"].Value = item.ID != null ? (object)item.ID : System.DBNull.Value;
                command.Parameters.Add("@Content", System.Data.SqlDbType.NVarChar);
                command.Parameters["@Content"].Value = item.Content != null ? (object)item.Content : System.DBNull.Value;
                command.Parameters.Add("@Level", System.Data.SqlDbType.Int);
                command.Parameters["@Level"].Value = item.Level != null ? (object)item.Level : System.DBNull.Value;
                command.ExecuteNonQuery();
            }
        }
        public void LevelNullTest()
        {
            var target = new EnglishSentences();
            target.Level = null;

            Assert.AreEqual(null, target.Level);
        }
        /// <summary>
        /// Deletes the item
        /// </summary>
        /// <param name="item">Item to delete</param>
        public void Delete(EnglishSentences item)
        {
            using (var command = EntityBase.CreateCommand(Transaction))
            {
                command.CommandText = "DELETE FROM [EnglishSentences] WHERE ID = @ID";

                command.Parameters.Add("@ID", System.Data.SqlDbType.Int);
                command.Parameters["@ID"].Value = item.ID != null ? (object)item.ID : System.DBNull.Value;
                command.ExecuteNonQuery();
            }
        }