Большое спасибо за вашу помощь.
В приведенном ниже примере кода используется moq и он написан на vb.net для других программистов vb.net, которые могли столкнуться с аналогичными проблемами.
Класс бетона
Public Class UserService
Implements IUserService
Private ReadOnly userRepository As IUserRepository
Public Sub New( _
ByVal userRepository As IUserRepository)
Me.userRepository = userRepository
End Sub
Public Sub Edit(userDto As Dtos.UserDto) Implements Core.Interfaces.Services.IUserService.Edit
Try
ValidateUserProperties(userDto)
Dim user = CreateUserObject(userDto)
userRepository.Edit(user)
Catch ex As Exception
Throw
End Try
End Sub
Private Function CreateUserObject(userDto As Dtos.UserDto) As User Implements Core.Interfaces.Services.IUserService.CreateUserObject
Dim user = New User With {.Id = userDto.Id, _
.UserName = userDto.UserName, _
.UserPassword = userDto.UserPassword, _
.Profile = New Profile With {.Id = userDto.ProfileId}}
Return user
End Function
Sub ValidateUserProperties(userDto As Dtos.UserDto)
End Sub
Тестовый класс
<TestFixture()>
Public Class UserServiceTest
Private userRepository As Mock(Of IUserRepository)
Public serviceUnderTest As IUserService
<SetUp()>
Public Sub SetUp()
userRepository = New Mock(Of IUserRepository)(MockBehavior.Strict)
serviceUnderTest = New UserService(userRepository.Object)
End Sub
<Test()>
Public Sub Test_Edit()
'Arrange
Dim userDto As New UserDto With {.UserName = "gbrown", .UserPassword = "power", .Id = 98, .ProfileId = 1}
Dim userObject As User = Nothing
userRepository.Setup(Sub(x) x.Edit(It.IsAny(Of User))) _
.Callback(Of User)(Sub(m) userObject = m)
'Act
serviceUnderTest.Edit(userDto)
'Assert
userRepository.Verify(Sub(x) x.Edit(It.IsAny(Of User)), Times.AtLeastOnce())
Assert.NotNull(userObject)
Assert.AreEqual(userDto.Id, userObject.Id)
Assert.AreEqual(userDto.ProfileId, userObject.Profile.Id)
Assert.AreEqual(userDto.UserName, userObject.UserName)
Assert.AreEqual(userDto.UserPassword, userObject.UserPassword)
End Sub
End Class