/* $Id: RestrictionCheckerTest.cs,v 1.2 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.IO;
using NUnit.Framework;
using SQLToNeo.Model;
using SQLToNeo.Controller;
namespace SQLToNeo.Tests{
[TestFixture]
public class RestrictionCheckerTest
{
private RestrictionChecker _checker;
private DataSetController _dsc;
private string _testdataset = @"\testdataset.xml";
private string _testpath;
[SetUp]
public void Init()
{
_checker = new RestrictionChecker();
_dsc = new DataSetController();
_testpath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + _testdataset;
LoadTestData();
}
[Test]
public void RestrictionTest()
{
_checker.Validate(_dsc.CurrentDataSet);
int cnt = _checker.Conflicts.Count;
Console.WriteLine("Cnt : {0}", cnt);
Assert.IsTrue(cnt > 0, "Must return some conflicts!");
foreach(string s in _checker.Conflicts)
Console.WriteLine(s);
}
private void LoadTestData()
{
StreamWriter sw = new StreamWriter(_testpath);
sw.WriteLine(StringTest());
sw.Close();
_dsc.CurrentDataSet.ReadXml(_testpath);
File.Delete(_testpath);
}
#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>norque.dtd</norquedtd>
<neopath>..\Resources\</neopath>
<packagename>NeoCustomer.Model</packagename>
<neodbname>NeoCustomer</neodbname>
<modelpathfile>C:\temp\model1.xml</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>false</create> <!--conflict-->
</column>
<column>
<id>15</id>
<tableid>2</tableid>
<javaName>CustomerGuid</javaName>
<type>UNIQUEIDENTIFIER</type>
<required>true</required>
<hidden>false</hidden>
<primaryKey>false</primaryKey>
<create>false</create> <!--conflict-->
</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>false</create> <!--conflict-->
<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>
";
return teststring.Replace('','"');
}
#endregion
}
}
/*
* $Log: RestrictionCheckerTest.cs,v $
* Revision 1.2 2004/11/10 07:24:43 larsbm
* - optimized test cases
*
* Revision 1.1 2004/11/01 14:36:38 larsbm
* - Finished NeoXmlModelWriter
* - Fixed bugs in TableStyleCreator and TableBuilder
* - Implement new RestrictionChecker and additional test cases
*
*/
|