コード例 #1
0
        private static void AssertSetterSets(string propertyName)
        {
            const string test     = "test";
            var          property = typeof(ResourceAuthorizeAttribute).GetProperty(propertyName);

            Assert.AreEqual(typeof(string), property.PropertyType);
            var attribute            = new ResourceAuthorizeAttribute();
            var initialPropertyValue = (string)property.GetValue(attribute);

            Assert.IsTrue(string.IsNullOrWhiteSpace(initialPropertyValue), "string.IsNullOrWhiteSpace(initialPropertyValue)");
            property.SetValue(attribute, test);
            var newPropertyValue = property.GetValue(attribute);

            Assert.AreEqual(test, newPropertyValue);
        }
コード例 #2
0
        public void UserShouldNotBeAuthorized()
        {
            using (var request = new HttpRequestMessage())
            {
                var controllerContext = CreateControllerContext(request);
                var actionContext     = CreateActionContext(controllerContext);

                try
                {
                    var attribute = new ResourceAuthorizeAttribute();
                    attribute.OnAuthorization(actionContext);
                    Assert.AreEqual(HttpStatusCode.Unauthorized, actionContext.Response.StatusCode);
                }
                finally
                {
                    actionContext.Response?.Dispose();
                }
            }
        }
コード例 #3
0
        public void OnAuthorizationShouldThrowWhenFilterContextIsNull()
        {
            var attribute = new ResourceAuthorizeAttribute();

            attribute.OnAuthorization(null);
        }