using System; using NUnit.Framework; using IBatisNet.DataMapper.Test.Domain; namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests { /// /// Summary description for ResultClassTest. /// [TestFixture] public class ResultClassTest : BaseTest { #region SetUp & TearDown /// /// SetUp /// [SetUp] public void Init() { } /// /// TearDown /// [TearDown] public void Dispose() { /* ... */ } #endregion #region Specific statement test /// /// Test a boolean resultClass /// [Test] public void TestBoolean() { bool bit = (bool) sqlMap.QueryForObject("GetBoolean", 1); Assert.AreEqual(true, bit); } /// /// Test a boolean implicit resultClass /// [Test] public void TestBooleanWithoutResultClass() { bool bit = Convert.ToBoolean(sqlMap.QueryForObject("GetBooleanWithoutResultClass", 1)); Assert.AreEqual(true, bit); } /// /// Test a byte resultClass /// [Test] public void TestByte() { byte letter = (byte) sqlMap.QueryForObject("GetByte", 1); Assert.AreEqual(155, letter); } /// /// Test a byte implicit resultClass /// [Test] public void TestByteWithoutResultClass() { byte letter = Convert.ToByte(sqlMap.QueryForObject("GetByteWithoutResultClass", 1)); Assert.AreEqual(155, letter); } /// /// Test a char resultClass /// [Test] public void TestChar() { char letter = (char) sqlMap.QueryForObject("GetChar", 1); Assert.AreEqual('a', letter); } /// /// Test a char implicit resultClass /// [Test] public void TestCharWithoutResultClass() { char letter = Convert.ToChar(sqlMap.QueryForObject("GetCharWithoutResultClass", 1)); Assert.AreEqual('a', letter); } /// /// Test a DateTime resultClass /// [Test] public void TestDateTime() { DateTime orderDate = (DateTime) sqlMap.QueryForObject("GetDate", 1); System.DateTime date = new DateTime(2003, 2, 15, 8, 15, 00); Assert.AreEqual(date.ToString(), orderDate.ToString()); } /// /// Test a DateTime implicit resultClass /// [Test] public void TestDateTimeWithoutResultClass() { DateTime orderDate = Convert.ToDateTime(sqlMap.QueryForObject("GetDateWithoutResultClass", 1)); System.DateTime date = new DateTime(2003, 2, 15, 8, 15, 00); Assert.AreEqual(date.ToString(), orderDate.ToString()); } /// /// Test a decimal resultClass /// [Test] public void TestDecimal() { decimal price = (decimal) sqlMap.QueryForObject("GetDecimal", 1); Assert.AreEqual((decimal)1.56, price); } /// /// Test a decimal implicit resultClass /// [Test] public void TestDecimalWithoutResultClass() { decimal price = Convert.ToDecimal(sqlMap.QueryForObject("GetDecimalWithoutResultClass", 1)); Assert.AreEqual((decimal)1.56, price); } /// /// Test a double resultClass /// [Test] public void TestDouble() { double price = (double) sqlMap.QueryForObject("GetDouble", 1); Assert.AreEqual(99.5f, price); } /// /// Test a double implicit resultClass /// [Test] public void TestDoubleWithoutResultClass() { double price = Convert.ToDouble(sqlMap.QueryForObject("GetDoubleWithoutResultClass", 1)); Assert.AreEqual(99.5f, price); } /// /// IBATISNET-25 Error applying ResultMap when using 'Guid' in resultClass /// [Test] public void TestGuid() { Guid newGuid = new Guid("CD5ABF17-4BBC-4C86-92F1-257735414CF4"); Guid guid = (Guid) sqlMap.QueryForObject("GetGuid", 1); Assert.AreEqual(newGuid, guid); } /// /// Test a Guid implicit resultClass /// [Test] public void TestGuidWithoutResultClass() { Guid newGuid = new Guid("CD5ABF17-4BBC-4C86-92F1-257735414CF4"); string guidString = Convert.ToString(sqlMap.QueryForObject("GetGuidWithoutResultClass", 1)); Guid guid = new Guid(guidString); Assert.AreEqual(newGuid, guid); } /// /// Test a int16 resultClass /// [Test] public void TestInt16() { short integer = (short) sqlMap.QueryForObject("GetInt16", 1); Assert.AreEqual(32111, integer); } /// /// Test a int16 implicit resultClass /// [Test] public void TestInt16WithoutResultClass() { short integer = Convert.ToInt16(sqlMap.QueryForObject("GetInt16WithoutResultClass", 1)); Assert.AreEqual(32111, integer); } /// /// Test a int 32 resultClass /// [Test] public void TestInt32() { int integer = (int) sqlMap.QueryForObject("GetInt32", 1); Assert.AreEqual(999999, integer); } /// /// Test a int 32 implicit resultClass /// [Test] public void TestInt32WithoutResultClass() { int integer = Convert.ToInt32(sqlMap.QueryForObject("GetInt32WithoutResultClass", 1)); Assert.AreEqual(999999, integer); } /// /// Test a int64 resultClass /// [Test] public void TestInt64() { long bigInt = (long) sqlMap.QueryForObject("GetInt64", 1); Assert.AreEqual(9223372036854775800, bigInt); } /// /// Test a int64 implicit resultClass /// [Test] public void TestInt64WithoutResultClass() { long bigInt = Convert.ToInt64(sqlMap.QueryForObject("GetInt64WithoutResultClass", 1)); Assert.AreEqual(9223372036854775800, bigInt); } /// /// Test a single/float resultClass /// [Test] public void TestSingle() { float price = (float)sqlMap.QueryForObject("GetSingle", 1); Assert.AreEqual(92233.5, price); } /// /// Test a single/float implicit resultClass /// [Test] public void TestSingleWithoutResultClass() { double price = Convert.ToDouble(sqlMap.QueryForObject("GetSingleWithoutResultClass", 1)); Assert.AreEqual(92233.5, price); } /// /// Test a string resultClass /// [Test] public void TestString() { string cardType = sqlMap.QueryForObject("GetString", 1) as string; Assert.AreEqual("VISA", cardType); } /// /// Test a string implicit resultClass /// [Test] public void TestStringWithoutResultClass() { string cardType = Convert.ToString(sqlMap.QueryForObject("GetStringWithoutResultClass", 1)); Assert.AreEqual("VISA", cardType); } /// /// Test a TimeSpan resultClass /// [Test] [Ignore("To do")] public void TestTimeSpan() { Guid newGuid = Guid.NewGuid();; Category category = new Category(); category.Name = "toto"; category.Guid = newGuid; int key = (int)sqlMap.Insert("InsertCategory", category); Guid guid = (Guid)sqlMap.QueryForObject("GetGuid", key); Assert.AreEqual(newGuid, guid); } /// /// Test a TimeSpan implicit resultClass /// [Test] [Ignore("To do")] public void TestTimeSpanWithoutResultClass() { } #endregion } }