public ActionResult View(string name)
{
if (TempData["SessionVariable"] != null)
{
FileName = name;
return View();
}
else
{
return RedirectToAction("index", "Home");
}
}
TestMethod
public void UseCaseView_CorrectRequirements()
{
var mock = new Mock<Controller>();
mock.Setup(p => p.TempData["SessionVariable"]).Returns("admin");
Controller.View("SAMPLE.xml");
}
It throws an error such as ,
Result StackTrace:
at Moq.Mock.ThrowIfSetupExpressionInvolvesUnsupportedMember(Expression setup, MethodInfo method) in C:\projects\moq4\Source\Mock.cs:line 883 at Moq.Mock.SetupGetPexProtected[T,TProperty](Mock
1 mock, Expression
1 expression, Condition condition) in C:\projects\moq4\Source\Mock.cs:line 537 at Moq.Mock.SetupGet[T,TProperty](Mock1 mock, Expression
1 expression, Condition condition) in C:\projects\moq4\Source\Mock.cs:line 517 at Moq.Mock.SetupPexProtected[T,TResult](Mock1 mock, Expression
1 expression, Condition condition) in C:\projects\moq4\Source\Mock.cs:line 507 at Moq.Mock.Setup[T,TResult](Mock1 mock, Expression
1 expression, Condition condition) in C:\projects\moq4\Source\Mock.cs:line 484 at Moq.QueryableMockExtensions.FluentMock[T,TResult](Mock1 mock, Expression
1 setup) in C:\projects\moq4\Source\Linq\Mocks.cs:line 224 at lambda_method(Closure ) at Moq.Mock.GetTargetMock(Expression fluentExpression, Mock mock) in C:\projects\moq4\Source\Mock.cs:line 856 at Moq.Mock.SetupPexProtected[T,TResult](Mock1 mock, Expression
1 expression, Condition condition) in C:\projects\moq4\Source\Mock.cs:line 505 at Moq.Mock.Setup[T,TResult](Mock1 mock, Expression
1 expression, Condition condition) in C:\projects\moq4\Source\Mock.cs:line 484 at SE_WEBAPP.Tests.TestControllers.UsecaseControllerTests.UseCaseView_CorrectRequirements() inD:\Public\SE_WEBAPP_TESTCASE\SE_WEBAPP\SE_WEBAPP.Tests\TestControllers\UsecaseControllerTests.cs:line 23
Result Message: Test method SE_WEBAPP.Tests.TestControllers.UsecaseControllerTests.UseCaseView_CorrectRequirements threw exception: System.NotSupportedException: Invalid setup on a non-virtual (overridable in VB) member: mock => mock.TempData