Exemplo n.º 1
0
        public QsiCacheRepository()
        {
            var comparer = new IdentifierEqualityComparer();

            _lookupCache           = new ConcurrentDictionary <QsiQualifiedIdentifier, QsiTableStructure>(comparer);
            _lookupDefinitionCache = new ConcurrentDictionary <QsiQualifiedIdentifier, QsiScript>(comparer);
        }
    public void PopulateEntityRelationStorage_OneRelationMatches ()
    {
      var aPersons = new[]
                     {
                         new PersonA (new Identifier<int> (1), "Homer", 49, 1),
                         new PersonA (new Identifier<int> (2), "Marge", 49, 1), // Just one of those two is allowed to match
                         new PersonA (new Identifier<int> (4), "Marge", 49, 1), // Just one of those two is allowed to match
                         new PersonA (new Identifier<int> (3), "Bart", 8, 1),
                     };
      var bPersons = new[]
                     {
                         new PersonB (new Identifier<string> ("one"), "Homerx", "49", "1"),
                         new PersonB (new Identifier<string> ("two"), "Marge", "49", "1"),
                         new PersonB (new Identifier<string> ("three"), "Bart", "9", "1"),
                     };

      var atypeIdEqualityComparer = new IdentifierEqualityComparer<int>();
      var btypeIdEqualityComparer = new IdentifierEqualityComparer<string>();

      var atypeEntityVersions = aPersons.ToDictionary (p => p.Id, p => p.Version, atypeIdEqualityComparer);
      var btypeEntityVersions = bPersons.ToDictionary (p => p.Id, p => p.Version, btypeIdEqualityComparer);

      var allAtypeEntities = aPersons.ToDictionary (p => p.Id, atypeIdEqualityComparer);
      var allBtypeEntities = bPersons.ToDictionary (p => p.Id, btypeIdEqualityComparer);

      var foundRelations = new TestInitialEntityMatcher (btypeIdEqualityComparer).FindMatchingEntities (
          new PersonAPersonBRelationDataFactory(),
          allAtypeEntities,
          allBtypeEntities,
          atypeEntityVersions,
          btypeEntityVersions);

      Assert.That (foundRelations.Count, Is.EqualTo (1));
      var relation = foundRelations[0];

      Assert.That (relation.AtypeId.Value, Is.EqualTo (2).Or.EqualTo (4)); // Depends on the implementation which one matches
      Assert.That (relation.AtypeVersion, Is.EqualTo (1));
      Assert.That (relation.BtypeId.Value, Is.EqualTo ("two"));
      Assert.That (relation.BtypeVersion, Is.EqualTo ("1"));
    }