07.11.2014 Views

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

66<br />

<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />

<strong>Test</strong> case Result Automated test<br />

Verify that custom<br />

database classes<br />

that are derived from<br />

the Database class<br />

can be added to the<br />

application block<br />

and configured from<br />

Passed In this example, the custom database class CustomMock-<br />

Database derives from the Database class. The <strong>Enterprise</strong><br />

<strong>Library</strong> Core uses information in the configuration file to add<br />

the custom class to the application block.<br />

[DatabaseAssembler(typeof(CustomDatabaseCustomAsse<br />

mbler))]<br />

public class CustomMockDatabase : Database<br />

information in the<br />

{<br />

public CustomMockDatabase(string connectionconfiguration<br />

source.<br />

String):base(connectionString,SqlClientFactory.<br />

Instance)<br />

{<br />

…<br />

}<br />

protected override void DeriveParameters(System.<br />

Data.Common.DbCommand discoveryCommand)<br />

{<br />

…<br />

);<br />

}<br />

public class CustomDatabaseCustomAssembler : IDatabaseAssembler<br />

{<br />

public Database Assemble(string name, System.<br />

Configuration.ConnectionStringSettings connection-<br />

StringSettings, Microsoft.Practices.<strong>Enterprise</strong><strong>Library</strong>.Common.Configuration.IConfigurationSource<br />

configurationSource)<br />

{<br />

return new CustomMockDatabase(connectionStringSett<br />

ings.ConnectionString);<br />

}<br />

}<br />

The following is the information in the configuration file.<br />

<br />

<br />

<br />

<br />

<br />

<br />

The following is the test case.<br />

[<strong>Test</strong>Method]<br />

public void CreateCustomDatabase<strong>Test</strong>()<br />

{<br />

Database db= DatabaseFactory.CreateDatabase("Cus<br />

tomDatabase");<br />

Assert.IsNotNull(db);<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!