Reputation: 13
public static LoginResult CreateLoginSuccessResponse(this PortalIdentity user)
{
return new LoginResult(
true,
string.Empty,
user.Roles,
false
);
}
public class PortalIdentity : IdentityUser
{
public string Firstname { get; set; }
public string Lastname { get; set; }
}
This block of code is for creating a success response whenever a user logs in successfully. I am a QA and trying to learn how to write unit tests. I am not sure how to write unit test for "this" keyword
Upvotes: 0
Views: 223
Reputation: 23975
this
(in the above context at least) just means it is an extension method.
To test it, new
up a PortalIdentity
, assign to a variable (bob
) and call bob.CreateLoginSuccessResponse()
:
var bob = new PortalIdentity(you may need parameters here);
var result = bob.CreateLoginSuccessResponse();
If the call to bob.CreateLoginSuccessResponse()
doesn't compile, then the extension method is likely in a different namespace. As per the docs, you need to:
In the calling code, add a using directive to specify the namespace that contains the extension method class.
Upvotes: 1