public void testErrors()
        {
            PibMemory pibImpl = new PibMemory();

            PibCertificateContainer container = new PibCertificateContainer(
                fixture.id1Key1Name, pibImpl);

            try {
                container.add(fixture.id1Key2Cert1);
                Assert.Fail("Did not throw the expected exception");
            } catch (ArgumentException ex) {
            } catch (Exception ex_0) {
                Assert.Fail("Did not throw the expected exception");
            }

            try {
                container.remove(fixture.id1Key2Cert1.getName());
                Assert.Fail("Did not throw the expected exception");
            } catch (ArgumentException ex_1) {
            } catch (Exception ex_2) {
                Assert.Fail("Did not throw the expected exception");
            }

            try {
                container.get(fixture.id1Key2Cert1.getName());
                Assert.Fail("Did not throw the expected exception");
            } catch (ArgumentException ex_3) {
            } catch (Exception ex_4) {
                Assert.Fail("Did not throw the expected exception");
            }
        }
        public void testBasic()
        {
            PibMemory pibImpl = new PibMemory();

            // Start with an empty container.
            PibCertificateContainer container = new PibCertificateContainer(
                fixture.id1Key1Name, pibImpl);

            Assert.AssertEquals(0, container.size());
            Assert.AssertEquals(0, container.getCertificates_().Count);

            // Add a certificate.
            container.add(fixture.id1Key1Cert1);
            Assert.AssertEquals(1, container.size());
            Assert.AssertEquals(1, container.getCertificates_().Count);
            Assert.AssertTrue(container.getCertificates_().Contains(
                                  fixture.id1Key1Cert1.getName()));

            // Add the same certificate again.
            container.add(fixture.id1Key1Cert1);
            Assert.AssertEquals(1, container.size());
            Assert.AssertEquals(1, container.getCertificates_().Count);
            Assert.AssertTrue(container.getCertificates_().Contains(
                                  fixture.id1Key1Cert1.getName()));

            // Add another certificate.
            container.add(fixture.id1Key1Cert2);
            Assert.AssertEquals(2, container.size());
            Assert.AssertEquals(2, container.getCertificates_().Count);
            Assert.AssertTrue(container.getCertificates_().Contains(
                                  fixture.id1Key1Cert1.getName()));
            Assert.AssertTrue(container.getCertificates_().Contains(
                                  fixture.id1Key1Cert2.getName()));

            // Get the certificates.
            try {
                container.get(fixture.id1Key1Cert1.getName());
            } catch (Exception ex) {
                Assert.Fail("Unexpected exception: " + ex.Message);
            }
            try {
                container.get(fixture.id1Key1Cert2.getName());
            } catch (Exception ex_0) {
                Assert.Fail("Unexpected exception: " + ex_0.Message);
            }
            Name id1Key1Cert3Name = new Name(fixture.id1Key1Name);

            id1Key1Cert3Name.append("issuer").appendVersion(3);
            try {
                container.get(id1Key1Cert3Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (Pib.Error ex_1) {
            } catch (Exception ex_2) {
                Assert.Fail("Did not throw the expected exception");
            }

            // Check the certificates.
            CertificateV2 cert1 = container.get(fixture.id1Key1Cert1.getName());
            CertificateV2 cert2 = container.get(fixture.id1Key1Cert2.getName());

            // Use the wire encoding to check equivalence.
            Assert.AssertTrue(cert1.wireEncode().equals(fixture.id1Key1Cert1.wireEncode()));
            Assert.AssertTrue(cert2.wireEncode().equals(fixture.id1Key1Cert2.wireEncode()));

            // Create another container with the same PibImpl. The cache should be empty.
            PibCertificateContainer container2 = new PibCertificateContainer(
                fixture.id1Key1Name, pibImpl);

            Assert.AssertEquals(2, container2.size());
            Assert.AssertEquals(0, container2.getCertificates_().Count);

            // Get a certificate. The cache should be filled.
            try {
                container2.get(fixture.id1Key1Cert1.getName());
            } catch (Exception ex_3) {
                Assert.Fail("Unexpected exception: " + ex_3.Message);
            }
            Assert.AssertEquals(2, container2.size());
            Assert.AssertEquals(1, container2.getCertificates_().Count);

            try {
                container2.get(fixture.id1Key1Cert2.getName());
            } catch (Exception ex_4) {
                Assert.Fail("Unexpected exception: " + ex_4.Message);
            }
            Assert.AssertEquals(2, container2.size());
            Assert.AssertEquals(2, container2.getCertificates_().Count);

            // Remove a certificate.
            container2.remove(fixture.id1Key1Cert1.getName());
            Assert.AssertEquals(1, container2.size());
            Assert.AssertEquals(1, container2.getCertificates_().Count);
            Assert.AssertTrue(!container2.getCertificates_().Contains(
                                  fixture.id1Key1Cert1.getName()));
            Assert.AssertTrue(container2.getCertificates_().Contains(
                                  fixture.id1Key1Cert2.getName()));

            // Remove another certificate.
            container2.remove(fixture.id1Key1Cert2.getName());
            Assert.AssertEquals(0, container2.size());
            Assert.AssertEquals(0, container2.getCertificates_().Count);
            Assert.AssertTrue(!container2.getCertificates_().Contains(
                                  fixture.id1Key1Cert2.getName()));
        }