C# Properties

  • Julian Gall

    Julian Gall - 2004-10-07

    Is there any way to use EasyMock with C# Properties? It seems to detect the get_MyProperty that is under the covers but I don't seem to be able to set a return value.



    • Matthew

      Matthew - 2006-01-24

      I'm wondering this as well. I keep getting "incompatible return value type" messages when I set a return value for a property as opposed to a pure method. Quite aggravating as most of the things I need to test right now happen to be properties!

      Otherwise, great port. I like it a lot.


      • Jon Skeet

        Jon Skeet - 2006-01-24

        You should be able to use properties fine.

        Are you running under VS2005, though? If so, that could explain the problem - there's an issue with void methods (such as property setters) in .NET 2.0.

        There's another post in the forums giving a workaround. However, that may not be the issue here...

        Could you come up with a failing NUnit test?

        (Of course, it's possible that I've fixed it in my development version... some time I *will* find time to release stuff!)


        • Matthew

          Matthew - 2006-01-25

          Jon, I'm running VS2003 and .NET 1.1. I can't really send a failing test because what I'm testing is a class internal to the company I work for. I'll see if I can come up with something against one of .NET's built-in classes, though.

          • Jon Skeet

            Jon Skeet - 2006-01-25

            You shouldn't need to post any sensitive code - just a test class and a class which has a property.


            • Matthew

              Matthew - 2006-01-27

              Jon, I gave this about 10 minutes but was having trouble with NUnit assembly conflicts on my machine (so much for .NET eliminating DLL hell) so I gave up. I've switched to using NUnit's mocks which, while not as robust, at least appear to handle my code better. I'd really like to provide you with a failing test, but I can't justify the time since it looks like it'll take a while to get everything setup again. Sorry.

              • Jon Skeet

                Jon Skeet - 2006-01-27

                Okay - not to worry.

                Just as a thought - if you were trying to set the return value by setting the property, that wouldn't work. Instead, you need to access the property, then use SetReturnValue or whatever to set the return value.

                Anyway, if you ever do get a chance to find an example, I'll be happy to take a look.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks