public void ShouldRedirectToStartPathIfUserIsNotAdmin() { // arrange var attribute = new RequireAdminAttribute { IsAdministrator = false }; var httpActionContext = new HttpActionContext { ControllerContext = new HttpControllerContext { Request = new HttpRequestMessage() } }; // act attribute.OnAuthorization(httpActionContext); // assert httpActionContext.Response.Should().NotBeNull(); httpActionContext.Response.StatusCode.Should().Be(System.Net.HttpStatusCode.Unauthorized); httpActionContext.Response.Headers.Count().Should().Be(0); var error = httpActionContext.Response.Content as ObjectContent <HttpError>; error.Should().NotBeNull(); var errorValue = error.Value as HttpError; errorValue.Should().NotBeNull(); errorValue.Message.Should().Be(Texts.PermissionIsDenied); }
public void ShouldNotRedirectToStartPathIfUserIsAdmin() { // arrange var attribute = new RequireAdminAttribute { IsAdministrator = true }; var httpActionContext = new HttpActionContext { ControllerContext = new HttpControllerContext { Request = new HttpRequestMessage() } }; // act attribute.OnAuthorization(httpActionContext); // assert httpActionContext.Response.Should().BeNull(); }