locked
Performing TestMethod with Claims RRS feed

  • Question

  • User667237548 posted

    Hello guys, I'm starting TDD in Visual Studio with Microsoft Fakes, and I'm having problems/difficulties to pass the permissions of Claims on request which is held to the server. For the following error:

    Message: Test method MainTestes. Areas. Auxiliary. Controllers. AX001_CFOP. SvcControllerUnitTest. AutocompleteByCfopTest threw exception: System.InvalidOperationException: ID7024: an attempt was made to use the ClaimsPrincipalPermission attribute and possibly no configuration section defined. See the inner exception for details. In addition, make sure that the ClaimsAuthorizationManager element is defined in section

    Below the code from my test method:

        /// <summary>
        ///     Performs unit testing in the AutocompleteByCFOP method
        /// </summary>
        /// <remarks>
        ///     Microsoft fakes was used to simulate communication with request and as database for code isolation.
        /// </remarks>
        [TestMethod]
        [Owner("Julio")]
        [TestCategory("UnitTest")]
        [TestCategory("MainTests")]
        public void AutocompleteByCfopTest()
        {
            // Creates fake method return object
            var listCfop = new List<TechShop.Model.AX001_CFOP>
            {
                _ax001Cfop
            };
    
            // Fake class to the manager
            var manager = new StubAX001_CFOPManager()
            {
                FindExpressionOfFuncOfAX001_CFOPBoolean = s => listCfop
            };
    
            // Creates a Fake HttpRequestMessage method to override the request
            using (var request = new StubHttpRequestMessage())
            {
                request.SetConfiguration(new HttpConfiguration());
                request.Method = HttpMethod.Get;
                request.Headers.Add("Authorization",
                                    "Bearer 0cr1oRh2byktwIXIDQspQtCkh-kmwZ716NwcfVoeUJ4HJ8mJ2X8FIHcBBRMF3K6I8AZcUYXj7RuvWoQrJm3V6AxGF3OIpxWZMOSwxNdxUVCmwZWZF2hju-tgAM5");
    
                using (var controller = new CFOPSvcController { Request = request, Manager = manager })
                {
                    using (var response = controller.AutocompleteByCFOP(_ax001Cfop.AX001_ID.ToString(), _ax001Cfop.AX001_Type, _ax001Cfop.AX001_Origin))
                    {
                        foreach (var item in (List<CFOPFormVM>)((ObjectContent)response.Content).Value)
                        {
                            Assert.AreEqual(item.ID, _ax001Cfop.AX001_ID);
                            Assert.AreEqual(item.Description, _ax001Cfop.AX001_Description);
                        }
                    }
                }
            }
        }

    Has anyone been through this or know the solution to enforce Claims in testing?

    Thank you!!! Laughing

    Thursday, October 27, 2016 11:31 AM

Answers

All replies