Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming <code>HubCallerContext</code> is this one - <a href="https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Core/Hubs/HubCallerContext.cs" rel="nofollow">https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Core/Hubs/HubCallerContext.cs</a> - then setting up the tests will be easy. You just want two mocks of <code>IPrincipal</code>, one of which returns true for the <code>.IsInRole("admin")</code> call and the other that returns false.wrap these two in mocks of <code>IRequest</code>.</p> <p>The syntax will vary depending on the mocking framework used, but your tests will end up something like:</p> <pre><code>[Test] public void IsAdmin_CalledByAdmin_ReturnTrue() { UserService userService = new UserService(); var principalMock = new Mock&lt;IPrincipal&gt;(); principalMock.Setup(x =&gt; x.IsInRole("admin")).Returns(true); var requestMock = new Mock&lt;IRequest&gt;(); requestMock.Setup(x =&gt; x.User).Returns(principalMock.Object); var result = userService.IsAdmin(new HubCallerContext(requestMock.Object, "")); Assert.IsTrue( result, "Something is wrong." ); } [Test] public void IsAdmin_CalledByUser_ReturnFalse() { UserService userService = new UserService(); var principalMock = new Mock&lt;IPrincipal&gt;(); principalMock.Setup(x =&gt; x.IsInRole("admin")).Returns(false); var requestMock = new Mock&lt;IRequest&gt;(); requestMock.Setup(x =&gt; x.User).Returns(principalMock.Object); var result = userService.IsAdmin(new HubCallerContext(requestMock.Object, "")); Assert.IsFalse( result, "Something is wrong." ); } </code></pre> <p>I haven't checked if the above compiles, but it is based on the syntax needed for <a href="http://code.google.com/p/moq/" rel="nofollow">Moq</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload