Overwriting CatalogName for testing with NUNit

Posts   
 
    
jmcervera
User
Posts: 27
Joined: 03-Jun-2004
# Posted on: 20-Dec-2005 15:34:37   

Hello everybody! stuck_out_tongue_winking_eye I pretend to do unit testing of manager classes tha uses llblgen business entities, and I am having troubles with the ovewriting od the catalog to use, because I am using Adapter, and I want to use a different database for testing. The use of the config file works when I use the application, but It doesn`t work with the config file used by NUnit (project_test.dll.config) How can I make this in a config file? Can somebody help give me a sample?

Thank you

wink

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 20-Dec-2005 17:42:13   

I use the same setup (a dll.config file) and it works great. If the connection string can be read from the config file, so will the name overwriting settings (and tracing stuff etc.).

Frans Bouma | Lead developer LLBLGen Pro
pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 20-Dec-2005 20:34:27   

jmcervera wrote:

Hello everybody! stuck_out_tongue_winking_eye I pretend to do unit testing of manager classes tha uses llblgen business entities, and I am having troubles with the ovewriting od the catalog to use, because I am using Adapter, and I want to use a different database for testing. The use of the config file works when I use the application, but It doesn`t work with the config file used by NUnit (project_test.dll.config) How can I make this in a config file? Can somebody help give me a sample?

Thank you

wink

Make sure your config file is getting coppied into the bin folder with the dll.

BOb

jmcervera
User
Posts: 27
Joined: 03-Jun-2004
# Posted on: 21-Dec-2005 10:25:21   

Otis wrote:

I use the same setup (a dll.config file) and it works great. If the connection string can be read from the config file, so will the name overwriting settings (and tracing stuff etc.).

Yes Frans, it works, but I am making something wrong sometimes.

This is my case. The name of the catalog I use when generating was "boletines", and the name of the catalog for testing is "boletines_test".

I have the dll.config file in the right folder and this works

<?xml version="1.0" encoding="utf-8" ?> <configuration>

<appSettings>
    <add key="Main.ConnectionString" value="data source=localhost;initial catalog=boletines_test;integrated security=SSPI;"/>       
    <add key="CatalogNameUsageSetting" value="1" />
    <add key="CatalogNameToUse" value="boletines_test" />       
</appSettings>

</configuration>

