ResultMapTest.cs :  » Persistence-Frameworks » iBATIS.NET » IBatisNet » DataMapper » Test » NUnit » SqlMapTests » Generics » 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 » Generics » ResultMapTest.cs
using System;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;

using NUnit.Framework;

using IBatisNet.DataMapper.Test.Domain;
using NUnit.Framework.SyntaxHelpers;

namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.Generics{
    /// <summary>
    /// Tests generic list
    /// 
    /// Interface tests
    /// 1) IList&lgt;LineItem&glt (Order.LineItemsGenericList) <--- QueryForList&lgt;LineItem&glt
    /// 2) IList&lgt;LineItem&glt (Order.LineItemsGenericList) <--- QueryForList&lgt;LineItem&glt Lazy load
    /// 3) IList&lgt;LineItem&glt (Order.LineItemsGenericList) <--- QueryForList&lgt;LineItem&glt with listClass = LineItemCollection2
    /// 4) IList&lgt;LineItem&glt (Order.LineItemsGenericList) <--- QueryForList&lgt;LineItem&glt with listClass = LineItemCollection2 lazy

    /// Strongly typed collection tests
    /// 5) LineItemCollection2 (Order.LineItemCollection2) <--- QueryForList&lgt;LineItem&glt with listClass = LineItemCollection2
    /// 6) LineItemCollection2 (Order.LineItemCollection2) <--- QueryForList&lgt;LineItem&glt  with listClass = LineItemCollection2 Lazy load
    /// </summary>
    [TestFixture] 
    public class ResultMapTest : BaseTest
    {
        #region SetUp & TearDown

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

        }

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

        #endregion

        #region Result Map test

        /// <summary>
        /// Coupons
        /// </summary>
        [Test]
        public void TestJIRA243WithGoupBy()
        {
            IList<Coupon> coupons = sqlMap.QueryForList<Coupon>("GetCouponBrand", null);

            Assert.That(coupons.Count, Is.EqualTo(5));
            Assert.That(coupons[0].BrandIds[0], Is.EqualTo(1));
            Assert.That(coupons[0].BrandIds[1], Is.EqualTo(2));
            Assert.That(coupons[0].BrandIds[2], Is.EqualTo(3));
            Assert.That(coupons[1].BrandIds[0], Is.EqualTo(4));
            Assert.That(coupons[1].BrandIds[1], Is.EqualTo(5));
            Assert.That(coupons[2].BrandIds.Count, Is.EqualTo(0));
            Assert.That(coupons[3].BrandIds.Count, Is.EqualTo(0));
            Assert.That(coupons[4].BrandIds[0], Is.EqualTo(6));
        }

        /// <summary>
        /// Coupons
        /// </summary>
        [Test]
        public void Test243WithoutGoupBy()
        {
            IList<Coupon> coupons = sqlMap.QueryForList<Coupon>("GetCoupons", null);

            Assert.That(coupons.Count, Is.EqualTo(5));
            Assert.That(coupons[0].BrandIds[0], Is.EqualTo(1));
            Assert.That(coupons[0].BrandIds[1], Is.EqualTo(2));
            Assert.That(coupons[0].BrandIds[2], Is.EqualTo(3));
            Assert.That(coupons[1].BrandIds[0], Is.EqualTo(4));
            Assert.That(coupons[1].BrandIds[1], Is.EqualTo(5));
            Assert.That(coupons[2].BrandIds.Count, Is.EqualTo(0));
            Assert.That(coupons[3].BrandIds.Count, Is.EqualTo(0));
            Assert.That(coupons[4].BrandIds[0], Is.EqualTo(6));
        }

        /// <summary>
        /// Test generic Ilist  : 
        /// 1) IList&lgt;LineItem&glt (Order.LineItemsGenericList) <--- QueryForList&lgt;LineItem&glt
        /// </summary>
        [Test]
        public void TestGenericList()
        {
            Order order = sqlMap.QueryForObject<Order>("GetOrderWithGenericListLineItem", 1);

            AssertOrder1(order);

            // Check generic IList collection
            Assert.IsNotNull(order.LineItemsGenericList);
            Assert.AreEqual(3, order.LineItemsGenericList.Count);
        }

        /// <summary>
        /// Test generic Ilist with lazy loading : 
        /// 2) IList&lgt;LineItem&glt (Order.LineItemsGenericList) <--- QueryForList&lgt;LineItem&glt Lazy load
        /// </summary>
        [Test]
        public void TestGenericListLazyLoad()
        {
            Order order = sqlMap.QueryForObject<Order>("GetOrderWithGenericLazyLoad", 1);

            AssertOrder1(order);

            // Check generic IList collection
            Assert.IsNotNull(order.LineItemsGenericList);
            Assert.AreEqual(3, order.LineItemsGenericList.Count);
        }

        /// <summary>
        /// Test generic typed generic Collection on generic IList  
        /// 3) IList&lgt;LineItem&glt (Order.LineItemsGenericList) <--- QueryForList&lgt;LineItem&glt with listClass = LineItemCollection2
        /// </summary>
        [Test]
        public void TestGenericCollectionOnIList()
        {
            Order order = sqlMap.QueryForObject<Order>("GetOrderWithGenericLineItemCollection", 1);

            AssertOrder1(order);

            // Check generic collection
            Assert.IsNotNull(order.LineItemsGenericList);
            Assert.AreEqual(3, order.LineItemsGenericList.Count);
            LineItemCollection2 lines = (LineItemCollection2)order.LineItemsGenericList;
        }

        /// <summary>
        /// Test generic IList with lazy typed collection 
        /// 4) IList&lgt;LineItem&glt (Order.LineItemsGenericList) <--- QueryForList&lgt;LineItem&glt with listClass = LineItemCollection2 lazy
        /// </summary>
        [Test]
        public void TestLazyListGenericMapping()
        {
            Order order = (Order)sqlMap.QueryForObject("GetOrderWithGenericLineItemsLazy", 1);

            AssertOrder1(order);

            Assert.IsNotNull(order.LineItemsGenericList);
            Assert.AreEqual(3, order.LineItemsGenericList.Count);
            LineItemCollection2 lines = (LineItemCollection2)order.LineItemsGenericList;
        }

        /// <summary>
        /// Test generic typed generic Collection on generic typed generic Collection
        /// 5) LineItemCollection2 (Order.LineItemCollection2) <--- QueryForList&lgt;LineItem&glt with listClass = LineItemCollection2
        /// </summary>
        [Test]
        public void TestTypedCollectionOnTypedCollection()
        {
            Order order = (Order)sqlMap.QueryForObject("GetOrderWithGenericTypedLineItemCollection", 1);

            AssertOrder1(order);

            Assert.IsNotNull(order.LineItemsCollection2);
            Assert.AreEqual(3, order.LineItemsCollection2.Count);

            IEnumerator<LineItem> e = ((IEnumerable<LineItem>)order.LineItemsCollection2).GetEnumerator();
            while (e.MoveNext())
            {
                LineItem item = e.Current;
                Assert.IsNotNull(item);
            }
        }

        /// <summary>
        /// Test generic typed generic Collection lazy
        /// 6) LineItemCollection2 (Order.LineItemCollection2) <--- QueryForList&lgt;LineItem&glt  with listClass = LineItemCollection2 Lazy load
        /// </summary>
        [Test]
        public void TestTypedCollectionLazy()
        {
            Order order = (Order)sqlMap.QueryForObject("GetOrderWithGenericTypedLineItemCollectionLazy", 1);

            AssertOrder1(order);

            Assert.IsNotNull(order.LineItemsCollection2);
            Assert.AreEqual(3, order.LineItemsCollection2.Count);

            IEnumerator<LineItem> e = ((IEnumerable<LineItem>)order.LineItemsCollection2).GetEnumerator();
            while (e.MoveNext())
            {
                LineItem item = e.Current;
                Assert.IsNotNull(item);
            }
        }

        #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.