Configuration of SnapDAL Mock features

For each test configured in your unit tests with MockProvider.TestName = "someTestName", there must be a config file. So if you have a test named "mockreadertest", there will be a mockreadertest.config in the Mock folder of your statements directory. This file tells SnapDAL what to load for the named test. Here is an example with the configurable parameters:

<?xml version="1.0" ?>
<DataFactory>
  <Reader statement="query_categories" provider="dataset" fileBaseName="query_categories" />
  <Reader statement="query_customer" provider="SqlClient" 
       connectionString="trusted_connection=true;database=Northwind;server=localhost" />
</DataFactory>

Name Description Example
Reader Element that holds the setup information to return a DataReader for a particular statement in this test n/a
statement The statement name used to execute the reader for this test query_categories
provider Provider to be used for this connection "SqlClient" or other SnapDAL provider name. In the case of serialized datasets, the name "dataset" is used
connectionString Connection string for this provider trusted_connection=true;database=Northwind;server=localhost
fileBaseName In the case of the dataset provider, the combination of testname-fileBaseName.xml is used to pull the serialized xml from the saved file in the cachedData folder. query_categories (will look for <root dir>/cachedData/sometestname-query_categories.xml

While recording tests is the quickest way to get serialized xml files for your test, the syntax is fairly easy to modify with a trusty text editor. For each statement there is a series of data elements separated by a parameters attribute. Then there is a Schema element that is used to build the mock reader's record structure. Here is an example. Note that in this example for the query "query_customer", different results are returned depending on the parameters in the file.

<cache>
  <data params="" dataType="dataset">
    <dataset>
      <NewDataSet>
  <Table ID="Table1">
    <companyname>Alfreds Futterkiste</companyname>
  </Table>
</NewDataSet>
    </dataset>
</data>
  <data params="test1" dataType="dataset">
    <dataset>
      <NewDataSet>
  <Table ID="Table2">
    <companyname>test1</companyname>
  </Table>
</NewDataSet>
    </dataset>
</data>
  <data params="test2" dataType="dataset">
    <dataset>
      <NewDataSet>
  <Table ID="Table3">
			<companyname>test2</companyname>
  </Table>
</NewDataSet>
    </dataset>
</data>

    <schema><![CDATA[<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="NewDataSet" msdata:IsDataSet="true">
    <xs:complexType>
      <xs:choice maxOccurs="unbounded">
        <xs:element name="Table">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="companyname" type="xs:string" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>]]></schema>
</cache>