Hi I am trying to write a simple unit test for a function.
That function is to get something from the Controller class and get a specific item from it.
This is the code that I wanted to do unit test from (In Helper class):
public static string GetMemberCode(Controller controller)
{
var claim = controller.User.Claims.FirstOrDefault(c => c.Type == "membercode");
return (claim != null) ? claim.Value : string.Empty;
}
The way this function is called is by using (More than 1 Controller class will be calling this)
string membercode = Helper.GetMemberCode(this)
This is what I have in my unit testing for now
[Theory]
[InlineData("asdfqwer")]
public void GetMemberCode_IfControllerIsValid(string membercode)
{
//Arrange
var controller = new Controller(); //ERROR:CS0144 Cannot create an instance of the abstract type or interface 'Controller'
//TODO: How to assign value inside?
//Act
var result = Helper.GetMemberCode(controller);
//Assert
result.Should().Be(membercode);
}
So my question is How to assign value inside the Controller class?
Thanks in advance.