Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Behaviour with Parameterized Properties #293

Closed
flandersen opened this issue Apr 17, 2014 · 8 comments · Fixed by #311
Closed

Unexpected Behaviour with Parameterized Properties #293

flandersen opened this issue Apr 17, 2014 · 8 comments · Fixed by #311
Assignees
Milestone

Comments

@flandersen
Copy link

This fails but it shouldn't:
I configured an object to be returned if the parameterized property is called with "Width". When you then call the property with another string you get another fake. That's ok. But if you call the property with "Width" again you don't get the correct fake, see VB.Net code below.

This behaviour doesn't appear when you change the property into a function.

Public Interface IHmiProperties

    Property Properties(name As String) As IHmiProperty
End Interface

Public Interface IHmiProperty

    Property Name As String
End Interface

<TestMethod>
Public Sub PropertiesWithStringParameter_ShouldntFailIfPropertyNotConfigured()
    ' Arange
    Dim widthProperty As IHmiProperty = A.Fake(Of IHmiProperty)()
    widthProperty.Name = "Width"

    Dim properties As IHmiProperties = A.Fake(Of IHmiProperties)()
    A.CallTo(Function() properties.Properties("Width")).Returns(widthProperty)

    ' Act
    properties.Properties("SomeOther").Name = "Dummy"

    ' Assert
    Assert.AreEqual("Width", properties.Properties("Width").Name)
End Sub
@blairconrad
Copy link
Member

@flandersen, thanks for mentioning this. I wonder if it's not the same underlying problem as in #277.
If you're interested, I have a workaround posted in the StackOverflow question that begat that issue. Perhaps give it a try and see if it eases your pain while we investigate?

@blairconrad
Copy link
Member

Putting in the Backlog and marking as P2 for now.

@flandersen
Copy link
Author

@blairconrad, thanks for your quick reply. Your workaround seems to work quite well. But I had to write A(Of String).Ignored because VB.Net doesn't allow me to use the shortcut A(Of String)._.

<TestMethod>
Public Sub PropertiesWithStringParameter_ShouldntFailIfPropertyNotConfigured()
    ' Arange
    Dim widthProperty As IHmiProperty = A.Fake(Of IHmiProperty)()
    widthProperty.Name = "Width"

    Dim properties As IHmiProperties = A.Fake(Of IHmiProperties)()
    '' TODO: Delete when bug is fixed https://github.com/FakeItEasy/FakeItEasy/issues/293
    A.CallTo(Function() faceplateTypical.Properties(A(Of String).Ignored)).ReturnsLazily(Function() A.Fake(Of IHmiProperty)())
    ''

    A.CallTo(Function() properties.Properties("Width")).Returns(widthProperty)

    ' Act
    properties.Properties("SomeOther").Name = "Dummy"

    ' Assert
    Assert.AreEqual("Width", properties.Properties("Width").Name)
End Sub

@blairconrad
Copy link
Member

I'm glad to hear you have some relief. Of course, I still think we have an opportunity to improve the FakeItEasy indexed property handling.

@blairconrad
Copy link
Member

Marking as 2 - Working and enhancement (a closer look makes me think that indexed property support was never implemented, not that there's a flaw in the implementation) and assigning to me.

@blairconrad
Copy link
Member

@flandersen, thanks very much for raising this issue. Look for your name in the release notes. 🏆

This issue has been fixed in release 1.21.0.

https://www.nuget.org/packages/FakeItEasy/1.21.0
https://github.com/FakeItEasy/FakeItEasy/releases/tag/1.21.0

@flandersen
Copy link
Author

Thanks Blair for the fix. Works great.

Am 28.05.2014 um 11:55 schrieb Blair Conrad notifications@github.com:

@flandersen, thanks very much for raising this issue. Look for your name in the release notes.

This issue has been fixed in release 1.21.0.
@flandersen, thanks very much for raising this issue. Look for your name in the release notes.

This issue has been fixed in release 1.21.0.

https://www.nuget.org/packages/FakeItEasy/1.21.0
https://github.com/FakeItEasy/FakeItEasy/releases/tag/1.21.0


Reply to this email directly or view it on GitHub.

@blairconrad
Copy link
Member

Yay. I'm glad!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants