GroupByTest.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 » GroupByTest.cs

using System.Collections;
#if dotnet2
using System.Collections.Generic;
#endif
using IBatisNet.DataMapper.Test.Domain;

using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

using CategoryIBatisNet.DataMapper.Test.Domain.Petshop.Category;

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

        /// <summary>
        /// SetUp
        /// </summary>
        [TestFixtureSetUp]
        protected override void SetUpFixture()
        {
            base.SetUpFixture();

            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-drop.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-schema.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-init.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "child-parent-init.sql");

        }


        /// <summary>
        /// Dispose the SqlMap
        /// </summary>
        [TestFixtureTearDown]
        protected override void TearDownFixture()
        {
            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-drop.sql");
            base.TearDownFixture();
        }
        #endregion

#if dotnet2
        [Test]
        public void TestBobHanson ()
        {
            InitScript(sqlMap.DataSource, ScriptDirectory + "groupby-schema.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "groupby-init.sql");

            IList<Application> list = sqlMap.QueryForList<Application>("GroupByBobHanson", null);
            Assert.AreEqual(1, list.Count);
            Application application = list[0];

            Assert.AreEqual("Admin", application.DefaultRole.Name);
            Assert.AreEqual(2, application.Users.Count);
            Assert.AreEqual("user1", application.Users[0].UserName);
            Assert.IsNull(application.Users[0].Address);
            
            Assert.AreEqual(1, application.Users[0].Roles.Count);
            Assert.AreEqual("User", application.Users[0].Roles[0].Name);

            Assert.AreEqual(2, application.Users[1].Roles.Count);
            Assert.AreEqual("User", application.Users[1].Roles[1].Name);
            Assert.AreEqual("Admin", application.Users[1].Roles[0].Name);

        }

        [Test]
        [Category("JIRA-253")]
        public void Issue_When_Using_Sql_Timestamp_Data_Type()
        {
            IList<Parent> parents = sqlMap.QueryForList<Parent>("GetAllParentsNPlus1", null);

            Assert.That(parents[0].Children.Count, Is.EqualTo(2));
            Assert.That(parents[1].Children.Count, Is.EqualTo(0));
        }
#endif

        [Test]
        public void TestGroupByWithNullSon() 
        {
            IList list = sqlMap.QueryForList("GetCategories", null);
            Assert.AreEqual(6, list.Count);
        }

        [Test]
        public void TestGroupBy()
        {
            IList list = sqlMap.QueryForList("GetAllCategories", null);
            Assert.AreEqual(5, list.Count);
        }
        
        [Test]
        public void TestGroupByExtended()  
        {
            IList list = sqlMap.QueryForList("GetAllCategoriesExtended", null);
            Assert.AreEqual(5, list.Count);
        }

        [Test]
        public void TestNestedProperties()
        {
            IList list = sqlMap.QueryForList("GetFish", null);
            Assert.AreEqual(1, list.Count);

            Domain.Petshop.Category cat = (Domain.Petshop.Category)list[0];
            Assert.AreEqual("FISH", cat.Id);
            Assert.AreEqual("Fish", cat.Name);
            Assert.IsNotNull(cat.Products, "Expected product list.");
            Assert.AreEqual(4, cat.Products.Count);

            Domain.Petshop.Product product = (Domain.Petshop.Product)cat.Products[0];
            Assert.AreEqual(2, product.Items.Count);
        }

        [Test]
        public void TestForQueryForObject()
        {
            Domain.Petshop.Category cat = (Domain.Petshop.Category)sqlMap.QueryForObject("GetFish", null);
            Assert.IsNotNull(cat);

            Assert.AreEqual("FISH", cat.Id);
            Assert.AreEqual("Fish", cat.Name);
            Assert.IsNotNull(cat.Products, "Expected product list.");
            Assert.AreEqual(4, cat.Products.Count);

            Domain.Petshop.Product product = (Domain.Petshop.Product)cat.Products[0];
            Assert.AreEqual(2, product.Items.Count);
        }

#if dotnet2

        [Test]
        public void TestGenericFish()
        {
            IList list = sqlMap.QueryForList("GetFishGeneric", null);
            Assert.AreEqual(1, list.Count);

            Domain.Petshop.Category cat = (Domain.Petshop.Category)list[0];
            Assert.AreEqual("FISH", cat.Id);
            Assert.AreEqual("Fish", cat.Name);
            Assert.IsNotNull(cat.GenericProducts, "Expected product list.");
            Assert.AreEqual(4, cat.GenericProducts.Count);

            Domain.Petshop.Product product = cat.GenericProducts[0];
            Assert.AreEqual(2, product.GenericItems.Count);
        }

        [Test]
        public void TestForQueryForObjectGeneric()
        {
            Domain.Petshop.Category cat = sqlMap.QueryForObject<Domain.Petshop.Category>("GetFishGeneric", null);
            Assert.IsNotNull(cat);

            Assert.AreEqual("FISH", cat.Id);
            Assert.AreEqual("Fish", cat.Name);
            Assert.IsNotNull(cat.GenericProducts, "Expected product list.");
            Assert.AreEqual(4, cat.GenericProducts.Count);

            Domain.Petshop.Product product = cat.GenericProducts[0];
            Assert.AreEqual(2, product.GenericItems.Count);
        }

        [Test]
        public void TestJira241()
        {
            Category myCategory = new Category();

            sqlMap.QueryForObject<Category>("GetFishGeneric", null, myCategory);
            Assert.IsNotNull(myCategory);

            Assert.AreEqual("FISH", myCategory.Id);
            Assert.AreEqual("Fish", myCategory.Name);
            Assert.IsNotNull(myCategory.GenericProducts, "Expected product list.");
            Assert.AreEqual(4, myCategory.GenericProducts.Count);

            Domain.Petshop.Product product = myCategory.GenericProducts[0];
            Assert.AreEqual(2, product.GenericItems.Count);
        }

        [Test]
        public void TestGenericList()
        {
            IList<Domain.Petshop.Category> list = sqlMap.QueryForList<Domain.Petshop.Category>("GetFishGeneric", null);
            Assert.AreEqual(1, list.Count);

            Domain.Petshop.Category cat = list[0];
            Assert.AreEqual("FISH", cat.Id);
            Assert.AreEqual("Fish", cat.Name);
            Assert.IsNotNull(cat.GenericProducts, "Expected product list.");
            Assert.AreEqual(4, cat.GenericProducts.Count);

            Domain.Petshop.Product product = cat.GenericProducts[0];
            Assert.AreEqual(2, product.GenericItems.Count);
        }
#endif
        
        [Test]
        public void TestGroupByNull()
        {
            IList list = sqlMap.QueryForList("GetAllProductCategoriesJIRA250", null);
            Domain.Petshop.Category cat = (Domain.Petshop.Category)list[0];
            Assert.AreEqual(0, cat.Products.Count);
        }
        
        /// <summary>
        /// Test Select N+1 on Order/LineItem
        /// </summary>
        [Test]
        public void TestOrderLineItemGroupBy()
        {
            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-drop.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "account-init.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "order-init.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "line-item-init.sql");

            Order order = new Order();
            order.Id = 11;
            LineItem item = new LineItem();
            item.Id = 10;
            item.Code = "blah";
            item.Price = 44.00m;
            item.Quantity = 1;
            item.Order = order;

            sqlMap.Insert("InsertLineItemPostKey", item);

            
            IList list = sqlMap.QueryForList("GetOrderLineItem", null);

            Assert.AreEqual(11, list.Count);
            
            order = (Order)list[0];
            Assert.AreEqual(3, order.LineItemsIList.Count);
            Assert.IsNotNull(order.Account);
            AssertAccount1(order.Account);

            order = (Order)list[10];
            Assert.AreEqual(1, order.LineItemsIList.Count);
            Assert.IsNull(order.Account);
        }

#if dotnet2
        /// <summary>
        /// Test GroupBy With use of Inheritance
        /// </summary>
        [Test]
        public void GroupByWithInheritance()
        {
            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-drop.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "account-init.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "documents-init.sql");

            IList<Account> list = sqlMap.QueryForList<Account>("JIRA206", null);
            
            Assert.AreEqual(5, list.Count);
            Assert.AreEqual(0, list[0].Documents.Count);
            Assert.AreEqual(2, list[1].Documents.Count);
            Assert.AreEqual(1, list[2].Documents.Count);
            Assert.AreEqual(0, list[3].Documents.Count);
            Assert.AreEqual(2, list[4].Documents.Count);

            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-drop.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-schema.sql");
            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-init.sql");
        }
#endif
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.