public T[] GetRootObjectsInDateRange <T>(string qualifier = null, DateTimeOffset?olderThan = null, DateTimeOffset?newerThan = null) where T : ISerializableItem
        {
            var set   = _syncPoints.GetOrAdd(getKeyFromQualifiedType(typeof(T), qualifier));
            var lower = new SyncPointInformation(Guid.Empty, Guid.Empty, typeof(int), null, newerThan ?? DateTimeOffset.MinValue);
            var upper = new SyncPointInformation(Guid.Empty, Guid.Empty, typeof(int), null, olderThan ?? DateTimeOffset.MaxValue);

            return(set.GetViewBetween(lower, upper).Select(x => Load <T>(x.RootObjectHash)).ToArray());
        }
        public void EnsureSyncPointInformationDoesntSerializeExtraJunk()
        {
            var template = new SyncPointInformation(Guid.NewGuid(), Guid.NewGuid(), typeof (string), "Foo", DateTimeOffset.MinValue);
            var json = JSONHelper.Serialize(template);
            this.Log().Debug(json);

            var expected = new[] {
                "RootObjectHash",
                "ParentSyncPoint",
                "RootObjectTypeName",
                "Qualifier",
                "CreatedOn"
            };

            // TODO: This test sucks out loud
            expected.Run(x => Assert.True(json.Contains(x)));
        }
        public ISyncPointInformation CreateSyncPoint <T>(T obj, string qualifier = null, DateTimeOffset?createdOn = null)
            where T : ISerializableItem
        {
            Save(obj);

            var key    = getKeyFromQualifiedType(typeof(T), qualifier ?? String.Empty);
            var parent = (_syncPointIndex.ContainsKey(key) ? _syncPointIndex[key] : Guid.Empty);
            var ret    = new SyncPointInformation(obj.ContentHash, parent, typeof(T), qualifier ?? String.Empty, createdOn ?? DateTimeOffset.Now);

            Save(ret);
            _syncPointIndex[key] = ret.ContentHash;
            _syncPoints.GetOrAdd(key).Add(ret);

            this.Log().InfoFormat("Created sync point: {0}.{1}", obj.ContentHash, qualifier);

            FlushChanges();
            return(ret);
        }
        public void EnsureSyncPointInformationCalculatesHash()
        {
            var template = new SyncPointInformation(Guid.NewGuid(), Guid.NewGuid(), typeof (string), "Foo", DateTimeOffset.MinValue);
            var fixtures = new[] {
                template,
                new SyncPointInformation(template.RootObjectHash, template.ParentSyncPoint, typeof (string), template.Qualifier, DateTimeOffset.MaxValue),
                new SyncPointInformation(template.RootObjectHash, template.ParentSyncPoint, typeof (string), "Bar", template.CreatedOn),
                new SyncPointInformation(template.RootObjectHash, template.ParentSyncPoint, typeof (int), template.Qualifier, template.CreatedOn),
                new SyncPointInformation(template.RootObjectHash, Guid.NewGuid(), typeof (string), template.Qualifier, template.CreatedOn),
                new SyncPointInformation(Guid.NewGuid(), template.ParentSyncPoint, typeof (string), template.Qualifier, template.CreatedOn),
            };

            //PexAssert.AreDistinctValues(fixtures.Select(x => x.ContentHash).ToArray());
            foreach(var v in fixtures) {
                var hash = v.ContentHash;
                Assert.True(fixtures.Count(x => x.ContentHash == hash) == 1);
            }
        }
示例#5
0
        public void EnsureSyncPointInformationDoesntSerializeExtraJunk()
        {
            var template = new SyncPointInformation(Guid.NewGuid(), Guid.NewGuid(), typeof(string), "Foo", DateTimeOffset.MinValue);
            var json     = JSONHelper.Serialize(template);

            var expected = new[] {
                "RootObjectHash",
                "ParentSyncPoint",
                "RootObjectTypeName",
                "Qualifier",
                "CreatedOn"
            };

            // TODO: This test sucks out loud
            foreach (var v in expected)
            {
                Assert.True(json.Contains(v));
            }
        }
示例#6
0
        public void EnsureSyncPointInformationCalculatesHash()
        {
            var template = new SyncPointInformation(Guid.NewGuid(), Guid.NewGuid(), typeof(string), "Foo", DateTimeOffset.MinValue);
            var fixtures = new[] {
                template,
                new SyncPointInformation(template.RootObjectHash, template.ParentSyncPoint, typeof(string), template.Qualifier, DateTimeOffset.MaxValue),
                new SyncPointInformation(template.RootObjectHash, template.ParentSyncPoint, typeof(string), "Bar", template.CreatedOn),
                new SyncPointInformation(template.RootObjectHash, template.ParentSyncPoint, typeof(int), template.Qualifier, template.CreatedOn),
                new SyncPointInformation(template.RootObjectHash, Guid.NewGuid(), typeof(string), template.Qualifier, template.CreatedOn),
                new SyncPointInformation(Guid.NewGuid(), template.ParentSyncPoint, typeof(string), template.Qualifier, template.CreatedOn),
            };

            //PexAssert.AreDistinctValues(fixtures.Select(x => x.ContentHash).ToArray());
            foreach (var v in fixtures)
            {
                var hash = v.ContentHash;
                Assert.True(fixtures.Count(x => x.ContentHash == hash) == 1);
            }
        }