public void TestBuildTBSField_SerialNumber_AssertBuilt()
 {
     var parser = new SimpleTextV1LexiconPolicyParser();
     dynamic tbsField = parser.BuildTBSField("X509.TBS.SerialNumber");
     Assert.NotNull(tbsField);
     Assert.Equal(tbsField.GetType(), typeof(SerialNumberAttributeField));
     Assert.True(tbsField.IsRequired());
 }
        public void TestBuildTBSField_Issuer_AssertBuilt()
        {
            var parser = new SimpleTextV1LexiconPolicyParser();
            var tbsField = parser.BuildTBSField("X509.TBS.Issuer.CN") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof (IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.COMMON_NAME);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.CN+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.COMMON_NAME);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.C") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.COUNTRY);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.C+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.COUNTRY);
            tbsField.IsRequired().Should().BeTrue();


            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.O") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.ORGANIZATION);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.O+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.ORGANIZATION);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.OU") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.ORGANIZATIONAL_UNIT);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.OU+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.ORGANIZATIONAL_UNIT);
            tbsField.IsRequired().Should().BeTrue();


            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.ST") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.STATE_ST);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.ST+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.STATE_ST);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.L") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.LOCALITY);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.L+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.LOCALITY);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.E") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.EMAIL);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.E+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.EMAIL);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.DC") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.DOMAIN_COMPONENT);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.DC+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.DOMAIN_COMPONENT);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.DNQUALIFIER") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.DISTINGUISHED_NAME_QUALIFIER);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.DNQUALIFIER+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.DISTINGUISHED_NAME_QUALIFIER);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.SERIALNUMBER") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.SERIAL_NUMBER);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.SERIALNUMBER+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.SERIAL_NUMBER);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.SN") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.SURNAME);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.SN+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.SURNAME);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.TITLE") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.TITLE);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.TITLE+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.TITLE);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.GIVENNAME") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.GIVEN_NAME);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.GIVENNAME+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.GIVEN_NAME);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.INITIALS") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.INITIALS);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.INITIALS+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.INITIALS);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.PSEUDONYM") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.PSEUDONYM);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.PSEUDONYM+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.PSEUDONYM);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.GERNERAL_QUALIFIER") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.GERNERAL_QUALIFIER);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.GERNERAL_QUALIFIER+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.GERNERAL_QUALIFIER);
            tbsField.IsRequired().Should().BeTrue();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.DN") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.DISTINGUISHED_NAME);
            tbsField.IsRequired().Should().BeFalse();

            parser = new SimpleTextV1LexiconPolicyParser();
            tbsField = parser.BuildTBSField("X509.TBS.Issuer.DN+") as IssuerAttributeField;
            tbsField.Should().NotBeNull();
            tbsField.GetType().Should().Be(typeof(IssuerAttributeField));
            tbsField.GetRDNAttributeFieldId().Should().Be(RDNAttributeIdentifier.DISTINGUISHED_NAME);
            tbsField.IsRequired().Should().BeTrue();
            
        }
 public void TestBuildTBSField_Signature_AssertFieldNotImplemented()
 {
     var parser = new SimpleTextV1LexiconPolicyParser();
     Assert.Throws<PolicyParseException>(() =>parser.BuildTBSField("X509.TBS.Signature"));
     Assert.Throws<PolicyParseException>(() => parser.BuildTBSField("X509.TBS.Signature+"));
 }
        public void TestBuildTBSField_Validity_AssertFieldNotImplemented()
        {
            var parser = new SimpleTextV1LexiconPolicyParser();
            Action action = () => parser.BuildTBSField("X509.TBS.Validity.ValidFrom");
            action.ShouldThrow<PolicyParseException>();

            action = () => parser.BuildTBSField("X509.TBS.Validity.ValidFrom+");
            action.ShouldThrow<PolicyParseException>();

            action = () => parser.BuildTBSField("X509.TBS.Validity.ValidTo");
            action.ShouldThrow<PolicyParseException>();

            action = () => parser.BuildTBSField("X509.TBS.Validity.ValidTo+");
            action.ShouldThrow<PolicyParseException>();
        }