private void FactoryCreateFor(string testcase, SecurityKey key, string algorithm, SignatureProviderFactory factory, ExpectedException expectedException)
        {
            Console.WriteLine(string.Format("Testcase: '{0}'", testcase));

            try
            {
                if (testcase.StartsWith("Siging"))
                {
                    factory.CreateForSigning(key, algorithm);
                }
                else
                {
                    factory.CreateForVerifying(key, algorithm);
                }

                expectedException.ProcessNoException();
            }
            catch (Exception ex)
            {
                expectedException.ProcessException(ex);
            }
        }
        private void RunCreationTests( SecurityTokenDescriptor tokenDescriptor, int iterations, bool display = true )
        {
            // Create jwts using wif
            // Create Saml2 tokens
            // Create Saml tokens

            DateTime started;
            string written = "Created, signed and xmlWrite: '{0}', '{1}' Tokens. Time: '{2}'";
            string created = "Created, signed: '{0}', '{1}' Tokens. Time: '{2}'";

            SignatureProviderFactory factory = new SignatureProviderFactory();
            SignatureProvider signatureProvider = factory.CreateForSigning( tokenDescriptor.SigningCredentials.SigningKey, tokenDescriptor.SigningCredentials.SignatureAlgorithm );

            started = DateTime.UtcNow;
            for ( int i = 0; i < iterations; i++ )
            {
                CreateJwts( tokenDescriptor, signatureProvider );
            }

            if ( display )
            {
                Console.WriteLine( string.Format( created, "JwtHandler - signatureProvider != null", iterations, DateTime.UtcNow - started ) );
            }

            started = DateTime.UtcNow;
            for ( int i = 0; i < iterations; i++ )
            {
                CreateJwts( tokenDescriptor, null );
            }

            if ( display )
            {
                Console.WriteLine( string.Format( created, "JwtHandler - signatureProvider == null", iterations, DateTime.UtcNow - started ) );
            }

            started = DateTime.UtcNow;
            for ( int i = 0; i < iterations; i++ )
            {
                CreateSaml2Tokens( tokenDescriptor );
            }

            if ( display )
            {
                Console.WriteLine( string.Format( written, "Saml2", iterations, DateTime.UtcNow - started ) );
            }

            started = DateTime.UtcNow;
            for ( int i = 0; i < iterations; i++ )
            {
                CreateSamlTokens( tokenDescriptor );
            }

            if ( display )
            {
                Console.WriteLine( string.Format( written, "Saml1", iterations, DateTime.UtcNow - started ) );
            }

            started = DateTime.UtcNow;
            for ( int i = 0; i < iterations; i++ )
            {
                WriteJwts( tokenDescriptor, signatureProvider );
            }

            if ( display )
            {
                Console.WriteLine( string.Format( written, "JwtHandler", iterations, DateTime.UtcNow - started ) );
            }

        }