コード例 #1
0
 public void GivenAFilter_WhenTheUserIsNull_ThenTheFilterReturnsFalse()
 {
     AuthorizationContext filterContext = CreateFilterContext();
     _mockHttpContext.Setup(h => h.User).Returns((IPrincipal) null);
     var loggedInUserAttribute = new AuthorizeLoggedInUserAttribute();
     loggedInUserAttribute.OnAuthorization(filterContext);
     Assert.That(filterContext.Result, Is.TypeOf<RedirectResult>());
 }
コード例 #2
0
 public void GivenAFilter_WhenTheUserIsNotLoggedIn_ThenTheFilterReturnsFalse()
 {
     AuthorizationContext filterContext = CreateFilterContext();
     var model = new UserViewModel {IsLoggedIn = false};
     _mockHttpContext.Setup(h => h.User).Returns(model);
     var loggedInUserAttribute = new AuthorizeLoggedInUserAttribute();
     loggedInUserAttribute.OnAuthorization(filterContext);
     Assert.That(filterContext.Result, Is.TypeOf<RedirectResult>());
 }