DynamicTest.cs :  » Persistence-Frameworks » iBATIS.NET » IBatisNet » DataMapper » Test » NUnit » SqlMapTests » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » iBATIS.NET 
iBATIS.NET » IBatisNet » DataMapper » Test » NUnit » SqlMapTests » DynamicTest.cs
using System;
using System.Collections;
using System.Configuration;

using NUnit.Framework;

using IBatisNet.DataMapper.Test;
using IBatisNet.DataMapper.Test.Domain;

namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests{
    /// <summary>
    /// Summary description for DynamicTest.
    /// </summary>
    [TestFixture]
    public class DynamicTest : BaseTest
    {
        #region SetUp & TearDown

        /// <summary>
        /// SetUp
        /// </summary>
        [SetUp]
        public void Init()
        {
            InitScript(sqlMap.DataSource, ScriptDirectory + "account-init.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "account-procedure.sql", false);
            InitScript(sqlMap.DataSource, ScriptDirectory + "order-init.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "line-item-init.sql");
        }

        /// <summary>
        /// TearDown
        /// </summary>
        [TearDown]
        public void Dispose()
        { /* ... */ }

        #endregion

        #region Dynamic tests

        /// <summary>
        /// Test Dynamic Sql On Column Selection
        /// JIRA IBATISNET-114
        /// </summary>
        [Test]
        public void TestDynamicSqlOnColumnSelection()
        {
            Account paramAccount = new Account();
            Account resultAccount = new Account();
            IList list = null;

            paramAccount.LastName = "Dalton";
            list = sqlMap.QueryForList("DynamicSqlOnColumnSelection", paramAccount);
            resultAccount = (Account)list[0];
            AssertAccount1(resultAccount);
            Assert.AreEqual(5, list.Count);

            paramAccount.LastName = "Bayon";
            list = sqlMap.QueryForList("DynamicSqlOnColumnSelection", paramAccount);
            resultAccount = (Account)list[0];
            Assert.IsNull(resultAccount.FirstName);
            Assert.IsNull(resultAccount.LastName);
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test IsNotEmpty True
        /// </summary>
        [Test]
        public void TestIsNotEmptyTrue()
        {
            IList list = sqlMap.QueryForList("DynamicIsNotEmpty", "Joe");
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(1, list.Count);
        }

        /// <summary>
        /// Test IsNotEmpty False
        /// </summary>
        [Test]
        public void TestIsNotEmptyFalse()
        {
            IList list = sqlMap.QueryForList("DynamicIsNotEmpty", "");
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test IsEqual true
        /// </summary>
        [Test]
        public void TestIsEqualTrue()
        {
            IList list = sqlMap.QueryForList("DynamicIsEqual", "Joe");
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(1, list.Count);
        }

        /// <summary>
        /// Test IsEqual False
        /// </summary>
        [Test]
        public void TestIsEqualFalse()
        {
            IList list = sqlMap.QueryForList("DynamicIsEqual", "BLAH!");
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test IsGreater true
        /// </summary>
        [Test]
        public void TestIsGreaterTrue()
        {
            IList list = sqlMap.QueryForList("DynamicIsGreater", 5);
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(1, list.Count);
        }

        /// <summary>
        /// Test IsGreater false
        /// </summary>
        [Test]
        public void TestIsGreaterFalse()
        {
            IList list = sqlMap.QueryForList("DynamicIsGreater", 1);
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test IsGreaterEqual true
        /// </summary>
        [Test]
        public void TestIsGreaterEqualTrue()
        {
            IList list = sqlMap.QueryForList("DynamicIsGreaterEqual", 3);
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(1, list.Count);
        }

        /// <summary>
        /// Test IsGreaterEqual false
        /// </summary>
        [Test]
        public void TestIsGreaterEqualFalse()
        {
            IList list = sqlMap.QueryForList("DynamicIsGreaterEqual", 1);
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test IsLess true
        /// </summary>
        [Test]
        public void TestIsLessTrue()
        {
            IList list = sqlMap.QueryForList("DynamicIsLess", 1);
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(1, list.Count);
        }

        /// <summary>
        /// Test IsLess false
        /// </summary>
        [Test]
        public void TestIsLessFalse()
        {
            IList list = sqlMap.QueryForList("DynamicIsLess", 5);
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test IsLessEqual true
        /// </summary>
        [Test]
        public void TestIsLessEqualTrue()
        {
            IList list = sqlMap.QueryForList("DynamicIsLessEqual", 3);
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(1, list.Count);
        }

        /// <summary>
        /// Test IsLessEqual false
        /// </summary>
        [Test]
        public void TestIsLessEqualFalse()
        {
            IList list = sqlMap.QueryForList("DynamicIsLessEqual", 5);
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test IsNotNull true
        /// </summary>
        [Test]
        public void TestIsNotNullTrue()
        {
            IList list = sqlMap.QueryForList("DynamicIsNotNull", "");
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(1, list.Count);
        }

        /// <summary>
        /// Test IsNotNull false
        /// </summary>
        [Test]
        public void TestIsNotNullFalse()
        {
            IList list = sqlMap.QueryForList("DynamicIsNotNull", null);
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test IsPropertyAvailable true
        /// </summary>
        [Test]
        public void TestIsPropertyAvailableTrue()
        {
            Account account = new Account();
            account.Id = 1;

            IList list = sqlMap.QueryForList("DynamicIsPropertyAvailable", account);
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(1, list.Count);
        }

        /// <summary>
        /// Test IsPropertyAvailable false
        /// </summary>
        [Test]
        public void TestIsPropertyAvailableFalse()
        {
            string parameter = "1";

            IList list = sqlMap.QueryForList("DynamicIsPropertyAvailable", parameter);
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test IsParameterPresent true
        /// </summary>
        [Test]
        public void TestIsParameterPresentTrue()
        {
            IList list = sqlMap.QueryForList("DynamicIsParameterPresent", 1);
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(1, list.Count);
        }

        /// <summary>
        /// Test IsParameterPresent false
        /// </summary>
        [Test]
        public void TestIsParameterPresentFalse()
        {
            IList list = sqlMap.QueryForList("DynamicIsParameterPresent", null);
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test Iterate 
        /// </summary>
        [Test]
        public void TestIterate()
        {
            IList parameters = new ArrayList();
            parameters.Add(1);
            parameters.Add(2);
            parameters.Add(3);

            IList list = sqlMap.QueryForList("DynamicIterate", parameters);
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(3, list.Count);
        }

        /// <summary>
        /// Test Iterate 2
        /// </summary>
        [Test]
        public void TestIterate2()
        {
            Account account = new Account();
            account.Ids = new int[3] { 1, 2, 3 };

            IList list = sqlMap.QueryForList("DynamicIterate2", account);
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(3, list.Count);
        }

        /// <summary>
        /// Test Empty Parameter Object
        /// </summary>
        [Test]
        public void TestEmptyParameterObject()
        {
            Account account = new Account();
            account.Id = -1;

            IList list = sqlMap.QueryForList("DynamicQueryByExample", account);

            AssertAccount1((Account)list[0]);
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test Dynamic With Extend
        /// </summary>
        [Test]
        public void TestDynamicWithExtend()
        {
            Account account = new Account();
            account.Id = -1;

            IList list = sqlMap.QueryForList("DynamicWithExtend", account);

            AssertAccount1((Account)list[0]);
            Assert.AreEqual(5, list.Count);
        }

        /// <summary>
        /// Test Multiple Iterate
        /// </summary>
        [Test]
        public void TestMultiIterate()
        {
            IList parameters = new ArrayList();
            parameters.Add(1);
            parameters.Add(2);
            parameters.Add(3);

            IList list = sqlMap.QueryForList("MultiDynamicIterate", parameters);

            AssertAccount1((Account)list[0]);
            Assert.AreEqual(3, list.Count);
        }

        /// <summary>
        /// Test Array Property Iterate
        /// </summary>
        [Test]
        public void TestArrayPropertyIterate()
        {
            Account account = new Account();
            account.Ids = new int[3] { 1, 2, 3 };

            IList list = sqlMap.QueryForList("DynamicQueryByExample", account);

            AssertAccount1((Account)list[0]);
            Assert.AreEqual(3, list.Count);
        }

        /// <summary>
        /// Test Complete Statement Substitution
        /// </summary>
        [Test]
        [Ignore("No longer supported.")]
        public void TestCompleteStatementSubst()
        {
            string statement = "select" +
            "    Account_ID      as Id," +
            "    Account_FirstName  as FirstName," +
            "    Account_LastName  as LastName," +
            "    Account_Email    as EmailAddress" +
            "  from Accounts" +
            "  where Account_ID = #id#";
            int id = 1;

            Hashtable parameters = new Hashtable();
            parameters.Add("id", id);
            parameters.Add("statement", statement);

            IList list = sqlMap.QueryForList("DynamicSubst", parameters);
            AssertAccount1((Account)list[0]);
            Assert.AreEqual(1, list.Count);
        }

        /// <summary>
        /// Test Query By Example
        /// </summary>
        [Test]
        public void TestQueryByExample()
        {
            Account account;

            account = new Account();

            account.Id = 5;
            account = sqlMap.QueryForObject("DynamicQueryByExample", account) as Account;
            AssertGilles(account);

            account = new Account();
            account.FirstName = "Gilles";
            account = sqlMap.QueryForObject("DynamicQueryByExample", account) as Account;
            AssertGilles(account);

            account = new Account();
            account.LastName = "Bayon";
            account = sqlMap.QueryForObject("DynamicQueryByExample", account) as Account;
            AssertGilles(account);

            account = new Account();
            account.EmailAddress = "gilles";
            account = (Account)sqlMap.QueryForObject("DynamicQueryByExample", account) as Account;
            AssertGilles(account);

            account = new Account();
            account.Id = 5;
            account.FirstName = "Gilles";
            account.LastName = "Bayon";
            account.EmailAddress = "gilles.bayon@nospam.org";
            account = sqlMap.QueryForObject("DynamicQueryByExample", account) as Account;
            AssertGilles(account);
        }

        /// <summary>
        /// Test Query By Example via private field
        /// </summary>
        [Test]
        public void TestQueryByExampleViaField()
        {
            Account account;

            account = new Account();

            account.Id = 5;
            account = sqlMap.QueryForObject("DynamicQueryByExampleViaPrivateField", account) as Account;
            AssertGilles(account);

            account = new Account();
            account.FirstName = "Gilles";
            account = sqlMap.QueryForObject("DynamicQueryByExampleViaPrivateField", account) as Account;
            AssertGilles(account);

            account = new Account();
            account.LastName = "Bayon";
            account = sqlMap.QueryForObject("DynamicQueryByExampleViaPrivateField", account) as Account;
            AssertGilles(account);

            account = new Account();
            account.EmailAddress = "gilles";
            account = (Account)sqlMap.QueryForObject("DynamicQueryByExampleViaPrivateField", account) as Account;
            AssertGilles(account);

            account = new Account();
            account.Id = 5;
            account.FirstName = "Gilles";
            account.LastName = "Bayon";
            account.EmailAddress = "gilles.bayon@nospam.org";
            account = sqlMap.QueryForObject("DynamicQueryByExampleViaPrivateField", account) as Account;
            AssertGilles(account);
        }
        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.