Example #1
0
    public bool PosTest2()
    {
        bool retVal = true;
        const string c_TEST_DESC = "PosTest2: Verify the Nullable object's value doesn't equal the parameter";
        const string c_TEST_ID = "P002";

        Random rand = new Random(-55);
        int value = rand.Next(Int32.MinValue,Int32.MaxValue);
        int? nullObj = new Nullable<int>(value+1);

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (nullObj.Equals((object)value))
            {
                string errorDesc = "result is false as expected: Actual(true)";
                errorDesc += "\n parameter value is " + value;
                errorDesc += "\n Nullable object's value is " + nullObj.Value;
                TestLibrary.TestFramework.LogError("003 " + "TestID_" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e + "\n parameter value is " + value+"\n Nullable object's value is "+nullObj.Value);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
Example #2
0
    public bool PosTest1()
    {
        bool retVal = true;
        const string c_TEST_DESC = "PosTest1: Verify the Nullable object's value equals the parameter";
        const string c_TEST_ID = "P001";

        int value = TestLibrary.Generator.GetInt32(-55);
        int? nullObj = new Nullable<int>(value);

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (!nullObj.Equals((object)value))
            {
                string errorDesc = "result is true as expected: Actual(false)";
                errorDesc += "\n parameter value is " + value;
                TestLibrary.TestFramework.LogError("001 " + "TestID_" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e+"parameter value is "+ value);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
Example #3
0
 public static bool proofLoggedIn(Nullable<Int64> currentUser)
 {
     if (currentUser.Equals(null))
     {
         return false;
     }
     else
     {
         return true;
     }
 }
Example #4
0
        public void TestCase()
        {
            Nullable<Int32> foo = new Nullable<Int32>();
            Assert.IsNull(foo, "#1");
            Assert.IsFalse(foo.HasValue, "#2");

            foo = 3;
            Assert.IsTrue(foo.HasValue, "#3");
            Assert.AreEqual(3, foo, "#4");
            Assert.IsTrue(foo.Equals(3), "#5");
            Assert.IsTrue(3.Equals(foo), "#6");

            foo = null;
            Assert.IsNull(foo, "#7");
            Assert.IsFalse(foo.HasValue, "#8");
        }
	/**
	 * Convert a Nullable<DateTime> into a String.
	 * 
	 * @param d
	 *            The Date to convert.
	 * @return The formated date or null.
	 * @see java.util.SimpleDateFormat
	 */
	private String GetDateValue(Nullable<DateTime> d) {
		if (d == null || d.Equals(""))
			return "";
		else {
			SimpleDateFormat df = new SimpleDateFormat(
					"yyyy-MM-dd'T'HH:mm:ss'Z'");
            return df.Format(d.Value, CultureInfo.CurrentCulture);
		}
	}
Example #6
0
 /// <summary>
 /// 页面上,get时,转为{0:HH:mm:ss}或""
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static string ConvertDateTimeToTime(Nullable<DateTime> arg)
 {
     return arg.Equals(DBNull.Value) ? "" : String.Format("{0:HH:mm:ss}", arg);
 }
Example #7
0
 /// <summary>
 /// 页面上,get时,转为{0:yyyy-MM}或""
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static string ConvertDateTimeToShotMonth(Nullable<DateTime> arg)
 {
     return arg.Equals(DBNull.Value) ? "" : String.Format("{0:yyyy-MM-1}", arg);
 }
Example #8
0
 /// <summary>
 /// 页面上,get时,转为{0:yyyy-MM-dd HH:mm:ss}或""
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static string ConvertDateTimeToNullable(Nullable<DateTime> arg)
 {
     return arg.Equals(null) ? "" : arg.Value.ToString();
 }
Example #9
0
    public bool PosTest6()
    {
        bool retVal = true;
        const string c_TEST_DESC = "PosTest6: Verify the Nullable's type is int and parameter is string";
        const string c_TEST_ID = "P006";

        object value = TestLibrary.Generator.GetString(-55, false,1,10);
        int i = TestLibrary.Generator.GetInt32(-55);
        int? nullObj = new Nullable<int>(i);

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (nullObj.Equals(value))
            {
                string errorDesc = "result is true as expected: Actual(fasle)";
                errorDesc += "\n parameter value is "+value.ToString();
                errorDesc += "\n Nullable object's value is "+ i;
                TestLibrary.TestFramework.LogError("009 " + "TestID_" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("010 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e + "\n parameter value is "+value.ToString()+" \n Nullable object's  value is "+i);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
Example #10
0
 /// <summary>
 /// 将单精度范型转为数据库类型,处理空值
 /// </summary>
 /// <param name="arg">可为空单精度范型</param>
 /// <returns>数据库类型</returns>
 public static string ConvertSingleNullToDBType(Nullable<Single> arg)
 {
     return arg.Equals(null) ? "null" : arg.Value.ToString();
 }
Example #11
0
 /// <summary>
 /// 将时间范型转为数据库类型,处理空值
 /// </summary>
 /// <param name="arg">可为空时间范型</param>
 /// <returns>数据库类型</returns>
 public static string ConvertNullableToDBType(Nullable<DateTime> arg)
 {
     return arg.Equals(null) ? "null" : arg.Value.ToString();
 }
Example #12
0
 /// <summary>
 /// 将整型转为数据库类型,处理空值
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static string ConvertNullableToDBString(Nullable<int> arg)
 {
     return arg.Equals(null) ? "null" : arg.Value.ToString();
 }
Example #13
0
 /// <summary>
 /// 页面上,get时,int空值转为“”
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static string ConvertIntToNullable(Nullable<int> arg)
 {
     return arg.Equals(null) ? "" : arg.Value.ToString();
 }
Example #14
0
 /// <summary>
 /// 页面上,get时,转为{0:yyyy}或""
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static string ConvertDateTimeToYear(Nullable<DateTime> arg)
 {
     return arg.Equals(DBNull.Value) ? "" : String.Format("{0:yyyy}", arg);
 }
Example #15
0
 internal static long CountByParentId(Nullable<int> parent_id)
 {
     return Core.FileSystem.UseConnection<long>(delegate (IDbConnection connection) {
         IDbCommand command = connection.CreateCommand();
         string query = null;
         if (parent_id.Equals(null)) {
             query = "SELECT count(id) FROM directoryitems WHERE parent_id ISNULL AND type = 'D'";
         } else {
             query = "SELECT count(id) FROM directoryitems WHERE parent_id = @parent_id AND type = 'D'";
             Core.FileSystem.AddParameter(command, "@parent_id", (int)parent_id);
         }
         command.CommandText = query;
         return (long) Core.FileSystem.ExecuteScalar(command);
     });
 }
Example #16
0
 /// <summary>
 /// 页面上,get时,单精度型转为" "
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static string ConvertSingleToNullable(Nullable<Single> arg)
 {
     return arg.Equals(null) ? "" : arg.Value.ToString();
 }
Example #17
0
        internal static LocalDirectory[] ListByParentId(Nullable<int> parent_id)
        {
            return Core.FileSystem.UseConnection<LocalDirectory[]>(delegate (IDbConnection connection) {
                IDbCommand command = connection.CreateCommand();
                string query = null;
                if (parent_id.Equals(null)) {
                    query = "SELECT * FROM directoryitems WHERE parent_id ISNULL AND type = 'D'";
                } else {
                    query = "SELECT * FROM directoryitems WHERE parent_id = @parent_id AND type = 'D'";
                    Core.FileSystem.AddParameter(command, "@parent_id", (int)parent_id);
                }
                command.CommandText = query;
                DataSet ds = Core.FileSystem.ExecuteDataSet(command);

                LocalDirectory[] results = new LocalDirectory[ds.Tables[0].Rows.Count];
                for (int x = 0; x < ds.Tables[0].Rows.Count; x++) {
                    results[x] = LocalDirectory.FromDataRow(ds.Tables[0].Rows[x]);
                }
                return results;
            });
        }
Example #18
0
    public bool PosTest5()
    {
        bool retVal = true;
        const string c_TEST_DESC = "PosTest5: Verify the Nullable's hasValue is false and parameter is null";
        const string c_TEST_ID = "P005";

        object value = null;
        int? nullObj = new Nullable<int>();

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (!nullObj.Equals(value))
            {
                string errorDesc = "result is true as expected: Actual(fasle)";
                errorDesc += "\n parameter value is null";
                errorDesc += "\n Nullable object's HasValue is false";
                TestLibrary.TestFramework.LogError("009 " + "TestID_" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("010 " + "TestID_" + c_TEST_ID, "Unexpected exception: " + e + "\n parameter value is null  \n Nullable object's  HasValue is false");
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }