Entity Spaces Tests Getting Started
Entity Spaces Tests Getting Started
Registered members can download the entire EntitySpaces Test Suite for free from the download
forums. We highly recommend downloading the suite, even if you have no interest in testing and
do not intend to install NUnit. The source code contained in the test application and fixtures is an
invaluable resource, demonstrating nearly every function available in the EntitySpaces
architecture for .NET.
Because the tests are designed to run without user interaction, there are some significant EntitySpaces’ features that
are not well represented, most notably; the DataGridView and ComboBox binding that are demonstrated in the Trial
version’s SqlDemo. See this Blog to get some background on our testing philosophy.
Requirements:
• EntitySpaces architecture for .NET (the Trial version will do.)
• Microsoft .NET 2.0 Framework.
• Microsoft Visual Studio or Visual C# 2005 Express Edition.
• NUnit 2.2.6 or later.
• One or more of the following databases
o Microsoft SQL Server (2000 or later, including the MSDE and Express versions)
o Microsoft Access (2000 or later. AggregateDb.mdb is included in the Test Suite.)
o Oracle.
o MySQL (4.x may be used in DynamicSql mode. 5.x is required for Stored Procedure or View
support.)
Note to VB.NET developers: At this time, there is no testing application (Tests.exe) or solution for VB.NET. The
source code for all the test fixtures, generated, and custom classes has been converted to VB, however, and
represents a significant repository of sample code. You will find it in the \TestsVB\Tests folder.
Quick Start:
These steps assume you are using the Microsoft Access database AggregateDb.mdb located in
Tests\MSAccess. See these detailed instructions if you need to prepare SQL Server, MySQL or Oracle test
databases.
<add name="ACCESSDynamic"
providerMetadataKey="esAccess"
sqlAccessType="DynamicSQL"
provider="EntitySpaces.MSAccessProvider"
providerClass="DataProvider"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;
Data Source=C:\Program Files\EntitySpaces\Tests\Tests\MSAccess\AggregateDb.mdb;
Persist Security Info=False"
/>
A little GUI we coded to try different EntitySpaces queries, check code from user posts, and to debug failing
tests. There is a grid for the query results, a multi-line text box for displaying exceptions and/or
Query.LastQuery, and RowCounts can be displayed in the status bar. This is not intended to be a polished
demo and you will see a lot of commented code that is there to quickly test under different scenarios.
Tools Menu:
• Provider: You can chose between DynamicSql (Dynamic) and Stored Procedure (SP) mode for each of
the four supported databases; Access, SQL Server (SqlExpress,) MySQL, and Oracle. This sets the
connection used by Tests.exe to the matching one in app.config.
• RefreshDatabase: Deletes all rows in the AggregateTest table for the provider chosen above. Then,
thirty specific records are added. This sets the table to a known condition for the unit tests.
• Tests\Base: This folder contains all the test fixtures and the EntitySpaces Generated and Custom
classes for the SQL Server AggregateDb test database. The EntitySpaces Master templates were run in
MyGeneration for the AggregateTest table and the FullNameView. The only template that needed to be
run for Access, MySQL and Oracle was the EntitySpaces Generated MetadataMap template (once each
for the table and view.) It could have just as successfully been done the other way around – a full set
for Access and the MetadataMap for SQL Server, MySQL and Oracle. Just note that esDefault in
app.config should then be for Access, not SQL Server.
• Tests\MSAccess: You will find the generated source files for Access, AggregateDb.mdb, and the
stored procedure script that was run on it.
• Tests\MySQL: You will find the generated source files for MySQL and sql scripts for the database.
• Tests\Oracle: You will find the generated source files for Oracle and sql scripts for the database.
• Tests\SqlExpress: You will find the sql scripts for the database.
• Tests\TestsVB: All the VB.NET source code.
Buttons:
• Loadall: Loads all the rows for the provider selected from the Tools menu.
• Test 1: Runs whatever code is set up in buttonTest1_Click() against the database selected from
Tools|Provider.
• Test 2: Runs whatever code is set up in buttonTest2_Click() against the database selected from
Tools|Provider.
Out-of-the-box, Tests.exe is set up with some simple tests. The results of a test are displayed in the grid.
Query.LastQuery and/or any exception are displayed in the read-only text box at the top of the form. The
status bar contains the connection information that was selected from Tools|Provider and a row count.
For instances where Access does not support a feature or behaves differently than SQL Server, the test
fixtures have switch/case statements so the correct assertion is tested. For example, in some of the aggregate
tests, Access treats nulls differently than SQL Server and separate asserts were needed for the different
RowCounts. Unsupported features (like aggregates in a GroupBy) are flagged ignored for Access only. They
will show up yellow in the NUnit GUI and be listed on the Tests Not Run tab.
The RefreshDatabase() method removes any records in the database and re-populates it with known rows that
are required for the tests. It is called from the TestFixtureSetUp of the AggregateFixture. If you run a set of
tests on a database that has not been pre-populated with data, you may get many failing tests. Just click Run
again, as the database will now contain the expected data. You can also call RefreshDatabase() from the Tools
menu in Tests.exe.
In order to have a full set of tests that can be run against each supported database, we are taking advantage
of two things:
• EntitySpaces ability to dynamically change connections as long as the databases have matching
schemas.
• NUnit’s ability to match a specific NUnit project file to a corresponding NUnit config file.
All the NUnit project files are identical. The different names associate them with different NUnit config files.
The project files are pre-set to look for Tests.exe under Tests\bin\debug.
NUnit config files are identical in format to EntitySpaces app.config files. Consequently, you will see at least
two NUnit config files for each database, one for each sqlAccessType; DynamicSQL and StoredProcedure.
Microsoft SQL Server and Oracle have some additional configs using DataProviderEnterprise for the
providerClass. DataProviderEnterprise uses the new TransactionScope class in .NET 2. The default
providerClass uses esTransactionScope, which is built in to EntitySpaces. You need to open each config file
and make sure the connectionString matches the one in app.config for that database. Double-click one of the
.nunit files to run the tests in the NUnit GUI. Once the GUI is open, you can run other tests by opening the
other project files from File|Open.
Supported features for a particular configuration will display green in the NUnit GUI for passing tests and red
for failing. Unsupported features (like Aggregates in a GroupBy for Access) are flagged ignored in the test
fixture. They will show up yellow in the NUnit GUI and be listed on the Tests Not Run tab.
AggregateDb.mdb is located in Tests\MSAccess and contains everything needed for the tests. The
EntitySpaces Stored Procedures template for Microsoft Access was run in MyGeneration and the Stored
Procedures written directly to the database. It is also pre-populated with the test data.
• AggregateTest_Create.sql.
• FullNameView_Create.sql.
• Naming.Test_Create.sql.
• DataTypeTest_Create.sql.
• MicrosoftSQL_All.SQL (the stored procedures generated by the EntitySpaces template for
MyGeneration.)
• StoredProcForUnitTests.sql (a special stored procedure for testing output parameters.)
• Sql_inserts_AggregateTest.sql (thirty rows of data.)
MySQL:
MySQL scripts are located in Tests\MySQL. In your database administrator, run the following scripts in the
order listed:
• AggregateDbCreate.sql.
• FullNameView_Create.sql. (MySQL 5.x only.)
• aggregatest.sql (the stored procedures generated by the EntitySpaces template for MyGeneration.)
(MySQL 5.x only.)
• StoredProcForUnitTests.sql (a special stored procedure for testing output parameters.) (MySQL 5.x
only.)
• AggregateTestData.sql (thirty rows of data.)
You can also pre-populate the test data from Tests.exe by selecting MySQL Dynamic from Tools|Provider and
then Tools|RefreshDatabase, or by Opening one of the MySQL projects in NUnit, selecting the
AggregateFixture by clicking the CheckBox next to it, and clicking Run. (Remove the check to run a full set of
tests.) MySQL 4.x does not support stored procedures or views. Running the TestsMySQLSP.nunit project
against MySQL 4.x will net you a bunch of failing tests. Note: “How table and database names are stored
on disk and used in MySQL is affected by the lower_case_table_names system variable, which you can
set when starting mysqld.” The default setting in MySQL converts table names to lowercase. Hence, the
MetadataMap generated code needed a minor tweak in order to compile. AggregatetestMetadata was changed
to AggregateTestMetadata and FullnameviewMetadata was changed to FullNameViewMetadata. This was
necessary so the partial class names matched those generated for the other databases.
Oracle:
Oracle scripts are located in Tests\Oracle. In your database administrator, run the following scripts in the
order listed:
You can pre-populate the test data from Tests.exe by selecting Oracle Dynamic from Tools|Provider and then
Tools|RefreshDatabase, or by Opening one of the Oracle projects in NUnit, selecting the AggregateFixture by
clicking the CheckBox next to it, and clicking Run. (Remove the check to run a full set of tests.)