but this doesn`t work

<?xml version="1.0" encoding="utf-8" ?> <configuration>

<configSections>
    <section name="sqlServerCatalogNameOverwrites" type="System.Configuration.NameValueSectionHandler" />
</configSections>

<sqlServerCatalogNameOverwrites>
    <add key="boletines" value="boletines_test" />

</sqlServerCatalogNameOverwrites>

<appSettings>
    <add key="Main.ConnectionString" value="data source=localhost;initial catalog=boletines_test;integrated security=SSPI;"/>       
</appSettings>

</configuration>

In this last case I have this error:

SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: Invalid object name 'Boletines.dbo.maquinas'.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteSingleRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFields2 fieldsToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityUsingFilter(IEntityFields2 fieldsToFetch, IFieldPersistenceInfo[] persistenceInfos, IRelationPredicateBucket filter) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityUsingUniqueConstraint(IEntity2 entityToFetch, IPredicateExpression uniqueConstraintFilter) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityUsingUniqueConstraint(IEntity2 entityToFetch, IPredicateExpression uniqueConstraintFilter, Context contextToUse) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityUsingUniqueConstraint(IEntity2 entityToFetch, IPredicateExpression uniqueConstraintFilter, IPrefetchPath2 prefetchPath, Context contextToUse) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityUsingUniqueConstraint(IEntity2 entityToFetch, IPredicateExpression uniqueConstraintFilter, IPrefetchPath2 prefetchPath) at Fichajes.BusinessObjects.FichajeMaquina.BuscarMaquina(String codigo) in FichajeMaquina.cs:line 76 at Fichajes.BusinessObjects.FichajeMaquina..ctor(String codigo) in FichajeMaquina.cs:line 26 at Fichajes.BusinessObjects.Test.FichajeMaquinaFixture.Mas() in fichajemaquinafixture.cs:line 30

It seems the query is still looking for a catalog named boletines What am I doing wrong?

Thanks stuck_out_tongue_winking_eye

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 21-Dec-2005 15:08:59   

Please read the section Catalog specific persistence info (SqlServer specific) in the LLBLGen Pro documentation under "Using the generated code - Adapter - DataAccessAdapter Functionality"

This was copied from that section:

_Adapter uses schema specific persistence information. This means that the schema name is generated into the persistence information and that the queries will use the schema name generated into the persistence information for each field and database object (table/view). _

So you should overwrite the catalog name generated (as you did in the first example)

jmcervera
User
Posts: 27
Joined: 03-Jun-2004
# Posted on: 21-Dec-2005 15:59:15   

I thought I was doing the same with my second code sample.

And this is explained in the manual in "Generated code - Application configuration through .config files" section. The code was copied from there.

Thanks

Juanma

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 22-Dec-2005 06:24:40   

is it a Web project (ASP.NET)? if so pease note the following:

Note: for ASP.NET applications, the section declaration has to contain in the type attribute the full type with version and culture, otherwise you'll get an exception at runtime. The specific type declaration is specific for the .NET version you're using and you can find examples how to specify it from the machine.config file in %WINDIR%\Microsoft.NET\Framework\version\CONFIG. For example for .NET 1.1:

<configSections> <section name="sqlServerCatalogNameOverwrites" "sqlServerCatalogNameOverwrites" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </configSections>

is the schema name the same? for both databases? or your new catalog is in a different schema?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 22-Dec-2005 09:49:59   

the names are case sensitive:

<sqlServerCatalogNameOverwrites>
    <add key="boletines" value="boletines_test" />

should be

<sqlServerCatalogNameOverwrites>
    <add key="Boletines" value="boletines_test" />
Frans Bouma | Lead developer LLBLGen Pro
jmcervera
User
Posts: 27
Joined: 03-Jun-2004
# Posted on: 23-Dec-2005 23:27:56   

No Walaa, it's not a web project, and the schema is the same in both cases.

And I canĀ“t check it now, but I am pretty sure that Otis is right, and the problem is with the case sensivity issue.

Thank you very much

jelling
User
Posts: 22
Joined: 26-Oct-2007
# Posted on: 08-Nov-2007 00:05:29   

Otis wrote:

the names are case sensitive:

<sqlServerCatalogNameOverwrites>
    <add key="boletines" value="boletines_test" />

should be

<sqlServerCatalogNameOverwrites>
    <add key="Boletines" value="boletines_test" />

Is there any reason the key name should be case sensitive? I don't think most database names are case-sensitive.

I just ran into this issue and it cost me about an hour.

.jelling

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Nov-2007 11:10:25   

A wild guess: You may have Case-Sensetive collation database server, and you may have 2 catalogs with the same name but with different cases. And I think LLBLGen Pro won't know about the case sensetivity of your server, at runtime.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 08-Nov-2007 12:03:01   

Casing is important, because most databases are in fact case sensitive. Just because Sqlserver's default install is case insensitive doesn't mean it's always the case wink . To serve that situation as well, the name HAS TO BE case sensitive,

Frans Bouma | Lead developer LLBLGen Pro
jelling
User
Posts: 22
Joined: 26-Oct-2007
# Posted on: 08-Nov-2007 17:32:24   

Otis wrote:

Casing is important, because most databases are in fact case sensitive. Just because Sqlserver's default install is case insensitive doesn't mean it's always the case wink . To serve that situation as well, the name HAS TO BE case sensitive,

Haha, I can live with that. All though, for once I think MS got this one right. Case sensitive DB names seem like a feature that will only cause pain. Oh well.