This project is read-only.

Testing DependencyObjects with constructor overloads with parameters

Dec 9, 2009 at 7:01 PM

Hi,

I'm trying to test some types that derive from DependencyObject and has a default constructor and an overload that takes 3 parameters.

For some strange reason, the constructor is never called. 
When I run the tests without debugging, its as if it never got called at all and TestDriven reports the following:

 

******************************************
*Loading Silverlight Isolation Aspects...*
******************************************
 TEST RESULTS: 
---------------------------------------------
TestCase 'Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues'
failed: 
  Expected: 5.0f
  But was:  0.0f
H:\Projects\Balder\Source\Balder.Core.Tests\Math\CoordinateTests.cs(20,0): at Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues()
at CThru.Silverlight.SilverlightUnitTestAttribute.Execute()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
H:\Projects\Balder\Source\Balder.Core.Tests\Math\CoordinateTests.cs(14,0): at Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues()
0 passed, 1 failed, 0 skipped, took 1.98 seconds (NUnit 2.5).
******************************************
*Loading Silverlight Isolation Aspects...*
******************************************
 TEST RESULTS: 
---------------------------------------------
TestCase 'Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues'
failed: 
  Expected: 5.0f
  But was:  0.0f
H:\Projects\Balder\Source\Balder.Core.Tests\Math\CoordinateTests.cs(20,0): at Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues()
at CThru.Silverlight.SilverlightUnitTestAttribute.Execute()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
H:\Projects\Balder\Source\Balder.Core.Tests\Math\CoordinateTests.cs(14,0): at Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues()
When running it through the debugger I get and try to step into the constructor or even set a breakpoint in it, I clearly see it just steps over it.
The test code:
[Test,SilverlightUnitTest]
public void ConstructingWithArgumentedConstructorShouldSetValues()
{
const float x = 5f;
const float y = 6f;
const float z = 7f;
var coordinate = new Coordinate(x, y, z);
Assert.That(coordinate.X, Is.EqualTo(x));
Assert.That(coordinate.Y, Is.EqualTo(y));
Assert.That(coordinate.Z, Is.EqualTo(z));
                }

0 passed, 1 failed, 0 skipped, took 1.98 seconds (NUnit 2.5).

 

 

I'm running TypeMock 5.3.5.0 and CThru.Silverlight.dll is at 1.1.0.0.

 

Thanks

 

Coordinator
Dec 10, 2009 at 9:38 PM
if i remember correctly this is a by design behavior of the cthru engine - to silence all ctors with more than zero params on anything deriving from DO. 
however, this can be fixed. to see where this behavior is, in the source code, look at the DependencyObjectAspect.vb
the offending case is:

  If Not e.IsDefaultConstructor Then
                Write("Skipping ctor with more than one parameter")
                e.MethodBehavior = MethodBehaviors.SkipActualMethod
            End If

this can be changes to only skip the method if the type is not in the assembly under test, for example (so all user ctors are always run)


On Thu, Dec 10, 2009 at 10:05 PM, adept <notifications@codeplex.com> wrote:

From: adept

Hi,

I'm trying to test some types that derive from DependencyObject and has a default constructor and an overload that takes 3 parameters.

For some strange reason, the constructor is never called. 
When I run the tests without debugging, its as if it never got called at all and TestDriven reports the following:

 

******************************************
*Loading Silverlight Isolation Aspects...*
******************************************
 TEST RESULTS: 
---------------------------------------------
TestCase 'Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues'
failed: 
  Expected: 5.0f
  But was:  0.0f
H:\Projects\Balder\Source\Balder.Core.Tests\Math\CoordinateTests.cs(20,0): at Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues()
at CThru.Silverlight.SilverlightUnitTestAttribute.Execute()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
H:\Projects\Balder\Source\Balder.Core.Tests\Math\CoordinateTests.cs(14,0): at Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues()
0 passed, 1 failed, 0 skipped, took 1.98 seconds (NUnit 2.5).
******************************************
*Loading Silverlight Isolation Aspects...*
******************************************
 TEST RESULTS: 
---------------------------------------------
TestCase 'Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues'
failed: 
  Expected: 5.0f
  But was:  0.0f
H:\Projects\Balder\Source\Balder.Core.Tests\Math\CoordinateTests.cs(20,0): at Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues()
at CThru.Silverlight.SilverlightUnitTestAttribute.Execute()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
H:\Projects\Balder\Source\Balder.Core.Tests\Math\CoordinateTests.cs(14,0): at Balder.Core.Tests.Math.CoordinateTests.ConstructingWithArgumentedConstructorShouldSetValues()
When running it through the debugger I get and try to step into the constructor or even set a breakpoint in it, I clearly see it just steps over it.
The test code:
[Test,SilverlightUnitTest]
public void ConstructingWithArgumentedConstructorShouldSetValues()
{
const float x = 5f;
const float y = 6f;
const float z = 7f;
var coordinate = new Coordinate(x, y, z);
Assert.That(coordinate.X, Is.EqualTo(x));
Assert.That(coordinate.Y, Is.EqualTo(y));
Assert.That(coordinate.Z, Is.EqualTo(z));
                }

0 passed, 1 failed, 0 skipped, took 1.98 seconds (NUnit 2.5).

 

 

I'm running TypeMock 5.3.5.0 and CThru.Silverlight.dll is at 1.1.0.0.

 

Thanks

 

Read the full discussion online.

To add a post to this discussion, reply to this email (CThru@discussions.codeplex.com)

To start a new discussion for this project, email CThru@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Thanks,

Roy Osherove
www.TypeMock.com - Unit Testing, Plain Smart

Author of "The Art Of Unit Testing" (http://ArtOfUnitTesting.com )
A blog for team leaders: http://5Whys.com
my .NET blog: http://www.ISerializable.com
Twitter: http://twitter.com/RoyOsherove
+972-524-655388 (GMT+2)
Dec 15, 2009 at 7:01 AM

Thanks. 

I'll do that so I don't have to have different testing strategies. 

 

Keep up the great work - love what you've done so far!!