c# – Claims no TestMethod


Good morning everyone, I'm starting with TDD in Visual Studio, and I'm having problems/difficulties to pass the Claims permissions in the request that is made to the server. The following error is occurring:

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 inner exception for details. Also, make sure the ClaimsAuthorizationManager element is defined in the section

Below is my test method code

    /// <summary>
    ///     Realiza teste unitario no metodo AutocompleteByCFOP
    /// </summary>
    /// <remarks>
    ///     Foi utilizado microsoft fakes para simular comunicação com request e como banco de dados para isolamento do codigo.
    /// </remarks>
    public void AutocompleteByCfopTest()
        // Cria objeto de retorno do metodo fake
        var listCfop = new List<TechShop.Model.AX001_CFOP>

        // Classe fake para o manager
        var manager = new StubAX001_CFOPManager()
            FindExpressionOfFuncOfAX001_CFOPBoolean = s => listCfop

        // Cria um metodo Fake do HttpRequestMessage para substituir o request
        using (var request = new StubHttpRequestMessage())
            request.SetConfiguration(new HttpConfiguration());
            request.Method = HttpMethod.Get;
                                "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 gone through this or know the solution to apply Claims in Tests?


Hello Julio Mendonça

You need to define the claimsAuthorizationManager and identityConfiguration elements in your project configuration file (App.config), you must enter the system.identityModel and system.identityModel.services tags in configSections.

        <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
            <claimsAuthorizationManager type="MainTests.Security.TestAuthorizationManager, MainTests" />

You must define the path of the class that validates authorization and the project name of the class in the claimsAuthorizationManager.



Scroll to Top