public void ThrowsExceptionWhenEmailInvalidForm()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.Email
                                 };
                var validator = new Saml20NameIdValidator();

                var invalidEmails = new[]
                                        {
                                            "thisisnotavalid.email@ ",
                                            "thisisnotavalidemail",
                                            "thisisnotavalidemail.com",
                                            "@thisisnotavalidemail.com",
                                            " @thisisnotavalidemail.com",
                                            "@ @thisisnotavalidemail.com",
                                            " @ @thisisnotavalidemail.com",
                                            " . @thisisnotavalidemail.com",
                                            @"\. @thisisnotavalidemail.com",
                                            @"\.\@thisisnotavalidemail.com",
                                            @"a.\@thisisnotavalidemail.com",
                                            @"<.>@thisisnotavalidemail.com",
                                            @"<*****@*****.**",
                                            "thisisnotavalid.email@",
                                            "thisisnotavalid.email@ @",
                                            "thisisnotavalid.email@ @ "
                                        };

                foreach (var email in invalidEmails)
                {
                    nameId.Value = email;

                    try
                    {
                        // Act
                        validator.ValidateNameId(nameId);

                        // Assert
                        Assert.Fail("Email address " + email + " is not supposed to be valid");
                    }
                    catch (Saml20FormatException sfe)
                    {
                        Assert.AreEqual(sfe.Message, "Value of NameID is not a valid email address according to the IETF RFC 2822 specification");
                    }
                }
            }
            public void ThrowsExceptionWhenEmailValueContainsOnlyWhitespace()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.Email,
                                     Value = " "
                                 };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ValidatesWindowsDomainQualifiedName()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.Windows
                                 };
                var validator = new Saml20NameIdValidator();

                // Act
                nameId.Value = "a";
                validator.ValidateNameId(nameId);

                nameId.Value = "b\a";
                validator.ValidateNameId(nameId);
            }
            public void ValidatesTransient()
            {
                var nameId = new NameId { Format = Saml20Constants.NameIdentifierFormats.Transient };
                var validator = new Saml20NameIdValidator();

                nameId.Value = new string('f', 256);
                validator.ValidateNameId(nameId);

                nameId.Value = new string('f', 16);
                validator.ValidateNameId(nameId);
            }
 public void ValidatesPersistent()
 {
     var nameId = new NameId
                      {
                          Format = Saml20Constants.NameIdentifierFormats.Persistent,
                          Value = new string('f', 256)
                      };
     var validator = new Saml20NameIdValidator();
     validator.ValidateNameId(nameId);
 }
            public void ValidatesKerberos()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.Kerberos,
                                     Value = "a@b"
                                 };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ValidatesEntity()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.Entity,
                                     Value = new string('f', 1024)
                                 };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ValidatesEmail()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.Email,
                                     Value = "*****@*****.**"
                                 };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ThrowsExceptionWhenX509SubjecNameValueEmpty()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.X509SubjectName,
                                     Value = string.Empty
                                 };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ThrowsExceptionWhenTransientValueTooShort()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.Transient,
                                     Value = new string('f', 15)
                                 };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ThrowsExceptionWhenPersistentLengthTooLong()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.Persistent,
                                     Value = new string('f', 257)
                                 };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ThrowsExceptionWhenKerberosLessThanThreecharacters()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.Kerberos,
                                     Value = @"b"
                                 };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ThrowsExceptionWhenKerberosInvalidFormat()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.Kerberos,
                                     Value = @"a\b"
                                 };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ThrowsExceptionWhenEntitySPProvidedId()
            {
                // Arrange
                var nameId = new NameId
                                 {
                                     Format = Saml20Constants.NameIdentifierFormats.Entity,
                                     Value = new string('f', 1024),
                                     SPProvidedID = "ksljdf"
                                 };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }