0% found this document useful (0 votes)
36 views

Entity Spaces Tests Getting Started

The document provides information about downloading and using the EntitySpaces Test Suite: - The test suite contains source code that demonstrates EntitySpaces features and can be used as a learning resource even if not testing. - It includes test fixtures, databases, and NUnit project files to run automated tests against different databases like SQL Server, Access, MySQL and Oracle. - Quick setup instructions are provided to download, configure references and connection strings, and run the initial tests against the included Access database.

Uploaded by

adikusdianto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Entity Spaces Tests Getting Started

The document provides information about downloading and using the EntitySpaces Test Suite: - The test suite contains source code that demonstrates EntitySpaces features and can be used as a learning resource even if not testing. - It includes test fixtures, databases, and NUnit project files to run automated tests against different databases like SQL Server, Access, MySQL and Oracle. - Quick setup instructions are provided to download, configure references and connection strings, and run the initial tests against the included Access database.

Uploaded by

adikusdianto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Getting Started with the EntitySpaces Test Suite

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.)

What is Included in Tests.zip:


• The C# and VB source code for the test fixtures.
• The C# and VB source code generated for the test databases from the EntitySpaces Templates for
MyGeneration.
• The C# source code for a testing application.
• A Microsoft Visual Studio solution.
• SQL scripts for creating Microsoft SQL Server, MySQL, and Oracle test databases.
• A pre-populated Microsoft Access test database.
• NUnit project and config files for each of the EntitySpaces providers using different test configurations.

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.

• UnZip Tests.zip into your EntitySpaces Program Folder.


• Open Tests.sln in Visual Studio.
• Add References for the binary redistributables.
o EntitySpaces.Core.dll
o EntitySpaces.Interfaces.dll
o Your purchased provider(s) or the providers included with the Trial version.
 EntitySpaces.MSAccessProvider.dll
 EntitySpaces.SqlClientProvider.dll
 EntitySpaces.OracleClientProvider.dll
 EntitySpaces.MySqlClientProvider.dll
• Open app.config and set all the connectionStrings to match your database(s). If you do not have a
particular database, just leave the setting as is.

<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"
/>

• Rebuild the Solution.


• Open each NUnit config file (e.g.; TestsMSAccess.config) and change the connectionString as you did
for app.config.
• Run the tests for your database by opening Windows Explorer and double-clicking the NUnit project
file (e.g.; TestsMSAccess.nunit)

Testing Tools included:


Tests.exe:

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 Folder Structure:

• 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.

NUnit projects and configs:

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.

Preparing Your Database for the Tests:


Microsoft Access:

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.

Microsoft SQL Server:


SQL Server scripts are located in Tests\SqlExpress. In your database administrator, run the following scripts in
the order listed:

• 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:

• EntitySpaces_Oracle.sql (creates AggregateTest, FullNameView, and a SEQUENCE for the auto-


incrementing ID column.)
• EntitySpaces_Oracle_StoredProcedures.sql (generated by the EntitySpaces template for
MyGeneration.)
• StoredProcForUnitTests.sql (a special stored procedure for testing output parameters.)

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.)

What the Future Holds:


Testing some EntitySpaces features requires a database structure more sophisticated than the simple table in
AggregateDb. This is already in the works. The Forums are constantly monitored for potential issues. Unit
Tests are continuously being added for these un-anticipated scenarios. Of course, as we prepare for the next
release of EntitySpaces, we will add the necessary tests for the new features. Running a full set of tests has
become a routine part of our development effort and occurs almost daily. While this cannot guarantee bug-
free code, we hope it helps reassure you that we are taking the steps necessary to provide a dependable
product and to prevent changes and fixes from breaking working code.

Copyright © 2005 – 2006, EntitySpaces, LLC

You might also like