This is a migrated thread and some comments may be shown as answers.

Mocking FormsAuthentication

1 Answer 135 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 2
Mike asked on 28 Jan 2013, 09:33 AM
Is it possible to mock the static FormsAuthentication?  I would like to check that the SignIn and SignOut methods are called in an MVC LoginController.

I have a mocked LoginController, lc, and the following code:

Mock.SetupStatic(typeof(FormsAuthentication));
            Mock.Arrange(() => FormsAuthentication.SignOut()).OccursOnce();
 
            var result = lc.Logoff();
 
            Mock.Assert(() => FormsAuthentication.SignOut());

If I run this under debug it passes but if I just run it I get:
Test Name:  LogoffShouldCallFormsAuthenticationSignOut
Test FullName:  OfDisplays.WebTests.SecurityTests.LogoffShouldCallFormsAuthenticationSignOut
Test Source:    c:\SoftDev\Projects\OFDisplays\OfDisplays.Web\OfDisplays.WebTests\SecurityTests.cs : line 83
Test Outcome:   Failed
Test Duration:  0:00:01.9634171
 
Result Message:
Test method OfDisplays.WebTests.SecurityTests.LogoffShouldCallFormsAuthenticationSignOut threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Telerik.CodeWeaver.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=87210992829a189d' or one of its dependencies. The system cannot find the file specified.WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Result StackTrace: 
at System.Web.Security.FormsAuthentication.SignOut()
   at OfDisplays.Web.Controllers.LoginController.Logoff() in c:\SoftDev\Projects\OFDisplays\OfDisplays.Web\OfDisplays.Web\Controllers\LoginController.cs:line 57
   at OfDisplays.WebTests.SecurityTests.LogoffShouldCallFormsAuthenticationSignOut() in c:\SoftDev\Projects\OFDisplays\OfDisplays.Web\OfDisplays.WebTests\SecurityTests.cs:line 90

1 Answer, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 30 Jan 2013, 10:59 AM
Hello Mike,

Thank you for the detailed feedback.

I tried reproducing the issue following exactly the same approach as your test method and it worked as expected.

In order to assist you further, I would suggest you to send us an example project, reproducing the matter. However, if this is not doable in your case, please provide us some information about the environment you have:
  • What Visual Studio is being used
  • Which version of MVC you are writing the tests against

Thank you for the collaboration in advance.

Kind regards,
Kaloyan
the Telerik team
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Tags
General Discussions
Asked by
Mike
Top achievements
Rank 2
Answers by
Kaloyan
Telerik team
Share this question
or