As part of the unit test, I'm trying to mock the return value of FormsIdentity.Ticket.UserData p>
The following will not work, but it should give an idea of ββwhat I'm trying to do:
var principal = Mock<IPrincipal>(); var formsIdentity = Mock<FormsIdentity>(); formsIdentity.Setup(a => a.Ticket.UserData).Returns("aaa | bbb | ccc"); principal.Setup(b => b.Identity).Returns(formsIdentity.Object);
The code I'm trying to check looks something like this:
FormsIdentity fIdentity = HttpContext.Current.User.Identity as FormsIdentity; string userData = fIdentity.Ticket.UserData;
All I want to do in my unit test is fake the return value from FormsIdentity.Ticket.UserData. But when I run the code in the first section, I get an error when trying to mock FormsIdentity. The error says that the type for bullying should be an interface, an abstract class, or an unsealed class.
I tried to use the IIdentity parameter instead of FormsIdentity (FormsIdentity is an implementation of IIdentity), but IIdentity does not have .Ticket.UserData.
So how can I write this test to get the value from FormsIdentity.Ticket.UserData?
tdd asp.net-mvc moq mocking
codette
source share