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]); }
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); }
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); }
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]); }
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]); }
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]); }