/* $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
*
*/
|