public void Saml2AuthenticationRequest_ToXElement_RootNode()
        {
            var subject = new Saml2AuthenticationRequest().ToXElement();

            subject.Should().NotBeNull().And.Subject.Name.Should().Be(
                Saml2Namespaces.Saml2P + "AuthnRequest");
        }
        public void Saml2AuthenticationRequest_ForceAuthentication_OmittedIfFalse()
        {
            var subject = new Saml2AuthenticationRequest() {
                ForceAuthentication = false
            }.ToXElement();

            subject.Should().NotBeNull().And.Subject.Attribute("ForceAuthn").Should().BeNull();
        }
        public void Saml2AuthenticationRequest_ForceAuthentication()
        {
            var subject = new Saml2AuthenticationRequest() {
                ForceAuthentication = true
            }.ToXElement();

            subject.Should().NotBeNull().And.Subject.Attribute("ForceAuthn")
                .Should().NotBeNull().And.Subject.Value.Should().Be("true");
        }
        public void Saml2AuthenticationRequest_AssertionConsumerServiceUrl()
        {
            string url = "http://some.example.com/Saml2AuthenticationModule/acs";
            var subject = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri(url)
            }.ToXElement();

            subject.Should().NotBeNull().And.Subject.Attribute("AssertionConsumerServiceURL")
                .Should().NotBeNull().And.Subject.Value.Should().Be(url);
        }
        public void Saml2AuthenticationRequest_ToXElement_AddsRequestBaseFields()
        {
            // Just checking for the id field and assuming that means that the
            // base fields are added. The details of the fields are tested
            // by Saml2RequestBaseTests.

            var subject = new Saml2AuthenticationRequest().ToXElement();

            subject.Should().NotBeNull().And.Subject.Attribute("ID").Should().NotBeNull();
            subject.Attribute("AttributeConsumingServiceIndex").Should().BeNull();
        }
        public void Saml2AuthenticationRequest_ToXElement_Scoping_NullContents_EmptyScoping()
        {
            var subject = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri("http://destination.example.com"),
                Scoping = new Saml2Scoping()
            }.ToXElement().Element(Saml2Namespaces.Saml2P + "Scoping");

            var expected = new XElement(Saml2Namespaces.Saml2P + "root",
                new XAttribute(XNamespace.Xmlns + "saml2p", Saml2Namespaces.Saml2P),
                new XElement(Saml2Namespaces.Saml2P + "Scoping"))
                .Elements().Single();

            subject.Should().BeEquivalentTo(expected);
        }
        public void Saml2AuthenticationRequest_ToXElement_AddsElementSaml2NameIdPolicy()
        {
            var subject = new Saml2AuthenticationRequest()
            {
                AssertionConsumerServiceUrl = new Uri("http://destination.example.com"),
                NameIdPolicy = new Saml2NameIdPolicy { AllowCreate = false, Format = NameIdFormat.EmailAddress}
            }.ToXElement();

            XNamespace ns = "urn:oasis:names:tc:SAML:2.0:protocol";
            subject.Attribute("AttributeConsumingServiceIndex").Should().BeNull();
            subject.Should().NotBeNull().And.Subject.Element(ns + "NameIDPolicy").Should().NotBeNull();
        }