I'm trying to test a method that simply looks to see if a value exists in a property that contains a list of strings, but the test fails despite the fact that the value is in the list. Here is some sample code:
Imports System.Text
Imports Telerik.JustMock
Public Class User
Public Sub New()
MyBase.New()
End Sub
Public Shared Function Create() As User
Dim returnValue As New User
returnValue.UID = "TestUser"
returnValue.Roles.Add("Admin")
Return returnValue
End Function
Public Property UID As String
Public Property Roles As List(Of String)
Public Function IsAdministrator() As Boolean
Return _roles.Contains("Admin")
End Function
End Class
<
TestClass
()>
Public Class Mocking
<
TestMethod
()>
Public Sub Works()
Dim user As User = user.Create
Assert.IsTrue(user.IsAdministrator)
End Sub
<
TestMethod
()>
Public Sub DoesNotWork()
Dim user As User = Mock.Create(Of User)()
Dim roles As New List(Of String)
Mock.Arrange(Function() user.UID).Returns("SomeUser")
roles.Add("Admin")
Mock.Arrange(Function() user.Roles).Returns(roles)
Assert.AreEqual("SomeUser", user.UID)
Assert.AreEqual(roles.Count, user.Roles.Count)
Assert.AreEqual("Admin", user.Roles.Item(0))
Assert.IsTrue(user.IsAdministrator)
End Sub
End Class
I'm sure I'm just missing something obvious, so any help is greatly appreciated.