InheritanceTest.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 » InheritanceTest.cs
using System;
using System.Collections;
using System.Configuration;

using NUnit.Framework;

using IBatisNet.DataMapper; //<-- To access the definition of the deleagte RowDelegate
using IBatisNet.DataMapper.MappedStatements; //<-- To access the definition of the PageinatedList
using IBatisNet.Common;
using IBatisNet.Common.Exceptions;

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

namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests{
  /// <summary>
  /// Summary description for InheritanceTest.
  /// </summary>
  [TestFixture] 
  public class InheritanceTest: BaseTest
  {

    #region SetUp & TearDown


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


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

    #endregion

    #region Tests

    /// <summary>
    /// Test All document with no formula
    /// </summary>
    [Test] 
    public void GetAllDocument() 
    {
      IList list = sqlMap.QueryForList("GetAllDocument", null);

      Assert.AreEqual(6, list.Count);
      Book book = (Book) list[0];
      AssertBook(book, 1, "The World of Null-A", 55);

      book = (Book) list[1];
      AssertBook(book, 3, "Lord of the Rings", 3587);

      Document document = (Document) list[2];
      AssertDocument(document, 5, "Le Monde");

      document = (Document) list[3];
      AssertDocument(document, 6, "Foundation");

      Newspaper news = (Newspaper) list[4];
      AssertNewspaper(news, 2, "Le Progres de Lyon", "Lyon");

      document = (Document) list[5];
      AssertDocument(document, 4, "Le Canard enchaine");
    }

    /// <summary>
    /// Test All document in a typed collection
    /// </summary>
    [Test] 
    public void GetTypedCollection() 
    {
      DocumentCollection list = sqlMap.QueryForList("GetTypedCollection", null) as DocumentCollection;

      Assert.AreEqual(6, list.Count);

      Book book = (Book) list[0];
      AssertBook(book, 1, "The World of Null-A", 55);

      book = (Book) list[1];
      AssertBook(book, 3, "Lord of the Rings", 3587);

      Document document = list[2];
      AssertDocument(document, 5, "Le Monde");

      document = list[3];
      AssertDocument(document, 6, "Foundation");

      Newspaper news = (Newspaper) list[4];
      AssertNewspaper(news, 2, "Le Progres de Lyon", "Lyon");

      document = list[5];
      AssertDocument(document, 4, "Le Canard enchaine");
    }

    /// <summary>
    /// Test All document with Custom Type Handler
    /// </summary>
    [Test] 
    public void GetAllDocumentWithCustomTypeHandler() 
    {
      IList list = sqlMap.QueryForList("GetAllDocumentWithCustomTypeHandler", null);

      Assert.AreEqual(6, list.Count);
      Book book = (Book) list[0];
      AssertBook(book, 1, "The World of Null-A", 55);

      book = (Book) list[1];
      AssertBook(book, 3, "Lord of the Rings", 3587);

      Newspaper news = (Newspaper) list[2];
      AssertNewspaper(news, 5, "Le Monde", "Paris");

      book = (Book) list[3];
      AssertBook(book, 6, "Foundation", 557);

      news = (Newspaper) list[4];
      AssertNewspaper(news, 2, "Le Progres de Lyon", "Lyon");

      news = (Newspaper) list[5];
      AssertNewspaper(news, 4, "Le Canard enchaine", "Paris");
    }
      
      /// <summary>
    /// Test Inheritance On Result Property
    /// </summary>
        [Test]
        public void TestJIRA175()
      {
            Account account = sqlMap.QueryForObject("JIRA175", 3) as Account;
            Assert.AreEqual(3, account.Id, "account.Id");
            Assert.AreEqual("William", account.FirstName, "account.FirstName");
          
            Book book = account.Document as Book;
            Assert.IsNotNull(book);
            AssertBook(book, 3, "Lord of the Rings", 3587);
      }
      
    #endregion 

    void AssertDocument(Document document, int id, string title)
    {
      Assert.AreEqual(id, document.Id);
      Assert.AreEqual(title, document.Title);
    }

    void AssertBook(Book book, int id, string title, int pageNumber)
    {
      Assert.AreEqual(id, book.Id);
      Assert.AreEqual(title, book.Title);
      Assert.AreEqual(pageNumber, book.PageNumber);
    }

    void AssertNewspaper(Newspaper news, int id, string title, string city)
    {
      Assert.AreEqual(id, news.Id);
      Assert.AreEqual(title, news.Title);
      Assert.AreEqual(city, news.City);
    }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.