How do you test a renamed partial method?

I use Linq to SQL, which generates partial classes and partial methods. Then you extend this generated code, applying your settings manually in another partial class. One of the L2S hooks gives you the opportunity to implement partial methods called when a property changes. For example, if you have a property called "MyProp", you can implement a partial method as follows:

' Given to you in the generator Partial Private Sub OnMyPropChanged() End Sub ' Manually implemented in my custom class ' I cannot specify that this is an implementation of a Partial, even though it is... Private Sub OnMyPropChanged() Console.WriteLine("My prop changed... do something here") End Sub 

The problem I ran into is that the name "MyProp" has now changed to "MyNewPropName", so now the partial generator creates Partial Private Sub OnMyNewPropNameChanged() , but my version of the partial method still has the old name. In fact, I now have an orphaned private method that is never called callable, which means my code is broken at runtime. How would you test something like this, or even better - is there a way to indicate that my version of OnMyPropChanged() is an implementation of the partial method, so that I get a trade-off time gap if there is no corresponding partial in the generated code?

+4
source share
2 answers

Using static analysis (code analysis), you will receive a warning / error when your code contains any internal (private, freid, internal) elements that are never accessible or only ever installed. this can help find such constellations. (IIRC - corresponding error code CA1811)

+2
source

I don’t think you can.

When you change the name of a property in the designer, you call the recreated automatically generated code.

The best approach is to develop your facilities before you begin to implement business logic. Create unit tests in visual studio that verify the implementation of a partial implementation. Testing modules in a visual studio will even give you code coverage statistics.

Hope this helps

0
source

All Articles