MergeSpecialTest.cs :  » Persistence-Frameworks » NEO » SQLToNeo » Tests » 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 » NEO 
NEO » SQLToNeo » Tests » MergeSpecialTest.cs
/* $Id: MergeSpecialTest.cs,v 1.3 2004/11/10 07:24:43 larsbm Exp $
 * Copyright (c) 2004 Engine EAR GmbH & Co. KG
 * Developed by: Lars Behrmann, lb@engine.de
 */

using System;
using System.Data;
using NUnit.Framework;
using SQLToNeo.Model;
using SQLToNeo.Controller;

namespace SQLToNeo.Tests{
  /// <summary>
  /// MergeSpecialTest - Test for special merge
  /// </summary>
  [TestFixture]
  public class MergeSpecialTest
  {
    private DataSetController _dsc;
    private DataSet _ds;

    [SetUp]
    public void Init()
    {
      _dsc = new DataSetController();
      LoadContentToDatasets();
    }

    [Test]
    public void SpecialMergeTest()
    {
      MergeSpecial ms = new MergeSpecial();
      _ds = ms.Merge(_dsc.CurrentDataSet, _dsc.EmptyDataSet);
      Assert.IsNotNull(_ds, "Must return dataset!");
      Assert.IsNotNull((DataSet)PrivateTestClass.GetField(ms, "_current"), "No current dataset instance");
      Assert.IsNotNull((DataSet)PrivateTestClass.GetField(ms, "_currentDB"), "No currentDb dataset instance");
      Assert.IsTrue(_ds.Tables["table"].Select("javaname = 'CustomerTable'").Length > 0, "Row for CustomerTable must be existent!");
      Assert.IsTrue(_ds.Tables["table"].Select("javaname = 'OfferTable'").Length == 0, "Row for OfferTable must be deleted!");
      Assert.IsTrue(_ds.Tables["table"].Select("javaname = 'PricingTable'").Length > 0, "Row for PricingTable must be added!");
      Assert.IsTrue(_ds.Tables["column"].Select("javaname = 'NewTest'").Length > 0, "Row for column NewTest must be added!");
      Assert.IsTrue(_ds.Tables["column"].Select("javaname = 'Text'").Length == 0, "Row for Text must be deleted!");
      Assert.IsTrue(_ds.Tables["foreignkey"].Select("foreignTable = 'CustomerTable' and name ='Test'").Length == 0, "Row for foreignkey CustomerTable must be deleted!");
      Assert.AreEqual(_ds.Tables["column"].Select("javaname = 'SizeTest'")[0]["size"].ToString(), "200", "Size must be changed to 200");
      Assert.AreEqual(_ds.Tables["foreignkey"].Select("name = 'onDeleteTest'")[0]["onDelete"].ToString(), "cascade", "Row column onDelete must be changed to cascade");
      Assert.IsTrue(_ds.Tables["foreignkey"].Select("foreigntable = 'TestTable' and foreign = 'Guid'").Length > 0, "Row for foreignkey TableTest must be added!");
      OutputTest();
    }

    private void LoadContentToDatasets()
    {
      _dsc.LoadData("AbsolutelyNothing");
      //Load simulated content
      LoadTestData();
    }

    private void LoadTestData()
    {
      /*
       * Not the finest way to load test data, but it worked for me
       */
      DataRow dr;
      dr = _dsc.CurrentDataSet.Tables["table"].NewRow();
      dr["javaname"] = "CustomerTable";
      dr["name"] = "Customer";
      dr["create"] = true;
      _dsc.CurrentDataSet.Tables["table"].Rows.Add(dr);

      int id = Convert.ToInt32(_dsc.CurrentDataSet.Tables["table"].Select("javaname = 'CustomerTable'")[0]["id"].ToString());

      dr = _dsc.CurrentDataSet.Tables["table"].NewRow();
      dr["javaname"] = "TestTable";
      dr["name"] = "TestTable";
      dr["create"] = true;
      _dsc.CurrentDataSet.Tables["table"].Rows.Add(dr);

      int id1 = Convert.ToInt32(_dsc.CurrentDataSet.Tables["table"].Select("javaname = 'TestTable'")[0]["id"].ToString());
      Console.WriteLine("Id1 : {0}", id1);

      dr = _dsc.CurrentDataSet.Tables["table"].NewRow();
      dr["javaname"] = "OfferTable";
      dr["name"] = "Offer";
      dr["create"] = true;
      _dsc.CurrentDataSet.Tables["table"].Rows.Add(dr);

      dr = _dsc.CurrentDataSet.Tables["column"].NewRow();
      dr["javaname"] = "Text";
      dr["name"] = "Test";
      dr["create"] = true;
      dr["tableid"] = id;
      _dsc.CurrentDataSet.Tables["column"].Rows.Add(dr);

      dr = _dsc.CurrentDataSet.Tables["column"].NewRow();
      dr["javaname"] = "SizeTest";
      dr["name"] = "SizeTest";
      dr["create"] = true;
      dr["tableid"] = id;
      dr["size"] = "170";
      _dsc.CurrentDataSet.Tables["column"].Rows.Add(dr);

      dr = _dsc.CurrentDataSet.Tables["foreignkey"].NewRow();
      dr["foreigntable"] = "CustomerTable";
      dr["name"] = "Test";
      dr["create"] = true;
      dr["tableid"] = id;
      dr["local"] = "tableid";
      dr["foreign"] = "id";
      _dsc.CurrentDataSet.Tables["foreignkey"].Rows.Add(dr);

      dr = _dsc.CurrentDataSet.Tables["foreignkey"].NewRow();
      dr["foreigntable"] = "TestTable";
      dr["name"] = "onDeleteTest";
      dr["create"] = true;
      dr["tableid"] = id1;
      dr["local"] = "tableid";
      dr["foreign"] = "id";
      dr["onDelete"] = "none";
      _dsc.CurrentDataSet.Tables["foreignkey"].Rows.Add(dr);
      _dsc.CurrentDataSet.AcceptChanges();
      
      dr = _dsc.EmptyDataSet.Tables["table"].NewRow();
      dr["javaname"] = "CustomerTable";
      _dsc.EmptyDataSet.Tables["table"].Rows.Add(dr);

      dr = _dsc.EmptyDataSet.Tables["table"].NewRow();
      dr["javaname"] = "TestTable";
      dr["create"] = true;
      _dsc.EmptyDataSet.Tables["table"].Rows.Add(dr);

      dr = _dsc.EmptyDataSet.Tables["column"].NewRow();
      dr["javaname"] = "SizeTest";
      dr["name"] = "SizeTest";
      dr["create"] = true;
      dr["tableid"] = id;
      dr["size"] = "200";
      _dsc.EmptyDataSet.Tables["column"].Rows.Add(dr);

      dr = _dsc.EmptyDataSet.Tables["column"].NewRow();
      dr["javaname"] = "NewTest";
      dr["name"] = "NewTest";
      dr["create"] = true;
      dr["tableid"] = id;
      _dsc.EmptyDataSet.Tables["column"].Rows.Add(dr);

      dr = _dsc.EmptyDataSet.Tables["foreignkey"].NewRow();
      dr["foreigntable"] = "TestTable";
      dr["create"] = true;
      dr["tableid"] = id1;
      dr["local"] = "tableid";
      dr["foreign"] = "id";
      dr["onDelete"] = "cascade";
      _dsc.EmptyDataSet.Tables["foreignkey"].Rows.Add(dr);

      dr = _dsc.EmptyDataSet.Tables["foreignkey"].NewRow();
      dr["foreigntable"] = "TestTable";
      dr["create"] = true;
      dr["tableid"] = id1;
      dr["local"] = "tableid";
      dr["foreign"] = "Guid";
      dr["onDelete"] = "cascade";
      _dsc.EmptyDataSet.Tables["foreignkey"].Rows.Add(dr);

      dr = _dsc.EmptyDataSet.Tables["table"].NewRow();
      dr["javaname"] = "PricingTable";
      _dsc.EmptyDataSet.Tables["table"].Rows.Add(dr);
      _dsc.EmptyDataSet.AcceptChanges();
    }

    private void OutputTest()
    {
      foreach(DataRow d in _ds.Tables["table"].Rows)
        foreach(DataColumn dc in _ds.Tables["table"].Columns)
          Console.WriteLine("{0} = {1}", dc.ColumnName, d[dc.ColumnName]);
      Console.WriteLine("----------------------------------------------");

      foreach(DataRow d in _ds.Tables["column"].Rows)
        foreach(DataColumn dc in _ds.Tables["column"].Columns)
          Console.WriteLine("{0} = {1}", dc.ColumnName, d[dc.ColumnName]);
      Console.WriteLine("----------------------------------------------");
    }
  }
}

/*
 * $Log: MergeSpecialTest.cs,v $
 * Revision 1.3  2004/11/10 07:24:43  larsbm
 * - optimized test cases
 *
 * Revision 1.2  2004/10/26 13:23:46  larsbm
 * - Fixed bugs in tablebuilder
 * - Working on the forms
 * - Finishing MergeSpecial
 * - Make app run with mergespecial
 * - start converter for sqldatatypes
 *
 * Revision 1.1  2004/10/25 13:47:16  larsbm
 * - Add new classes MergeSpecial and MergSpecialTest
 * - Merging the current local model with the current db schema on the server
 *
 */
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.