public static async Task <SAMLForm> BuildRequestBindingContext(RequestContext requestContext)
        {
            string url      = String.Empty;
            var    builders = new List <IPostClauseBuilder>();

            requestContext.RelyingState.Add("relayState", "Test state");
            var xmlSerialiser      = new XMLSerialiser();
            var compressor         = new DeflateCompressor();
            var encoder            = new MessageEncoding(compressor);
            var logger             = new LogProviderMock();
            var serialiser         = new RequestSerialiser(xmlSerialiser, encoder, logger);
            var xmlSinatureManager = new XmlSignatureManager();

            RequestHelper.GetAuthnRequestBuilders = AuthnRequestBuildersFactoryMock.GetAuthnRequestBuildersFactory();
            var authnBuilder = new SamlRequestBuilder(serialiser);

            builders.Add(authnBuilder);

            //relay state builder
            var jsonSerialiser       = new NSJsonSerializer(new DefaultSettingsProvider());
            var relayStateSerialiser = new RelaystateSerialiser(jsonSerialiser, encoder, logger) as IRelayStateSerialiser;
            var relayStateBuilder    = new RelayStateBuilder(relayStateSerialiser);

            builders.Add(relayStateBuilder);

            //signature builder
            var certificateManager = new CertificateManager(logger);
            var signatureBuilder   = new SignatureBuilder(certificateManager, logger, xmlSinatureManager);

            builders.Add(signatureBuilder);
            var bindingContext = new RequestPostBindingContext(requestContext);

            foreach (var b in builders)
            {
                await b.Build(bindingContext);
            }
            var form          = new SAMLForm();
            var request       = bindingContext.RequestParts[HttpRedirectBindingConstants.SamlRequest];
            var base64Encoded = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(request));

            var relyingStateSerialised = bindingContext.RequestParts[HttpRedirectBindingConstants.RelayState];

            form.ActionURL = bindingContext.DestinationUri.AbsoluteUri;
            form.SetRequest(base64Encoded);
            form.SetRelatState(relyingStateSerialised);

            return(form);
        }
        public static async Task <RequestBindingContext> BuildRequestBindingContext(RequestContext requestContext)
        {
            string url      = String.Empty;
            var    builders = new List <IRedirectClauseBuilder>();

            requestContext.RelyingState.Add("relayState", "Test state");
            var xmlSerialiser = new XMLSerialiser();
            var compressor    = new DeflateCompressor();
            var encoder       = new MessageEncoding(compressor);
            var logger        = new LogProviderMock();
            var serialiser    = new RequestSerialiser(xmlSerialiser, encoder, logger);

            RequestHelper.GetAuthnRequestBuilders = AuthnRequestBuildersFactoryMock.GetAuthnRequestBuildersFactory();
            var authnBuilder = new SamlRequestBuilder(serialiser);

            builders.Add(authnBuilder);

            //request compression builder
            var encodingBuilder = new RequestEncoderBuilder(encoder);

            builders.Add(encodingBuilder);

            //relay state builder
            var jsonSerialiser       = new NSJsonSerializer(new DefaultSettingsProvider());
            var relayStateSerialiser = new RelaystateSerialiser(jsonSerialiser, encoder, logger) as IRelayStateSerialiser;
            var relayStateBuilder    = new RelayStateBuilder(relayStateSerialiser);

            builders.Add(relayStateBuilder);

            //signature builder
            var certificateManager = new CertificateManager(logger);
            var signatureBuilder   = new SignatureBuilder(certificateManager, logger);

            builders.Add(signatureBuilder);
            var bindingContext = new RequestBindingContext(requestContext);

            foreach (var b in builders)
            {
                await b.Build(bindingContext);
            }

            return(bindingContext);
        }