Hi Karol,
NSubstitute can't mock static methods, so if you want to use NSub for this you'll need to rewrite the original class, or wrap the functionality in a new class that you can mock. Because some extra code is required, I'd probably lose the output params as well (they're a pain to mock, and I like getting data out from the return value where possible). Here's a quick example of the wrapping the existing behaviour and mocking that wrapper.
public class UserDetails {
public readonly int? UserID;
public readonly string UserName;
public readonly string FullName;
public readonly string Culture;
public UserDetails(/* constructor fields here */) { /* init fields here */ }
}
public interface IGetUserDetails {
UserDetails GetDetails();
}
public class GetUserDetailsFromAcceptanceFlow : IGetUserDetails {
/* init output variables here */
AcceptanceFlow.GetLoggedInUserNameAndId(out userId, out userName, out userFullName, out culture); // <-- call original static method
return new UserDetails(userId, userName, ... );
}
[Test]
public void TestSomeOtherClassDisplaysLoggedInUser() {
var user = new UserDetails(1, "abc", "Karol", "");
var view = Substitute.For<ISomeView>();
var getDetails = Substitute.For<IGetUserDetails>();
getDetails.GetDetails().Returns(user);
var otherClass = new OtherClass(getDetails, view);
otherClass.Load();
Assert.That(view.LoggedInUser, Is.EqualTo(user.FullName))l;
}
Hope this helps.
Regards,
David