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

using NUnit.Framework;

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

namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.MSSQL{
  /// <summary>
  /// Summary description for StatementTest.
  /// </summary>
  [TestFixture] 
  [Category("MSSQL")]
  public class StatementTest : 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 + "ps_SelectAccount.sql", false );
      InitScript( sqlMap.DataSource, ScriptDirectory + "category-init.sql" );
      InitScript( sqlMap.DataSource, ScriptDirectory + "order-init.sql" );
    }

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

    #endregion

    #region Specific statement test for sql server

    /// <summary>
    /// Test Insert Account via store procedure
    /// </summary>
    [Test] 
    public void TestInsertAccountViaStoreProcedure() 
    {
      Account account = new Account();

      account.Id = 99;
      account.FirstName = "Achille";
      account.LastName = "Talon";
      account.EmailAddress = "Achille.Talon@somewhere.com";

      sqlMap.Insert("InsertAccountViaStoreProcedure", account);

      Account testAccount = sqlMap.QueryForObject("GetAccountViaColumnName", 99) as Account;

      Assert.IsNotNull(testAccount);
      Assert.AreEqual(99, testAccount.Id);
    }

    /// <summary>
    /// Test an insert with identity key.
    /// </summary>
    [Test] 
    public void TestInsertIdentityViaInsertQuery()
    {
      Category category = new Category();
      category.Name = "toto";
      category.Guid = Guid.NewGuid();

      int key = (int)sqlMap.Insert("InsertCategory", category);
      Assert.AreEqual(1, key);
    }

        /// <summary>
        /// Test an insert using SCOPE_IDENTITY.
        /// </summary>
        [Test]
        public void TestInsertCategoryScope()
        {
            Category category = new Category();
            category.Name = "toto";
            category.Guid = Guid.NewGuid();

            sqlMap.QueryForObject("InsertCategoryScope", category, category);
            Assert.That(category.Id, Is.EqualTo(1));
        }

    /// <summary>
    /// Test Insert Via Insert Statement.
    /// (Test for IBATISNET-21 : Property substitutions do not occur inside selectKey statement)
    /// </summary>
    [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);
    }

    /// <summary>
    /// Test statement with properties subtitutions
    /// (Test for IBATISNET-21 : Property substitutions do not occur inside selectKey statement)
    /// </summary>
    [Test] 
    public void TestInsertCategoryWithProperties()
    {
      Category category = new Category();
      category.Guid = Guid.NewGuid();

      int key = (int)sqlMap.Insert("InsertCategoryWithProperties", category);

      Category categoryTest = sqlMap.QueryForObject("GetCategory", key) as Category;
      Assert.AreEqual(key, categoryTest.Id);
      Assert.AreEqual("Film", categoryTest.Name);
      Assert.AreEqual(category.Guid, categoryTest.Guid);
    }

    /// <summary>
    /// Test guid column/field.
    /// </summary>
    [Test] 
    public void TestGuidColumn()
    {
      Category category = new Category();
      category.Name = "toto";
      category.Guid = Guid.NewGuid();

      int key = (int)sqlMap.Insert("InsertCategory", 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);
    }

    /// <summary>
    /// Test guid column/field through parameterClass.
    /// </summary>
    [Test] 
    public void TestGuidColumnParameterClass() {
      Guid newGuid = Guid.NewGuid();
      int key = (int)sqlMap.Insert("InsertCategoryGuidParameterClass", newGuid);

      Category categoryTest = (Category)sqlMap.QueryForObject("GetCategory", key);
      Assert.AreEqual(key, categoryTest.Id);
      Assert.AreEqual("toto", categoryTest.Name);
      Assert.AreEqual(newGuid, categoryTest.Guid);
    }

    /// <summary>
    /// Test guid column/field through parameterClass without specifiyng dbType
    /// </summary>
    [Test] 
    public void TestGuidColumnParameterClassJIRA20() 
    {
      Guid newGuid = Guid.NewGuid();
      int key = (int)sqlMap.Insert("InsertCategoryGuidParameterClassJIRA20", newGuid);

      Category categoryTest = (Category)sqlMap.QueryForObject("GetCategory", key);
      Assert.AreEqual(key, categoryTest.Id);
      Assert.AreEqual("toto", categoryTest.Name);
      Assert.AreEqual(newGuid, categoryTest.Guid);
    }

    /// <summary>
    /// Test Insert Category Via ParameterMap.
    /// </summary>
    [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);
    }

    /// <summary>
    /// Test Update Category with Extended ParameterMap
    /// </summary>
    [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());
    }

    /// <summary>
    /// Test select via store procedure
    /// </summary>
    [Test] 
    public void TestSelect()
    {
      Order order = (Order) sqlMap.QueryForObject("GetOrderWithAccountViaSP", 1);
      AssertOrder1(order);
      AssertAccount1(order.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.