Rhino Mocks Assert Property Setter was called with correct object type

rhino-mocks

Solution

I fixed it by making the ReportService accept a Network Credential instead of the username, password, domain

public void SetNetworkCredential(NetworkCredential networkCredential)
{
    _reportExecutionService.Credentials = networkCredential;
}

so my test was much easier

[TestMethod]
public void TestTest()
{
    const string userName = "userName";
    const string password = "password";
    const string domain = "domain";

    var mock = MockRepository.GenerateMock<IReportExecutionService>();
    var rptService= new ReportService(mock);

    var networkCredential = new System.Net.NetworkCredential(userName, password, domain);

    rptService.SetNetworkCredential(networkCredential);

    mock.AssertWasCalled(x => x.Credentials = networkCredential);
}

Problem

I have a method that sets a property ``` public void SetNetworkCredential(string userName, string password, string domain) { _reportExecutionService.Credentials = new NetworkCredential(userName, password, domain); } ``` how do I verify that Credentials was called with a valid NetworkCredential? I tried this TestMethod but it fails because the NetworkCredential objects are different references ``` [TestMethod] public void TestTest() { const string userName = "userName"; const string password = "password"; const string domain = "domain"; var mock = MockRepository.GenerateMock<IReportExecutionService>(); var rptService= new ReportService(mock); rptService.SetNetworkCredential(userName, password, domain); mock.AssertWasCalled(x => x.Credentials = new System.Net.NetworkCredential(userName, password, domain)); } ``` Is there a way to validate that the setter was called with an object of type NetworkCredential and with the correct parameters?

Original source