I am trying to test the below method using RhinoMocks and MbUnit however I am unable to get the test to pass. The current error is when the expect call for "" is not found.
The function is in vb.net and the test is in c#
Public Function Login(user As Website.BusinessObjects.User) As Integer Implements IActivityLog.Login
Dim item As BOAudit.IActivityLog = New BOAudit.ActivityLog(_request)
' Activity
item.UserID = User.GuidID
item.Type = Enums.ActivityType.Login
item.Description = String.Format(If(IsAdmin, "Logged in as {0}", "Logged in"), User.FullName)
item.EventUserID = _authenticatedUser.GuidID
Return _dalActivityLog.Save(item)
End Function
The test below is what I currently have and I believe the issue is down to declaring a new object within the function above and not passing that object into the function. What is the best way to test the above function and should I be passing in the object?
[Test]
public void Login_Data_NewRecordCreated()
{
const int id = 99;
var data = new Website.CodeModules.BusinessObjects.Audit.ActivityLog(_request)
{
Type = Enums.ActivityType.Login,
Description = "Logged in",
EventUserID = _user.GuidID
};
var user = _mocks.StrictMock<User>();
using (_mocks.Record())
{
Expect.Call(_dalActivityLog.Save(data)).Return(id);
}
using (_mocks.Playback())
{
var result = _balActivityLog.Login(user);
Assert.AreEqual(id, result);
}
}