Пример #1
0
        public void AddRecord(Direction direction, int forwardCacheCount, int forwardTypeCacheCount, int forwardReverseCacheCount, int reverseCacheCount, int reverseTypeCacheCount, int reverseReverseCacheCount)
        {
            EntityRelationshipCache.Instance.Clear( );

            EntityRelationshipCache.Instance.Merge(EntityRelationshipCacheKey.Create(1, direction), CreateCacheValue(2, 3));

            Expect(forwardCacheCount, forwardTypeCacheCount, forwardReverseCacheCount, reverseCacheCount, reverseTypeCacheCount, reverseReverseCacheCount);
        }
Пример #2
0
        public void AddRecordRemoveDifferentTypeWithType(Direction direction, int forwardCacheCount, int forwardTypeCacheCount, int forwardReverseCacheCount, int reverseCacheCount, int reverseTypeCacheCount, int reverseReverseCacheCount)
        {
            EntityRelationshipCache.Instance.Clear( );

            EntityRelationshipCache.Instance.Merge(EntityRelationshipCacheKey.Create(1, direction), CreateCacheValue(2, 3));
            EntityRelationshipCache.Instance.Remove(EntityRelationshipCacheTypeKey.Create(3, Flip(direction), 4));

            Expect(forwardCacheCount, forwardTypeCacheCount, forwardReverseCacheCount, reverseCacheCount, reverseTypeCacheCount, reverseReverseCacheCount);
        }
Пример #3
0
        public void AddEmptyRecordAddEmptyRecordDifferentDestination(Direction direction, int forwardCacheCount, int forwardTypeCacheCount, int forwardReverseCacheCount, int reverseCacheCount, int reverseTypeCacheCount, int reverseReverseCacheCount)
        {
            EntityRelationshipCache.Instance.Clear( );

            EntityRelationshipCache.Instance.Merge(EntityRelationshipCacheKey.Create(1, direction), CreateCacheValue(2));
            EntityRelationshipCache.Instance.Merge(EntityRelationshipCacheKey.Create(2, Flip(direction)), CreateCacheValue(2));

            Expect(forwardCacheCount, forwardTypeCacheCount, forwardReverseCacheCount, reverseCacheCount, reverseTypeCacheCount, reverseReverseCacheCount);
        }
Пример #4
0
        public void AddMultipleIsOfTypeRecordAddDifferentMultipleInstancesRecordOverlap(Direction direction, int forwardCacheCount, int forwardTypeCacheCount, int forwardReverseCacheCount, int reverseCacheCount, int reverseTypeCacheCount, int reverseReverseCacheCount)
        {
            EntityRelationshipCache.Instance.Clear( );

            EntityRelationshipCache.Instance.Merge(EntityRelationshipCacheKey.Create(1, direction), CreateCacheValue(2, 3));
            EntityRelationshipCache.Instance.Merge(EntityRelationshipCacheKey.Create(4, direction), CreateCacheValue(2, 3));
            EntityRelationshipCache.Instance.Merge(EntityRelationshipCacheKey.Create(3, Flip(direction)), CreateCacheValue(2, CreateEnumerable(4, 5)));

            Expect(forwardCacheCount, forwardTypeCacheCount, forwardReverseCacheCount, reverseCacheCount, reverseTypeCacheCount, reverseReverseCacheCount);
        }
Пример #5
0
        public void TestRelationshipLoadsType(bool isReverse)
        {
            // Setup schema
            var t1 = new EntityType
            {
                Name = "Type 1 " + Guid.NewGuid( ).ToString( )
            };

            t1.Save( );

            var t2 = new EntityType
            {
                Name = "Type 2 " + Guid.NewGuid( ).ToString( )
            };

            t2.Save( );

            var r = new Relationship
            {
                Name             = "Rel " + Guid.NewGuid( ).ToString( ),
                FromType         = t1,
                ToType           = t2,
                Cardinality_Enum = CardinalityEnum_Enumeration.ManyToMany
            };

            r.Save( );

            // Setup data
            IEntity inst2 = Entity.Create(t2.Id);

            inst2.Save( );
            IEntity inst1 = Entity.Create(t1.Id);

            inst1.SetRelationships(r.Id, new EntityRelationship <IEntity>(inst2).ToEntityRelationshipCollection( ), Direction.Forward);
            inst1.Save( );

            // Ensure cache is empty
            EntityRelationshipCache.Instance.Remove(EntityRelationshipCacheKey.Create(inst1.Id, Direction.Forward));
            EntityRelationshipCache.Instance.Remove(EntityRelationshipCacheKey.Create(inst2.Id, Direction.Forward));
            EntityRelationshipCache.Instance.Remove(EntityRelationshipCacheKey.Create(inst1.Id, Direction.Reverse));
            EntityRelationshipCache.Instance.Remove(EntityRelationshipCacheKey.Create(inst2.Id, Direction.Reverse));

            // Follow relationship
            IReadOnlyDictionary <long, ISet <long> > cache;
            long expectType;

            if (!isReverse)
            {
                IEntity inst1Again = Entity.Get(inst2.Id);
                inst1Again.GetRelationships(r.Id, Direction.Reverse);

                // Verify that target type data has appeared in cache
                cache      = EntityRelationshipCache.Instance[EntityRelationshipCacheKey.Create(inst1.Id, Direction.Forward)];
                expectType = t1.Id;
            }
            else
            {
                IEntity inst1Again = Entity.Get(inst1.Id);
                inst1Again.GetRelationships(r.Id, Direction.Forward);

                // Verify that target type data has appeared in cache
                cache      = EntityRelationshipCache.Instance[EntityRelationshipCacheKey.Create(inst2.Id, Direction.Forward)];
                expectType = t2.Id;
            }

            Assert.That(cache, Is.Not.Null);
            long isOfType = (new EntityRef("core:isOfType")).Id;

            Assert.That(cache.ContainsKey(isOfType), Is.True, "Cache should have isOfType");
            Assert.That(cache [isOfType].Single( ), Is.EqualTo(expectType), "Cache isOfType value");
        }