using System; using System.Collections; using NUnit.Framework; using IBatisNet.DataMapper.Test.NUnit; using IBatisNet.DataMapper.Test.Domain; namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.MySql { /// /// Summary description for StatementTest. /// [TestFixture] [Category("MySql")] public class StatementTest : BaseTest { #region SetUp & TearDown /// /// SetUp /// [SetUp] public void Init() { InitScript( sqlMap.DataSource, ScriptDirectory + "category-init.sql" ); } /// /// TearDown /// [TearDown] public void Dispose() { /* ... */ } #endregion #region Specific tests for MySql /// /// Test an insert with an autonumber key. /// [Test] public void TestInsertAutonumberViaInsertQuery() { Category category = new Category(); category.Name = "toto"; category.Guid = Guid.NewGuid(); int key = (int)sqlMap.Insert("InsertCategory", category); Assert.AreEqual(1, key); } /// /// Test Insert Via Insert Statement. /// [Test] public void TestInsertViaInsertStatement() { Category category = new Category(); category.Name = "toto"; category.Guid = Guid.NewGuid(); int key = (int)sqlMap.Insert("InsertCategoryViaInsertStatement", category); Assert.AreEqual(1, key); } /// /// Test guid column/field. /// [Test] public void TestGuidColumn() { Category category = new Category(); category.Name = "toto"; category.Guid = Guid.NewGuid(); int key = (int)sqlMap.Insert("InsertCategoryViaInsertStatement", category); Category categoryTest = (Category)sqlMap.QueryForObject("GetCategory", key); Assert.AreEqual(key, categoryTest.Id); Assert.AreEqual(category.Name, categoryTest.Name); Assert.AreEqual(category.Guid, categoryTest.Guid); } /// /// Test Insert Category Via ParameterMap. /// [Test] public void TestInsertCategoryViaParameterMap() { Category category = new Category(); category.Name = "Cat"; category.Guid = Guid.NewGuid(); int key = (int)sqlMap.Insert("InsertCategoryViaParameterMap", category); Assert.AreEqual(1, key); } /// /// Test Update Category with Extended ParameterMap /// [Test] public void TestUpdateCategoryWithExtendParameterMap() { Category category = new Category(); category.Name = "Cat"; category.Guid = Guid.NewGuid(); int key = (int)sqlMap.Insert("InsertCategoryViaParameterMap", category); category.Id = key; category.Name = "Dog"; category.Guid = Guid.NewGuid(); sqlMap.Update("UpdateCategoryViaParameterMap", category); Category categoryRead = null; categoryRead = (Category) sqlMap.QueryForObject("GetCategory", key); Assert.AreEqual(category.Id, categoryRead.Id); Assert.AreEqual(category.Name, categoryRead.Name); Assert.AreEqual(category.Guid.ToString(), categoryRead.Guid.ToString()); } #endregion } }