コード例 #1
0
        public void TestAbsentPresent()
        {
            var attr1 = Attribute <int> .From("attr1", 1);

            var tracked1 = TrackedAttribute.Of(_set, attr1);

            Assert.False(tracked1.IsAbsent);
            Assert.True(tracked1.IsPresent);

            Assert.True(TrackedAttribute.Absent.IsAbsent);
            Assert.False(TrackedAttribute.Absent.IsPresent);
        }
コード例 #2
0
    public TrackedAttribute AddIfAbsent <T>(Attribute <T> attribute)
    {
        var maybeAttribute = Find(attribute);

        if (maybeAttribute.IsAbsent)
        {
            var nowPresent = TrackedAttribute.Of(this, attribute);
            return(_attributes.AddOrUpdate(
                       nowPresent.Id !,
                       nowPresent,
                       (id, trackedAttribute) => nowPresent));
        }

        return(maybeAttribute);
    }
コード例 #3
0
        public void TestWithAttribute()
        {
            var attr1 = Attribute <int> .From("attr1", 1);

            var tracked1           = TrackedAttribute.Of(_set, attr1);
            var attr1ValueModified = Attribute <int> .From("attr1", 2);

            var tracked2 = tracked1.WithAttribute(attr1ValueModified);

            Assert.NotEqual(attr1, tracked2.Attribute);
            Assert.NotEqual(tracked1.Attribute, tracked2.Attribute);
            Assert.Equal(attr1ValueModified, tracked2.Attribute);
            Assert.Equal(tracked1.Distributed, tracked2.Distributed);
            Assert.Equal(tracked1.Id, tracked2.Id);
        }
コード例 #4
0
        public void TestAsDistributed()
        {
            var attr1 = Attribute <int> .From("attr1", 1);

            var tracked1 = TrackedAttribute.Of(_set, attr1);

            Assert.False(tracked1.Distributed);

            var tracked2 = tracked1.AsDistributed();

            Assert.True(tracked2.Distributed);

            Assert.Equal(tracked1.Attribute, tracked2.Attribute);
            Assert.Equal(tracked1.Id, tracked2.Id);
        }
コード例 #5
0
        public void TestTrackedAttributeOf()
        {
            var attr1 = Attribute <int> .From("attr1", 1);

            var tracked1 = TrackedAttribute.Of(_set, attr1);

            Assert.Equal(attr1, tracked1.Attribute);

            var attr2 = Attribute <int> .From("attr1", 1);

            var tracked2 = TrackedAttribute.Of(_set, attr2);

            Assert.Equal(attr1, attr2);
            Assert.Equal(attr2, tracked2.Attribute);
            Assert.Equal(tracked1, tracked2);
        }