Uniting Testing with LLBLGEN issues

Posts   
 
    
unity007
User
Posts: 10
Joined: 06-Jul-2010
# Posted on: 14-Sep-2010 16:21:53   

I've been having some issues when unit testing LLBLGEN. Using Visual Studio and Typemock. It seems that something in the autogenerated code isn't getting cleaned up correctly, and when I run a test individually, it will pass, but if I run more than one then it will error out on LLBLGEN.

Here's a snippet of code:


 PersonEntity fakePerson = new Person();
 FriendEntity fakeFriend = new CampaignAffiliateEntity() { friendId = 1 };
 fakePerson.Friends.Add(fakeFriend);

it errors out when I attempt to Add. Even though the debugger shows that fakePerson.Friends is not null, just an empty collection, I get a null error when I try this, but only when this test is with others (as if something isn't getting cleared from LLBLGEN), any advice?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 14-Sep-2010 20:42:11   

What is the actual exception that you get ? And can you duplicate it using code that does not involve unit testing and TypeMock ?

Matt

unity007
User
Posts: 10
Joined: 06-Jul-2010
# Posted on: 14-Sep-2010 21:15:49   

Hey Matt,

The exception I am getting is: System.ArgumentNullException: Value cannot be null. Parameter name: value. It happens when I attempt to call Person.Friends.Add(). Neither Person, the collection Person.Friends nor the FriendEntity I am adding is null when I debug.

It only happens when I run Unit Tests. I pasted the error stack trace below in case that's helpful:

System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
System.Diagnostics.TraceSwitch.OnValueChanged()
System.Diagnostics.Switch.InitializeWithStatus()
System.Diagnostics.Switch.get_SwitchSetting()
System.Diagnostics.TraceSwitch.get_Level()
System.Diagnostics.TraceSwitch.get_TraceVerbose()
PerformAdd(T item)
Add(T item)
TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)

I cannot reproduce without unit testing.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Sep-2010 05:37:51   

Hi unity007,

I don't see the exception occurs on LLBLGen side, from the stack trace, please see if that is the full stack trace.

Also, if the errors occurs when you run multiple tests, then it could be you are missing some TestInitialize, TestCleanup, ClassCleanup methods. To figure out what is going on, please try to reproduce the problem with Northwind database and send us the test project.

Send us this info as well: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7717

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 15-Sep-2010 10:54:13   

Please check your trace switch settings in the app.config file for your unittest project, the level is set to a value other than 0,1,2,3,4

Frans Bouma | Lead developer LLBLGen Pro
unity007
User
Posts: 10
Joined: 06-Jul-2010
# Posted on: 15-Sep-2010 17:14:56   

Hey,

The Add Method being called is actually the one on the LLBLGEN class, as far as the trace goes, it wasn't in the app.config file at all, so I added it (is it in the right spot?):


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="DataTests.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
    
      <DataTests.Properties.Settings>
            <setting name="DataTestsSetting" serializeAs="String">
                <value>http://localhost/Test/Test.asmx</value>
            </setting>
        </DataTests.Properties.Settings>
    
    </applicationSettings>

  <system.diagnostics>
    <switches>
      <add name="TraceLevelSwitch" value="4" />
    </switches>
  </system.diagnostics>

</configuration>

It gives me a slightly different error message on the error stack now:


System.Configuration.ConfigurationElementCollection.CompareKeys(Object key1, Object key2)
System.Configuration.ConfigurationElementCollection.BaseGet(Object key)
System.Diagnostics.SwitchElementsCollection.get_Item(String name)
System.Diagnostics.Switch.InitializeWithStatus()
System.Diagnostics.Switch.get_SwitchSetting()
System.Diagnostics.TraceSwitch.get_Level()
System.Diagnostics.TraceSwitch.get_TraceVerbose()
PerformAdd(T item)
Add(T item)

any ideas? I'm using LLBLGEN 2.6

unity007
User
Posts: 10
Joined: 06-Jul-2010
# Posted on: 15-Sep-2010 23:17:46   

I think I was able to pin it down to the fact that it's because in a different test, I'm mocking out DataAccessAdapter, but since DataAccessAdapter apparently uses a singleton pattern so it causes a problem.

Is there anyway around this?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Sep-2010 08:17:00   

Btw, TraceLevelSwitch isn't a switch we use.