public void AgentBasicTestKeys()
        {
            // create basic test key data
            String keyId = "testKeyId";

            byte[] keyBytes = new byte[] { 0x01, 0x01, 0x01, 0x03 };

            // create test key attributes
            AttributesDictionary keyAttributes        = DataStructureHelpers.CreateTestAttributes();
            AttributesDictionary mutableKeyAttributes = DataStructureHelpers.CreateTestAttributes();
            KeyObligationsMap    keyObligations       = DataStructureHelpers.CreateTestObligations();

            // AgentKey constructors
            {
                // empty constructor
                AgentKey key = new AgentKey();
                Assert.AreEqual(key.Id, "");
                Assert.AreEqual(key.KeyBytes, new byte[] { });
                Assert.AreEqual(key.Attributes, new AttributesDictionary());
                Assert.AreEqual(key.Obligations, new KeyObligationsMap());
                // constructor with key ID and bytes
                key = new AgentKey(keyId, keyBytes);
                Assert.AreEqual(key.Id, keyId);
                Assert.AreEqual(key.KeyBytes, keyBytes);
                Assert.AreEqual(key.Attributes, new AttributesDictionary());
                Assert.AreEqual(key.Obligations, new KeyObligationsMap());

                // constructor with key ID, bytes, and attributes
                key = new AgentKey(keyId, keyBytes, keyAttributes, mutableKeyAttributes, keyObligations);
                Assert.AreEqual(key.Id, keyId);
                Assert.AreEqual(key.KeyBytes, keyBytes);
                Assert.AreEqual(key.Attributes, keyAttributes);
                Assert.AreEqual(key.MutableAttributes, mutableKeyAttributes);
                Assert.AreEqual(key.Obligations, keyObligations);
            }

            // AgentKey accessors
            {
                AgentKey key = new AgentKey();

                // get / set key ID
                key.Id = keyId;
                Assert.AreEqual(key.Id, keyId);

                // get / set key bytes
                key.KeyBytes = keyBytes;
                Assert.AreEqual(key.KeyBytes, keyBytes);

                // get / set key attributes
                key.Attributes = keyAttributes;
                Assert.AreEqual(key.Attributes, keyAttributes);
            }
        }
        public void RelationsWithCompositeKey()
        {
            // User HasAndBelongsToMany Groups
            // Groups HasAndBelongsToMany Users
            // User HasMany Groups
            //
            ActiveRecordStarter.Initialize(GetConfigSource(),
                                           typeof(Group),
                                           typeof(Agent),
                                           typeof(Org));
            Recreate();

            Agent.DeleteAll();
            Org.DeleteAll();
            Group.DeleteAll();

            Org org = new Org("org1", "Test Org.");

            org.Save();

            Group group1 = new Group();

            group1.Name = "Group1";
            group1.Save();

            Group group2 = new Group();

            group2.Name = "Group2";
            group2.Save();

            AgentKey agentKey1 = new AgentKey("org1", "rbellamy");
            Agent    agent1    = new Agent(agentKey1);

            agent1.Save();
            agent1.Groups.Add(group1);
            group1.Agents.Add(agent1);
            agent1.Save();
            agent1.Groups.Add(group2);
            group2.Agents.Add(agent1);
            agent1.Save();

            AgentKey agentKey2 = new AgentKey("org1", "hammett");
            Agent    agent2    = new Agent(agentKey2);

            agent2.Groups.Add(group1);
            agent2.Save();

            using (new SessionScope())
            {
                org    = Org.Find(org.Id);
                group1 = Group.Find(group1.Id);
                group2 = Group.Find(group2.Id);
                agent1 = Agent.Find(agentKey1);
                agent2 = Agent.Find(agentKey2);

                Assert.IsNotNull(org);
                Assert.IsNotNull(group1);
                Assert.IsNotNull(group2);
                Assert.IsNotNull(agent1);
                Assert.IsNotNull(org.Agents, "Org agent collection is null.");
                Assert.IsNotNull(group1.Agents, "Group1 agent collection is null");
                Assert.IsNotNull(group2.Agents, "Group2 agent collection is null");
                Assert.IsNotNull(agent1.Groups, "Agent group collection is null.");
                Assert.IsNotNull(agent1.Org, "Agent's org is null.");
                Assert.AreEqual(2, group1.Agents.Count);
                Assert.AreEqual(2, agent1.Groups.Count);
                Assert.AreEqual(1, agent2.Groups.Count);

                foreach (Agent agentLoop in org.Agents)
                {
                    Assert.IsTrue(agentLoop.Groups.Contains(group1));
                }
            }
        }