NSubstitute with .NET 2.0

237 views
Skip to first unread message

Taur

unread,
Feb 21, 2012, 4:44:51 AM2/21/12
to NSubstitute
I am using VS 2005 and .NET 2.0. Can I use NSubstitute? Does it
integrates with ReSharper?

David Tchepak

unread,
Feb 21, 2012, 5:28:37 AM2/21/12
to nsubs...@googlegroups.com
Sorry, NSubstitute only supports .NET 3.5 and above (it uses Expressions and extension methods).

I believe Rhino Mocks still supports .NET 2.0 (I think Moq and FakeItEasy only work with 3.5 and above too -- someone please correct me if I'm wrong).

Regards,
David

On Tue, Feb 21, 2012 at 8:44 PM, Taur <nitin...@gmail.com> wrote:
I am using VS 2005 and .NET 2.0. Can I use NSubstitute? Does it
integrates with ReSharper?

--
You received this message because you are subscribed to the Google Groups "NSubstitute" group.
To post to this group, send email to nsubs...@googlegroups.com.
To unsubscribe from this group, send email to nsubstitute...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nsubstitute?hl=en.


jawad....@gteamstaff.com

unread,
Jan 16, 2015, 12:39:41 PM1/16/15
to nsubs...@googlegroups.com
I have .net 2.0 project to be tested. The test project can use .net 4.0 but I can't mock the object from the class to be tested. Is it because .net 2.0 isn't supported by NSusbtitute?

David Tchepak

unread,
Jan 16, 2015, 6:37:15 PM1/16/15
to nsubs...@googlegroups.com

Can you post the error message it is giving you? The interface and test would be helpful too if you can share it. Otherwise, can you post a simplified reproduction of the problem?

--
You received this message because you are subscribed to the Google Groups "NSubstitute" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nsubstitute...@googlegroups.com.

To post to this group, send email to nsubs...@googlegroups.com.

jawad....@gteamstaff.com

unread,
Jan 18, 2015, 9:51:03 PM1/18/15
to nsubs...@googlegroups.com
Following is the error message I receive:

System.NotSupportedException : The invoked member is not supported in a dynamic assembly.

On the line: 
EventBatch eventBatch = Substitute.ForPartsOf<EventBatch>();


Whereas EventBatch is a VB class with a Target .Net 2.0 Framework (An x86 application used as COM component)

Thanks,


On Tuesday, February 21, 2012 at 2:44:51 PM UTC+5, Taur wrote:

David Tchepak

unread,
Jan 18, 2015, 10:15:56 PM1/18/15
to nsubs...@googlegroups.com
Sounds like parts of the real class are being called (from the constructor?), similar to https://groups.google.com/d/topic/rhinomocks/ndHkf1uiT-I/discussion. I found a link on SO [1] mentioning that new'ing up a real version of the class first (`new EventBatch()`) may do whatever initialisation is required.

[1]: http://stackoverflow.com/a/19935430/906

Alternatively you could try to modify the design to avoid real calls/initialisation coming through (for example, pass in resource initialisation code as a dependency). Remember that whenever substituting for a real class you need to be very careful about non-virtual members and constructor logic running (see the warning here: http://nsubstitute.github.io/help/creating-a-substitute/).

Regards,
David

--
You received this message because you are subscribed to the Google Groups "NSubstitute" group.

Jawad Bokhari

unread,
Jan 22, 2015, 10:05:01 AM1/22/15
to nsubs...@googlegroups.com
Thanks David, 

I figured out that the issue was mainly with the version of EnterpriseServices. The codebase was using ES version 2.0 which is probably not compatible for NSubstitute project running version 4.0. So partial mocking an object using older version of ES isn't working. 
All I did now (slightly painful for me) is refactor the code and i) took out the function that I wanted to test, ii) made substitute for the older COM object and I could now write test cases. 

At last, The game is on!


--
You received this message because you are subscribed to a topic in the Google Groups "NSubstitute" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nsubstitute/obBqC5MYeik/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nsubstitute...@googlegroups.com.

To post to this group, send email to nsubs...@googlegroups.com.
Visit this group at http://groups.google.com/group/nsubstitute.
For more options, visit https://groups.google.com/d/optout.



--
Warm Regards,
Jawad Bokhari

David Tchepak

unread,
Jan 22, 2015, 5:04:11 PM1/22/15
to nsubs...@googlegroups.com
Good work on getting it sorted!
I'm not sure why there'd be a compatibility problem between 2.0 and 4.0, but the approach of extracting the bit you want to test seems like a very good idea regardless.
Reply all
Reply to author
Forward
0 new messages