When I run a unit test, this is the error I'm getting:

SetUp : Spring.Objects.Factory.ObjectDefinitionStoreException : Error registering object with name 'NHibernateSessionFactory' defined in 'assembly [Eiq.Middleware.Data.DomainRepository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c61376b85e43767], resource [Eiq.Middleware.Data.DomainRepository.Persistence.xml] line 15' : Could not resolve placeholder 'TDM.providerName'.
   at Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer.ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props)
   at Spring.Objects.Factory.Config.PropertyResourceConfigurer.PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
   at Spring.Context.Support.AbstractApplicationContext.InvokeObjectFactoryPostProcessors(IList objectFactoryPostProcessors, IConfigurableListableObjectFactory objectFactory)
   at Spring.Context.Support.AbstractApplicationContext.InvokeObjectFactoryPostProcessors(IConfigurableListableObjectFactory objectFactory)
   at Spring.Context.Support.AbstractApplicationContext.Refresh()
   at Spring.Context.Support.XmlApplicationContext..ctor(XmlApplicationContextArgs args)
   at Spring.Context.Support.XmlApplicationContext..ctor(String[] configurationLocations)
   at Spring.Testing.NUnit.AbstractSpringContextTests.LoadContextLocations(String[] locations)
   at Spring.Testing.NUnit.AbstractDependencyInjectionSpringContextTests.LoadContextLocations(String[] locations)
   at Spring.Testing.NUnit.AbstractSpringContextTests.GetContext(Object key)
   at Spring.Testing.NUnit.AbstractDependencyInjectionSpringContextTests.SetUp()

Is there any way I could get it to somehow pass in the value for "TDM.providerName" by setting something in my unit test app.config? This is what I have tried, but it did not help, where the name of the test project is MiddlewareTests, and the default namespace is Eiq.Middleware.SmokeTest:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="databaseProperties" type="System.Configuration.NameValueSectionHandler, System" />
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
      <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" restartOnExternalChanges="true" />
    </sectionGroup>
  </configSections>
  <appSettings>
    <add key="DefaultUserName" value="tdmuser" />
    <!-- Well Query Limit -->
    <add key="WellQueryLimit" value="50000" />
    <add key="TDM.providerName" value="SqlServer-2.0"/>
  </appSettings>
  <spring>
    <parsers>
      <parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
      <parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
      <parser type="Spring.Aop.Config.AopNamespaceParser, Spring.Aop" />
    </parsers>
    <context>
      <resource uri="assembly://MiddlewareTests/Eiq.Middleware.SmokeTest/Persistence.xml" />
      <resource uri="assembly://MiddlewareTests/TEiq.Middleware.SmokeTest/Repositories.xml" />
      <resource uri="assembly://MiddlewareTests/Eiq.Middleware.SmokeTest/Services.xml" />
      <resource uri="config://spring/objects" />
    </context>
    <objects configSource="config\spring.config" />
  </spring>
</configuration>

Or, alternatively, how could I get the application to point to copies of Persistence.xml, Repositories.xml, and Services.xml files that I have modified for testing directly in my unit testing project? Does anyone have any other suggestions?

1

There are 1 answers

0
user8128167 On BEST ANSWER

To resolve the above issue, performed several steps, though I'm not sure specifically which one fixed it:

  1. Added reference to NHibernate.Validator, Version=1.3.1.4000 in my test project and NHibernate.Caches.SysCache, Version 3.1.0.4000
  2. Added reference log4net, Version=1.2.10.0 to my test project to print out more diagnostic info
  3. Added references to System.Configuration, System.Web.ApplicationServices, and System.Web.Extensions to my test project
  4. Removed references to Spring.Core and Spring.Data from my test project.

Also, updated the App.config file in my test project to the following, with they key parts being those related to hibernate-configuration:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="databaseProperties" type="System.Configuration.NameValueSectionHandler, System" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
      <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" restartOnExternalChanges="true" />
    </sectionGroup>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
    <section name="nhv-configuration" type="NHibernate.Validator.Cfg.ConfigurationSectionHandler, NHibernate.Validator" requirePermission="false" />
    <section name="auditConfig" type="Eiq.Middleware.Common.Config.AuditConfigSectionHandler, Eiq.Middleware.Common" restartOnExternalChanges="true" />
    <section name="coordSys" type="Eiq.Middleware.Common.Config.CoordSysSectionHandler, Eiq.Middleware.Common" restartOnExternalChanges="true" />
  </configSections>
  <log4net>
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%message%newline" />
      </layout>
    </appender>
    <root>
      <level value="INFO" />
      <appender-ref ref="ConsoleAppender" />
    </root>
  </log4net>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string">Data Source=localhost;Initial Catalog=ENERGYIQ;User Id=svc_tdm;Password=svc_tdm;    
  </property>
  <mapping assembly="TdmTests" />
</session-factory>
  <nhv-configuration xmlns="urn:nhv-configuration-1.0">
    <shared_engine_provider class="NHibernate.Validator.Event.NHibernateSharedEngineProvider, NHibernate.Validator" />
  </nhv-configuration>
  <auditConfig configSource="Config\audit.config" />
  <connectionStrings configSource="config\connectionStrings.config" />
  <spring>
    <parsers>
      <parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
      <parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
      <parser type="Spring.Aop.Config.AopNamespaceParser, Spring.Aop" />
    </parsers>
    <context>
      <resource uri="assembly://TdmTests/TdmTests/Persistence.xml" />
      <resource uri="assembly://TdmTests/TdmTests/Repositories.xml" />
      <resource uri="assembly://TdmTests/TdmTests/Services.xml" />
      <resource uri="config://spring/objects" />
    </context>
    <objects configSource="config\spring.config" />
  </spring>
  <appSettings>
    <add key="DefaultUserName" value="tdmuser" />
    <!-- Well Query Limit -->
    <add key="WellQueryLimit" value="50000" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
</configuration>

HTH.