AddField() public method

Adds a field to the list of fields.
public AddField ( string propertyName ) : void
propertyName string
return void
Ejemplo n.º 1
0
 public void Sort_TwoFieldsAscending()
 {
     //---------------Set up test pack-------------------
     var resultSet = new QueryResult();
     resultSet.AddField("Name");
     resultSet.AddField("Age");
     resultSet.AddResult(new object[] { "Bob", 21 });
     resultSet.AddResult(new object[] { "Bob", 19 });
     resultSet.AddResult(new object[] { "Peter", 40 });
     resultSet.AddResult(new object[] { "Peter", 30 });
     var orderCriteria = OrderCriteria.FromString("Name, Age");
     var sorter = new QueryResultSorter();
     //---------------Execute Test ----------------------
     sorter.Sort(resultSet, orderCriteria);
     //---------------Test Result -----------------------
     var rows = resultSet.Rows.ToList();
     Assert.AreEqual("Bob", rows[0].Values[0]);
     Assert.AreEqual(19, rows[0].Values[1]);
     Assert.AreEqual("Bob", rows[1].Values[0]);
     Assert.AreEqual(21, rows[1].Values[1]);
     Assert.AreEqual("Peter", rows[2].Values[0]);
     Assert.AreEqual(30, rows[2].Values[1]);
     Assert.AreEqual("Peter", rows[3].Values[0]);
     Assert.AreEqual(40, rows[3].Values[1]);
 }
Ejemplo n.º 2
0
 public void AddField_ShouldSetIndexOfAddedField()
 {
     //---------------Set up test pack-------------------
     var resultSet = new QueryResult();
     const string propertyName1 = "Name";
     resultSet.AddField(propertyName1);
     const string propertyName2 = "Name2";
     resultSet.AddField(propertyName2);
     //---------------Execute Test ----------------------
     //---------------Test Result -----------------------
     var fields = resultSet.Fields.ToList();
     Assert.AreEqual(2, fields.Count);
     Assert.AreEqual(propertyName1, fields[0].PropertyName);
     Assert.AreEqual(0, fields[0].Index); 
     Assert.AreEqual(propertyName2, fields[1].PropertyName);
     Assert.AreEqual(1, fields[1].Index);
 }
Ejemplo n.º 3
0
 public void AddResult_ShouldAddRowToRowsList()
 {
     //---------------Set up test pack-------------------
     var resultSet = new QueryResult();
     resultSet.AddField("Name");
     var name = TestUtil.GetRandomString();
     //---------------Execute Test ----------------------
     resultSet.AddResult(new object[] {name});
     //---------------Test Result -----------------------
     var rows = resultSet.Rows.ToList();
     Assert.AreEqual(1, rows.Count);
     Assert.AreEqual(name, rows[0].RawValues[0]);
 }
Ejemplo n.º 4
0
 public void AddField_ShouldAddFieldToFields()
 {
     //---------------Set up test pack-------------------
     var resultSet = new QueryResult();
     const string propertyName = "Name";
     //---------------Execute Test ----------------------
     resultSet.AddField(propertyName);
     //---------------Test Result -----------------------
     var fields = resultSet.Fields.ToList();
     Assert.AreEqual(1, fields.Count);
     Assert.AreEqual(propertyName, fields[0].PropertyName);
     Assert.AreEqual(0, fields[0].Index);
 }
Ejemplo n.º 5
0
 public void Sort_OneFieldDescending()
 {
     //---------------Set up test pack-------------------
     var resultSet = new QueryResult();
     resultSet.AddField("Name");
     resultSet.AddResult(new object[] { "aaaaa" });
     resultSet.AddResult(new object[] { "zzzzz" });
     var orderCriteria = OrderCriteria.FromString("Name DESC");
     var sorter = new QueryResultSorter();
     //---------------Execute Test ----------------------
     sorter.Sort(resultSet, orderCriteria);
     //---------------Test Result -----------------------
     var rows = resultSet.Rows.ToList();
     Assert.AreEqual("zzzzz", rows[0].Values[0]);
     Assert.AreEqual("aaaaa", rows[1].Values[0]);
 }
Ejemplo n.º 6
0
 public void Sort_OneFieldAscending()
 {
     //---------------Set up test pack-------------------
     var resultSet = new QueryResult();
     resultSet.AddField("Name");
     const string lastValue = "zzzzz";
     const string firstValue = "aaaaa";
     resultSet.AddResult(new object[] { lastValue });
     resultSet.AddResult(new object[] { firstValue });
     var orderCriteria = new OrderCriteria();
     orderCriteria.Add("Name");
     var sorter = new QueryResultSorter();
     //---------------Execute Test ----------------------
     sorter.Sort(resultSet, orderCriteria);
     //---------------Test Result -----------------------
     var rows = resultSet.Rows.ToList();
     Assert.AreEqual(firstValue, rows[0].Values[0]);
     Assert.AreEqual(lastValue, rows[1].Values[0]);
 }