/* $Id: NeoXMLModelWriterTest.cs,v 1.6 2004/11/24 13:57:06 larsbm Exp $
* Copyright (c) 2004 Engine EAR GmbH & Co. KG
* Developed by: Lars Behrmann, lb@engine.de
*/
using System;
using System.IO;
using System.Xml;
using System.Data;
using System.Collections;
using SQLToNeo.Model;
using SQLToNeo.Controller;
using NUnit.Framework;
using SQLToNeo.PlugIn;
namespace SQLToNeo.Tests{
/// <summary>
/// NeoXMLModelWriterTest.
/// </summary>
[TestFixture]
public class NeoXMLModelWriterTest
{
private Writer _writer;
private DataSetController _dscontroller;
private XmlDocument _xmldoc;
private string _testfile;
private string _tempdatasetfile;
//Change if you would, this path and filename will be replaced in the teststring have a look at TestString
private string _testwritefolder;
private string _modelname = @"\nunit_modelfile.xml";
private string _datasetname = @"\nunit_tmp_dataset.xml";
[SetUp]
public void Init()
{
_testwritefolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
_testfile = _testwritefolder + _modelname;
_tempdatasetfile = _testwritefolder + _datasetname;
_writer = new Writer((IWriter)Activator.CreateInstance(typeof(NeoXMLModelWriter)));
_dscontroller = new DataSetController();
LoadTestData();
}
[Test]
public void WriteTest()
{
Assert.AreEqual("Neo XML", _writer.Instance.WriterName, "Writer name must be 'Neo XML'");
Assert.IsTrue(_writer.Instance.Write(_dscontroller.CurrentDataSet), "Writing the xml model must be succesfull!");
LoadXmlModel();
Assert.IsNotNull(_xmldoc.SelectSingleNode("//database").Attributes["name"].InnerText, "Node norquedtd shouldn't be empty!");
Assert.IsNotNull(_xmldoc.SelectSingleNode("database/table[@javaName='Contactperson']"), "Couldn't get node table where attribute javaname = Contactperson.");
Assert.IsNotNull(_xmldoc.SelectSingleNode("database/table[@javaName='Customer']/column[@javaName='Company']"), "Couldn't get node column where attribute javaname = Company.");
Assert.IsNotNull(_xmldoc.SelectSingleNode("database/table[@javaName='Contactperson']/foreign-key[@foreignTable='Customer']"), "Couldn't get node foreign-key where attribute foreignTable = Customer.");
Assert.IsNotNull(_xmldoc.SelectSingleNode("database/table[@javaName='Customer']/iforeign-key[@foreignTable='Contactperson']"), "Couldn't get node iforeign-key where attribute foreignTable = Contactperson.");
}
private void LoadXmlModel()
{
DoctypeDTDCall();
_xmldoc = new XmlDocument();
_xmldoc.Load(_testfile);
}
private void DoctypeDTDCall()
{
//Must delete doctype! Otherwise xmldocument wouldn't load the test model!
ArrayList al = new ArrayList();
StreamReader sr = new StreamReader(_testfile);
while(sr.Peek() >= 0)
al.Add(sr.ReadLine());
sr.Close();
al.RemoveAt(1);
StreamWriter sw = new StreamWriter(_testfile);
foreach(string s in al)
sw.WriteLine(s);
sw.Close();
}
private void LoadTestData()
{
try
{
StreamWriter sw = new StreamWriter(_tempdatasetfile);
sw.Write(StringTest());
sw.Close();
try
{
_dscontroller.CurrentDataSet.ReadXml(_tempdatasetfile,XmlReadMode.ReadSchema);
}
catch(XmlException exx)
{
System.Windows.Forms.MessageBox.Show("Exception while loading xml testdata into dataset!\n\nMessage:\n" + exx.Message + "\n\nStack:\n" + exx.StackTrace);
}
File.Delete(_tempdatasetfile);
}
catch(IOException ex)
{
System.Windows.Forms.MessageBox.Show("Exception while reading resp.writing testdata!\n" + ex.Message);
}
}
#region teststring with some data
private string StringTest()
{
string teststring =
@"<?xml version=1.0 standalone=yes?>
<CurrentDataSet>
<xs:schema id=CurrentDataSet xmlns= xmlns:xs=http://www.w3.org/2001/XMLSchema xmlns:msdata=urn:schemas-microsoft-com:xml-msdata>
<xs:element name=CurrentDataSet msdata:IsDataSet=true msdata:Locale=de-DE>
<xs:complexType>
<xs:choice maxOccurs=unbounded>
<xs:element name=xml>
<xs:complexType>
<xs:sequence>
<xs:element name=id msdata:AutoIncrement=true type=xs:int />
<xs:element name=norquedtd type=xs:string default=norque.dtd minOccurs=0 />
<xs:element name=neopath type=xs:string minOccurs=0 />
<xs:element name=packagename type=xs:string minOccurs=0 />
<xs:element name=neodbname type=xs:string minOccurs=0 />
<xs:element name=modelpathfile type=xs:string minOccurs=0 />
<xs:element name=idmethod type=xs:string default=guid minOccurs=0 />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=table>
<xs:complexType>
<xs:sequence>
<xs:element name=id msdata:AutoIncrement=true type=xs:int />
<xs:element name=name type=xs:string minOccurs=0 />
<xs:element name=javaName type=xs:string minOccurs=0 />
<xs:element name=create type=xs:boolean default=true minOccurs=0 />
<xs:element name=column minOccurs=0 maxOccurs=unbounded>
<xs:complexType>
<xs:sequence>
<xs:element name=id msdata:AutoIncrement=true type=xs:int />
<xs:element name=tableid type=xs:int minOccurs=0 />
<xs:element name=javaName type=xs:string minOccurs=0 />
<xs:element name=name type=xs:string minOccurs=0 />
<xs:element name=type type=xs:string minOccurs=0 />
<xs:element name=size type=xs:int minOccurs=0 />
<xs:element name=required type=xs:boolean minOccurs=0 />
<xs:element name=hidden type=xs:boolean default=false minOccurs=0 />
<xs:element name=primaryKey type=xs:boolean minOccurs=0 />
<xs:element name=create type=xs:boolean default=true minOccurs=0 />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=foreignkey minOccurs=0 maxOccurs=unbounded>
<xs:complexType>
<xs:sequence>
<xs:element name=id msdata:AutoIncrement=true type=xs:int />
<xs:element name=tableid type=xs:int minOccurs=0 />
<xs:element name=foreigntable type=xs:string minOccurs=0 />
<xs:element name=name type=xs:string minOccurs=0 />
<xs:element name=local type=xs:string minOccurs=0 />
<xs:element name=foreign type=xs:string minOccurs=0 />
<xs:element name=onUpdate type=xs:string minOccurs=0 />
<xs:element name=onDelete type=xs:string minOccurs=0 />
<xs:element name=create type=xs:boolean default=true minOccurs=0 />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=iforeignkey minOccurs=0 maxOccurs=unbounded>
<xs:complexType>
<xs:sequence>
<xs:element name=id msdata:AutoIncrement=true type=xs:int />
<xs:element name=tableid type=xs:int minOccurs=0 />
<xs:element name=foreigntable type=xs:string minOccurs=0 />
<xs:element name=name type=xs:string minOccurs=0 />
<xs:element name=local type=xs:string minOccurs=0 />
<xs:element name=foreign type=xs:string minOccurs=0 />
<xs:element name=onUpdate type=xs:string minOccurs=0 />
<xs:element name=onDelete type=xs:string minOccurs=0 />
<xs:element name=create type=xs:boolean default=true minOccurs=0 />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name=Constraint1 msdata:PrimaryKey=true>
<xs:selector xpath=.//xml />
<xs:field xpath=id />
</xs:unique>
<xs:unique name=column_Constraint1 msdata:ConstraintName=Constraint1 msdata:PrimaryKey=true>
<xs:selector xpath=.//column />
<xs:field xpath=id />
</xs:unique>
<xs:unique name=foreignkey_Constraint1 msdata:ConstraintName=Constraint1 msdata:PrimaryKey=true>
<xs:selector xpath=.//foreignkey />
<xs:field xpath=id />
</xs:unique>
<xs:unique name=iforeignkey_Constraint1 msdata:ConstraintName=Constraint1 msdata:PrimaryKey=true>
<xs:selector xpath=.//iforeignkey />
<xs:field xpath=id />
</xs:unique>
<xs:unique name=table_Constraint1 msdata:ConstraintName=Constraint1 msdata:PrimaryKey=true>
<xs:selector xpath=.//table />
<xs:field xpath=id />
</xs:unique>
<xs:keyref name=iforeignkeys refer=table_Constraint1 msdata:IsNested=true>
<xs:selector xpath=.//iforeignkey />
<xs:field xpath=tableid />
</xs:keyref>
<xs:keyref name=foreignkeys refer=table_Constraint1 msdata:IsNested=true>
<xs:selector xpath=.//foreignkey />
<xs:field xpath=tableid />
</xs:keyref>
<xs:keyref name=cols refer=table_Constraint1 msdata:IsNested=true>
<xs:selector xpath=.//column />
<xs:field xpath=tableid />
</xs:keyref>
</xs:element>
</xs:schema>
<xml>
<id>0</id>
<norquedtd>..\Resources\norque.dtd</norquedtd>
<neopath>..\Resources\</neopath>
<packagename>NeoCustomer.Model</packagename>
<neodbname>NeoCustomer</neodbname>
<modelpathfile>#outputfile#</modelpathfile>
<idmethod>guid</idmethod>
</xml>
<table>
<id>0</id>
<name>Contactperson</name>
<javaName>Contactperson</javaName>
<create>true</create>
<column>
<id>0</id>
<tableid>0</tableid>
<javaName>Guid</javaName>
<type>UNIQUEIDENTIFIER</type>
<required>false</required>
<hidden>false</hidden>
<primaryKey>true</primaryKey>
<create>true</create>
</column>
<column>
<id>1</id>
<tableid>0</tableid>
<javaName>CustomerGuid</javaName>
<type>UNIQUEIDENTIFIER</type>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>2</id>
<tableid>0</tableid>
<javaName>Name</javaName>
<type>VARCHAR</type>
<size>50</size>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>3</id>
<tableid>0</tableid>
<javaName>Telephone</javaName>
<type>INTEGER</type>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>4</id>
<tableid>0</tableid>
<javaName>Faxnumber</javaName>
<type>INTEGER</type>
<required>true</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>5</id>
<tableid>0</tableid>
<javaName>Email</javaName>
<type>VARCHAR</type>
<size>254</size>
<required>true</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<foreignkey>
<id>0</id>
<tableid>0</tableid>
<foreigntable>Customer</foreigntable>
<local>CustomerGuid</local>
<foreign>Guid</foreign>
<onUpdate>none</onUpdate>
<onDelete>none</onDelete>
<create>true</create>
</foreignkey>
</table>
<table>
<id>1</id>
<name>Customer</name>
<javaName>Customer</javaName>
<create>true</create>
<column>
<id>6</id>
<tableid>1</tableid>
<javaName>Guid</javaName>
<type>UNIQUEIDENTIFIER</type>
<required>false</required>
<hidden>false</hidden>
<primaryKey>true</primaryKey>
<create>true</create>
</column>
<column>
<id>7</id>
<tableid>1</tableid>
<javaName>Company</javaName>
<type>VARCHAR</type>
<size>254</size>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>8</id>
<tableid>1</tableid>
<javaName>Street</javaName>
<type>VARCHAR</type>
<size>50</size>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>9</id>
<tableid>1</tableid>
<javaName>City</javaName>
<type>VARCHAR</type>
<size>50</size>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>10</id>
<tableid>1</tableid>
<javaName>Zipcode</javaName>
<type>VARCHAR</type>
<size>8</size>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>11</id>
<tableid>1</tableid>
<javaName>Telephone</javaName>
<type>INTEGER</type>
<required>true</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>12</id>
<tableid>1</tableid>
<javaName>Fax</javaName>
<type>INTEGER</type>
<required>true</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>13</id>
<tableid>1</tableid>
<javaName>Homepage</javaName>
<type>VARCHAR</type>
<size>254</size>
<required>true</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<iforeignkey>
<id>0</id>
<tableid>1</tableid>
<foreigntable>Contactperson</foreigntable>
<local>Guid</local>
<foreign>CustomerGuid</foreign>
<onUpdate>none</onUpdate>
<onDelete>none</onDelete>
<create>true</create>
</iforeignkey>
<iforeignkey>
<id>1</id>
<tableid>1</tableid>
<foreigntable>Offer</foreigntable>
<local>Guid</local>
<foreign>CustomerGuid</foreign>
<onUpdate>cascade</onUpdate>
<onDelete>cascade</onDelete>
<create>true</create>
</iforeignkey>
<iforeignkey>
<id>2</id>
<tableid>1</tableid>
<foreigntable>Task</foreigntable>
<local>Guid</local>
<foreign>CustomerGuid</foreign>
<onUpdate>none</onUpdate>
<onDelete>cascade</onDelete>
<create>true</create>
</iforeignkey>
</table>
<table>
<id>2</id>
<name>Offer</name>
<javaName>Offer</javaName>
<create>true</create>
<column>
<id>14</id>
<tableid>2</tableid>
<javaName>Guid</javaName>
<type>UNIQUEIDENTIFIER</type>
<required>false</required>
<hidden>false</hidden>
<primaryKey>true</primaryKey>
<create>true</create>
</column>
<column>
<id>15</id>
<tableid>2</tableid>
<javaName>CustomerGuid</javaName>
<type>UNIQUEIDENTIFIER</type>
<required>true</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>16</id>
<tableid>2</tableid>
<javaName>Description</javaName>
<type>VARCHAR</type>
<size>1024</size>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>17</id>
<tableid>2</tableid>
<javaName>ValidTo</javaName>
<type>DATE</type>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>18</id>
<tableid>2</tableid>
<javaName>Title</javaName>
<type>VARCHAR</type>
<size>150</size>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<foreignkey>
<id>1</id>
<tableid>2</tableid>
<foreigntable>Customer</foreigntable>
<local>CustomerGuid</local>
<foreign>Guid</foreign>
<onUpdate>cascade</onUpdate>
<onDelete>cascade</onDelete>
<create>true</create>
</foreignkey>
</table>
<table>
<id>3</id>
<name>Task</name>
<javaName>Task</javaName>
<create>true</create>
<column>
<id>19</id>
<tableid>3</tableid>
<javaName>Id</javaName>
<name>Id</name>
<type>INTEGER</type>
<required>false</required>
<hidden>false</hidden>
<primaryKey>true</primaryKey>
<create>true</create>
</column>
<column>
<id>20</id>
<tableid>3</tableid>
<javaName>CustomerGuid</javaName>
<name>Customer</name>
<type>UNIQUEIDENTIFIER</type>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>21</id>
<tableid>3</tableid>
<javaName>Task</javaName>
<name>Task</name>
<type>VARCHAR</type>
<size>254</size>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>22</id>
<tableid>3</tableid>
<javaName>Start</javaName>
<name>Start</name>
<type>DATE</type>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<column>
<id>23</id>
<tableid>3</tableid>
<javaName>Ends</javaName>
<name>End</name>
<type>DATE</type>
<required>false</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>true</create>
</column>
<foreignkey>
<id>2</id>
<tableid>3</tableid>
<foreigntable>Customer</foreigntable>
<name>Customers</name>
<local>CustomerGuid</local>
<foreign>Guid</foreign>
<onUpdate>none</onUpdate>
<onDelete>cascade</onDelete>
<create>true</create>
</foreignkey>
</table>
</CurrentDataSet>
";
teststring = teststring.Replace('','"');
teststring = teststring.Replace("#outputfile#", _testfile);
return teststring;
}
#endregion
}
}
/*
* $Log: NeoXMLModelWriterTest.cs,v $
* Revision 1.6 2004/11/24 13:57:06 larsbm
* - new project SQLToNeoPlugIn
* - switched interfaces from mainsource into plug in
*
* Revision 1.5 2004/11/10 07:24:43 larsbm
* - optimized test cases
*
* Revision 1.4 2004/11/01 14:36:37 larsbm
* - Finished NeoXmlModelWriter
* - Fixed bugs in TableStyleCreator and TableBuilder
* - Implement new RestrictionChecker and additional test cases
*
* Revision 1.3 2004/10/29 13:49:37 larsbm
* - work on .. last todo realize "create = false"
*
* Revision 1.2 2004/10/28 13:47:23 larsbm
* - Work on ..
*
* Revision 1.1 2004/10/27 14:09:23 larsbm
* - Fixed bugs in tablebuilder, TablestyleCreator
* - Working on the forms
* - Finishing DBTypes
* - Add IWriter & Writer, NeoXMLModelWriter as abstraction for writing the xml model
*
*/
|