Assert.That() doesn't like properties with scoped setters
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
NUnit Framework |
Fix Released
|
Low
|
Charlie Poole | ||
NUnit V2 |
Fix Released
|
Low
|
Charlie Poole |
Bug Description
Public Class SomeClass
Public Property BrokenProp() As String
Get
Return String.Empty
End Get
Private Set(ByVal value As String)
End Set
End Property
End Class
<TestFixture()> Public Class clsTestTask
<Test()> Public Sub TestXyz()
Dim obj As New SomeClass()
End Sub
End Class
The above code produces a compiler error:
Error 1 'Set' accessor of property 'BrokenProp' is not accessible.
If the scoping wasn't applied to the setter on the property or the property
was ReadOnly, the compile error goes away.
This is a .NET 2.0 assembly, compiled with the Visual Studio 2008 SP1.
NUnit 2.4.7 and prior did not experience this issue.
BTW, I've also started a Google Group posting for this issue:
http://
[From SF:2792355]
SF Comment:
More info... the equivalent scoped setter in C# does not have this problem.
It arises solely with VB.
Changed in nunitv2: | |
status: | New → Confirmed |
importance: | Undecided → Low |
tags: | added: vb |
description: | updated |
Changed in nunit-3.0: | |
status: | Triaged → Fix Committed |
Changed in nunitv2: | |
status: | Fix Committed → Fix Released |
Changed in nunit-3.0: | |
status: | Fix Committed → Fix Released |
For what it's worth, I opened up a StackOverflow question that is directly related to this issue. http:// stackoverflow. com/questions/ 2128283/ bug-in- vb-compiler- and-or- intellisense- in-both- c-and-vb- wrt-out- of-scope- propert
It appears that the VB.NET compiler simply handles the case of fn(Object) and fn(ref T)(T) differently than C#. It's an unfortunate thing. Technically, one could argue that the C# compiler should change to match VB's behavior in this case. I think it's pretty crappy that both compliers choose a different function to call in this case.
So, if this isn't something that is going to be fixed on the compiler's end, we would want to shift our focus on to NUnit and how we can work around this. From a user's point of view, one workaround would be to call the Asset.That in the following way... Assert. That((obj. BrokenProp) , EqualTo( String. Empty)) , forcing the obj.BrokenProp to be passed in ByVal. Which, works fine, leading me to the question of... why do the templated Assert.That<T>(ref T actual, ...) functions, need the actual value to be by reference anyhow? Maybe I didn't dig into the 2.5.3 NUnit code deep enough to find out why, but i didn't see anything that jumped out at me that said those overloads (the the Match(...) functions that they call) need to be reference parameters. I was able to strip all of the 'ref's out of these functions, the code compiled and my existing test suite ran just fine. I'm guessing there is a valid reason for the ref parameter there and my test cases just never hit that reason. But if there isn't, then that would be one way to close this issue.