ToString() public method

Returns a that represents the current .
public ToString ( ) : string
return string
Example #1
0
        public void Test_ToString_BlankSource()
        {
            //-------------Setup Test Pack ------------------
            string surnameValue = Guid.NewGuid().ToString("N");
            const string surname = "Surname";
            Criteria criteria = new Criteria(surname, Criteria.ComparisonOp.Equals, surnameValue);
            criteria.Field.Source = new Source("");
            CriteriaDB surnameCriteria = new CriteriaDB(criteria);

            //-------------Execute test ---------------------
            
            string tostring = surnameCriteria.ToString(new SqlFormatter("<<", ">>", "", ""),
                                                       delegate(object value) { return Convert.ToString(value); }, 
                                                       SetupSingleAlias(""));
            //-------------Test Result ----------------------

            Assert.AreEqual(string.Format("a1.<<{0}>> = {1}", surname, surnameValue), tostring);
        }
Example #2
0
        private void AppendWhereClause(StringBuilder builder, SqlStatement statement)
        {
            Criteria fullCriteria = Criteria.MergeCriteria(_selectQuery.Criteria, _selectQuery.DiscriminatorCriteria);
            ClassDef classDef = (ClassDef) _selectQuery.ClassDef;
            if (classDef != null && classDef.ClassID.HasValue)
            {
                Criteria classIDCriteria = new Criteria("DMClassID", Criteria.ComparisonOp.Equals, classDef.ClassID.Value);
                classIDCriteria.Field.Source = this.Source;
                fullCriteria = Criteria.MergeCriteria(fullCriteria, classIDCriteria);
            }

            if (fullCriteria == null) return;
            builder.Append(" WHERE ");
            CriteriaDB criteriaDB = new CriteriaDB(fullCriteria);

            string whereClause = criteriaDB.ToString(_sqlFormatter, value => AddParameter(value, statement),Aliases);

            builder.Append(whereClause);
        }
Example #3
0
        public void Test_ToString_EqualsNullCriteria()
        {
            //-------------Setup Test Pack ------------------
            const string surnameField = "Surname";
            Criteria criteria = new Criteria(surnameField, Criteria.ComparisonOp.Equals, null);
            const string surnameTable = "surname_table";
            criteria.Field.Source = new Source(surnameTable);
            CriteriaDB surnameCriteria = new CriteriaDB(criteria);

            //-------------Execute test ---------------------
            string tostring = surnameCriteria.ToString(new SqlFormatter("<<", ">>", "", ""),
                                                       Convert.ToString,
                                                       SetupSingleAlias(surnameTable));
            //-------------Test Result ----------------------

            Assert.AreEqual(string.Format("a1.<<{0}>> IS NULL", surnameField), tostring);
        }
Example #4
0
		public void Test_ToString_WithFieldHavingSource_WhenAliasMissing_ShouldThrowError()
		{
			//---------------Set up test pack-------------------
			const string sourceName = "mysource";
			const string propertyName = "testproperty";
			QueryField queryField = new QueryField(propertyName, "testfield", new Source(sourceName));
			Criteria criteria = new Criteria(queryField, Criteria.ComparisonOp.Equals, "myvalue");
			IDictionary<string, string> aliases = new Dictionary<string, string>();
			CriteriaDB criteriaDb = new CriteriaDB(criteria);
			SqlFormatter sqlFormatter = new SqlFormatter("[", "]", "", "LIMIT");
			//---------------Execute Test ----------------------
			var habaneroDeveloperException = Assert.Throws<HabaneroDeveloperException>(() =>
			{
				criteriaDb.ToString(sqlFormatter, value => "Param", aliases);
			});
			//---------------Test Result -----------------------
			Assert.IsNotNull(habaneroDeveloperException);
			var expectedMessage = string.Format("The source '{0}' for the property '{1}' " + "in the given criteria does not have an alias provided for it.", sourceName, queryField.PropertyName);
			var expectedDeveloperMessage = expectedMessage 
				+ " The criteria object may have not been prepared correctly before the aliases were set up.";
			Assert.AreEqual(expectedMessage, habaneroDeveloperException.Message);
			Assert.AreEqual(expectedDeveloperMessage, habaneroDeveloperException.DeveloperMessage);
    }
Example #5
0
		public void Test_ToString_ShouldUseAliases()
        {
            //---------------Set up test pack-------------------
            const string sourceName = "mysource";
            var source1 = new Source(sourceName);
            Source field1Source = source1;
            QueryField field1 = new QueryField("testfield", "testfield", field1Source);
            Criteria criteria = new Criteria(field1, Criteria.ComparisonOp.Equals, "myvalue");
			IDictionary<string, string> aliases = new Dictionary<string, string>() { { source1.ToString(), "a1" } };
            CriteriaDB criteriaDb = new CriteriaDB(criteria);
            SqlFormatter sqlFormatter = new SqlFormatter("[", "]", "", "LIMIT");
            //---------------Execute Test ----------------------
            string whereClause = criteriaDb.ToString(sqlFormatter, value => "Param", aliases);
            //---------------Test Result -----------------------
            StringAssert.AreEqualIgnoringCase("a1.[testfield] = Param", whereClause);
        }
Example #6
0
        public void Test_ToString_NotIn()
        {
            //---------------Set up test pack-------------------
            string surnameValue1 = Guid.NewGuid().ToString("N");
            string surnameValue2 = Guid.NewGuid().ToString("N");
            const string surname = "Surname";
            CriteriaDB surnameCriteria =
                new CriteriaDB(new Criteria(surname, Criteria.ComparisonOp.NotIn, new object[] { surnameValue1, surnameValue2 }));
            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            string criteriaAsString = surnameCriteria.ToString(new SqlFormatter("", "", "", ""), value => value.ToString());

            //---------------Test Result -----------------------
            string expectedString = string.Format("Surname NOT IN ('{0}', '{1}')", surnameValue1, surnameValue2);
            StringAssert.AreEqualIgnoringCase(expectedString, criteriaAsString);
            //---------------Tear Down -------------------------          
        }
Example #7
0
        public void Test_ToString_UsingDelegates()
        {
            //---------------Set up test pack-------------------
            string surnameValue = Guid.NewGuid().ToString("N");
            const string surname = "Surname";
            CriteriaDB surnameCriteria =
                new CriteriaDB(new Criteria(surname, Criteria.ComparisonOp.Equals, surnameValue));
            DateTime dateTimeValue = DateTime.Now;
            const string datetimePropName = "DateTime";
            CriteriaDB dateTimeCriteria =
                new CriteriaDB(new Criteria(datetimePropName, Criteria.ComparisonOp.GreaterThan, dateTimeValue));

            CriteriaDB andCriteria =
                new CriteriaDB(new Criteria(surnameCriteria, Criteria.LogicalOp.And, dateTimeCriteria));

            //---------------Execute Test ----------------------
            int i = 0;
            string criteriaAsString = andCriteria.ToString(new SqlFormatter("", "","",""), delegate { return "param" + i++; });

            //---------------Test Result -----------------------
            const string expectedString = "(Surname = param0) AND (DateTime > param1)";
            StringAssert.AreEqualIgnoringCase(expectedString, criteriaAsString);

            //---------------Tear Down -------------------------
        }