public UnicornDataProvider(ITargetDataStore targetDataStore, ISourceDataStore sourceDataStore, IPredicate predicate, IFieldFilter fieldFilter, IUnicornDataProviderLogger logger, IUnicornDataProviderConfiguration dataProviderConfiguration, PredicateRootPathResolver rootPathResolver)
        {
            Assert.ArgumentNotNull(targetDataStore, "serializationProvider");
            Assert.ArgumentNotNull(predicate, "predicate");
            Assert.ArgumentNotNull(fieldFilter, "fieldPredicate");
            Assert.ArgumentNotNull(logger, "logger");
            Assert.ArgumentNotNull(sourceDataStore, "sourceDataStore");
            Assert.ArgumentNotNull(dataProviderConfiguration, "configuration");
            Assert.ArgumentNotNull(rootPathResolver, "rootPathResolver");

            _logger = logger;
            _dataProviderConfiguration = dataProviderConfiguration;
            _rootPathResolver = rootPathResolver;
            _predicate = predicate;
            _fieldFilter = fieldFilter;
            _targetDataStore = targetDataStore;
            _sourceDataStore = sourceDataStore;

            try
            {
                _targetDataStore.RegisterForChanges(RemoveItemFromCaches);
            }
            catch (NotImplementedException)
            {
                // if the data store doesn't implement watching, cool story bruv
            }
        }
        public UnicornDataProvider(ITargetDataStore targetDataStore, ISourceDataStore sourceDataStore, IPredicate predicate, IFieldFilter fieldFilter, IUnicornDataProviderLogger logger, IUnicornDataProviderConfiguration dataProviderConfiguration, ISyncConfiguration syncConfiguration, PredicateRootPathResolver rootPathResolver)
        {
            Assert.ArgumentNotNull(targetDataStore, nameof(targetDataStore));
            Assert.ArgumentNotNull(predicate, nameof(predicate));
            Assert.ArgumentNotNull(fieldFilter, nameof(fieldFilter));
            Assert.ArgumentNotNull(logger, nameof(logger));
            Assert.ArgumentNotNull(sourceDataStore, nameof(sourceDataStore));
            Assert.ArgumentNotNull(dataProviderConfiguration, nameof(dataProviderConfiguration));
            Assert.ArgumentNotNull(rootPathResolver, nameof(rootPathResolver));
            Assert.ArgumentNotNull(syncConfiguration, nameof(syncConfiguration));

            _logger = logger;
            _dataProviderConfiguration = dataProviderConfiguration;
            _syncConfiguration = syncConfiguration;
            _rootPathResolver = rootPathResolver;
            _predicate = predicate;
            _fieldFilter = fieldFilter;
            _targetDataStore = targetDataStore;
            _sourceDataStore = sourceDataStore;

            // enable capturing recycle bin and archive restores to serialize the target item if included
            EventManager.Subscribe<RestoreItemCompletedEvent>(HandleItemRestored);

            try
            {
                _targetDataStore.RegisterForChanges(RemoveItemFromCaches);
            }
            catch (NotImplementedException)
            {
                // if the data store doesn't implement watching, cool story bruv
            }
        }
        public SerializationLoader(ITargetDataStore targetDataStore, ISourceDataStore sourceDataStore, IPredicate predicate, IEvaluator evaluator, ISerializationLoaderLogger logger, PredicateRootPathResolver predicateRootPathResolver)
        {
            Assert.ArgumentNotNull(targetDataStore, "serializationProvider");
            Assert.ArgumentNotNull(sourceDataStore, "sourceDataStore");
            Assert.ArgumentNotNull(predicate, "predicate");
            Assert.ArgumentNotNull(evaluator, "evaluator");
            Assert.ArgumentNotNull(logger, "logger");
            Assert.ArgumentNotNull(predicateRootPathResolver, "predicateRootPathResolver");

            Logger = logger;
            PredicateRootPathResolver = predicateRootPathResolver;
            Evaluator = evaluator;
            Predicate = predicate;
            TargetDataStore = targetDataStore;
            SourceDataStore = sourceDataStore;
        }
        public SerializationLoader(ISourceDataStore sourceDataStore, ITargetDataStore targetDataStore, IPredicate predicate, IEvaluator evaluator, ISerializationLoaderLogger logger, ISyncConfiguration syncConfiguration, PredicateRootPathResolver predicateRootPathResolver)
        {
            Assert.ArgumentNotNull(targetDataStore, nameof(targetDataStore));
            Assert.ArgumentNotNull(sourceDataStore, nameof(sourceDataStore));
            Assert.ArgumentNotNull(predicate, nameof(predicate));
            Assert.ArgumentNotNull(evaluator, nameof(evaluator));
            Assert.ArgumentNotNull(logger, nameof(logger));
            Assert.ArgumentNotNull(predicateRootPathResolver, nameof(predicateRootPathResolver));
            Assert.ArgumentNotNull(syncConfiguration, nameof(syncConfiguration));

            Logger = logger;
            SyncConfiguration = syncConfiguration;
            PredicateRootPathResolver = predicateRootPathResolver;
            Evaluator = evaluator;
            Predicate = predicate;
            TargetDataStore = targetDataStore;
            SourceDataStore = sourceDataStore;
        }
Exemple #5
0
		//[Fact]
		//public void LoadTree_IdentifiesOrphanChildItem()
		//{
		//	var root = CreateTestTree(2);

		//	var serializedRootItem = new FakeItem("Root");
		//	serializedRootItem.SetupGet(y => y.DatabaseName).Returns("flag");

		//	var predicate = CreateInclusiveTestPredicate();

		//	var serializationProvider = Substitute.For<ITargetDataStore>();
		//	serializationProvider.Setup(x => x.GetReference(root)).Returns(serializedRootItem);

		//	var sourceDataProvider = Substitute.For<ISourceDataProvider>();
		//	sourceDataProvider.Setup(x => x.GetItemById("flag", It.IsAny<ID>())).Returns(root);

		//	var evaluator = Substitute.For<IEvaluator>();

		//	var loader = CreateTestLoader(sourceDataProvider, serializationProvider, predicate, evaluator, null);

		//	TestLoadTree(loader, serializedRootItem);

		//	evaluator.Verify(x => x.EvaluateOrphans(It.Is<ISourceItem[]>(y => y.Contains(root.Children[0]))));
		//}

		//[Fact]
		//public void LoadTree_DoesNotIdentifyValidChildrenAsOrphans()
		//{
		//	var root = CreateTestTree(2);

		//	var serializedRootItem = new FakeItem("Root");
		//	serializedRootItem.SetupGet(y => y.DatabaseName).Returns("flag");

		//	var serializedChildItem = new FakeItem("Child");
		//	serializedChildItem.SetupGet(y => y.DatabaseName).Returns("childflag");

		//	serializedRootItem.Setup(x => x.GetChildItems()).Returns(new[] { serializedChildItem });

		//	var predicate = CreateInclusiveTestPredicate();

		//	var serializationProvider = Substitute.For<ITargetDataStore>();
		//	serializationProvider.Setup(x => x.GetReference(root)).Returns(serializedRootItem);

		//	var sourceDataProvider = Substitute.For<ISourceDataProvider>();
		//	sourceDataProvider.Setup(x => x.GetItemById("flag", It.IsAny<ID>())).Returns(root);
		//	sourceDataProvider.Setup(x => x.GetItemById("childflag", It.IsAny<ID>())).Returns(root.Children[0]);

		//	var evaluator = Substitute.For<IEvaluator>();

		//	var loader = CreateTestLoader(sourceDataProvider, serializationProvider, predicate, evaluator, null);

		//	TestLoadTree(loader, serializedRootItem);

		//	evaluator.Verify(x => x.EvaluateOrphans(It.IsAny<ISourceItem[]>()), Times.Never());
		//}

		//[Fact]
		//public void LoadTree_DoesNotIdentifySkippedItemsAsOrphans()
		//{
		//	var root = CreateTestTree(2);

		//	var serializedRootItem = new FakeItem("Root");

		//	var predicate = CreateExclusiveTestPredicate(new[] { serializedRootItem }, new[] { root });

		//	var serializationProvider = Substitute.For<ITargetDataStore>();
		//	serializationProvider.Setup(x => x.GetReference(root)).Returns(serializedRootItem);

		//	var sourceDataProvider = Substitute.For<ISourceDataProvider>();
		//	sourceDataProvider.Setup(x => x.GetItemById(It.IsAny<string>(), It.IsAny<ID>())).Returns(root);

		//	var evaluator = Substitute.For<IEvaluator>();

		//	var loader = CreateTestLoader(sourceDataProvider, serializationProvider, predicate, evaluator, null);

		//	TestLoadTree(loader, serializedRootItem);

		//	evaluator.Verify(x => x.EvaluateOrphans(It.IsAny<ISourceItem[]>()), Times.Never());
		//}

		//[Fact]
		//public void LoadTree_UpdatesWhenItemDoesNotExistInSource()
		//{
		//	var root = CreateTestTree(1);

		//	var serializedRootItem = new FakeItem("Root");
		//	serializedRootItem.SetupGet(y => y.DatabaseName).Returns("flag");

		//	var serializedChildItem = new FakeItem("Child");

		//	serializedRootItem.Setup(x => x.GetChildItems()).Returns(new[] { serializedChildItem });

		//	var predicate = CreateInclusiveTestPredicate();

		//	var serializationProvider = Substitute.For<ITargetDataStore>();
		//	serializationProvider.Setup(x => x.GetReference(root)).Returns(serializedRootItem);

		//	var sourceDataProvider = Substitute.For<ISourceDataProvider>();
		//	sourceDataProvider.Setup(x => x.GetItemById("flag", It.IsAny<ID>())).Returns(root);

		//	var evaluator = Substitute.For<IEvaluator>();

		//	var loader = CreateTestLoader(sourceDataProvider, serializationProvider, predicate, evaluator, null);

		//	TestLoadTree(loader, serializedRootItem);

		//	evaluator.Verify(x => x.EvaluateNewSerializedItem(serializedChildItem));
		//}

		//[Fact]
		//public void LoadTree_AbortsWhenConsistencyCheckFails()
		//{
		//	var root = CreateTestTree(1);

		//	var serializedRootItem = new FakeItem("Test");
		//	serializedRootItem.Setup(x => x.Deserialize(false)).Returns(root);

		//	var predicate = CreateInclusiveTestPredicate();

		//	var serializationProvider = Substitute.For<ITargetDataStore>();
		//	serializationProvider.Setup(x => x.GetReference(It.IsAny<ISourceItem>())).Returns(serializedRootItem);

		//	var logger = Substitute.For<ISerializationLoaderLogger>();
		//	var consistencyChecker = Substitute.For<IConsistencyChecker>();

		//	consistencyChecker.Setup(x => x.IsConsistent(It.IsAny<IItemData>())).Returns(false);

		//	var loader = CreateTestLoader(null, serializationProvider, predicate, null, logger);

		//	Assert.Throws<ConsistencyException>((() => loader.LoadTree(serializedRootItem, Substitute.For<IDeserializeFailureRetryer>(), consistencyChecker)));
		//}

		private SerializationLoader CreateTestLoader(ISourceDataStore sourceDataStore = null, ITargetDataStore targetDataStore = null, IPredicate predicate = null, IEvaluator evaluator = null, ISerializationLoaderLogger logger = null)
		{
			if (targetDataStore == null) targetDataStore = Substitute.For<ITargetDataStore>();
			if (sourceDataStore == null) sourceDataStore = Substitute.For<ISourceDataStore>();
			if (predicate == null) predicate = CreateInclusiveTestPredicate();
			if (evaluator == null) evaluator = Substitute.For<IEvaluator>();
			if (logger == null) logger = Substitute.For<ISerializationLoaderLogger>();
			var mockLogger2 = Substitute.For<ILogger>();

			var pathResolver = new PredicateRootPathResolver(predicate, targetDataStore, sourceDataStore, mockLogger2);

			return new SerializationLoader(sourceDataStore, targetDataStore, predicate, evaluator, logger, pathResolver);
		}
Exemple #6
0
        //[Fact]
        //public void LoadTree_IdentifiesOrphanChildItem()
        //{
        //    var root = CreateTestTree(2);
        //    var serializedRootItem = new FakeItem("Root");
        //    serializedRootItem.SetupGet(y => y.DatabaseName).Returns("flag");
        //    var predicate = CreateInclusiveTestPredicate();
        //    var serializationProvider = Substitute.For<ITargetDataStore>();
        //    serializationProvider.Setup(x => x.GetReference(root)).Returns(serializedRootItem);
        //    var sourceDataProvider = Substitute.For<ISourceDataProvider>();
        //    sourceDataProvider.Setup(x => x.GetItemById("flag", It.IsAny<ID>())).Returns(root);
        //    var evaluator = Substitute.For<IEvaluator>();
        //    var loader = CreateTestLoader(sourceDataProvider, serializationProvider, predicate, evaluator, null);
        //    TestLoadTree(loader, serializedRootItem);
        //    evaluator.Verify(x => x.EvaluateOrphans(It.Is<ISourceItem[]>(y => y.Contains(root.Children[0]))));
        //}
        //[Fact]
        //public void LoadTree_DoesNotIdentifyValidChildrenAsOrphans()
        //{
        //    var root = CreateTestTree(2);
        //    var serializedRootItem = new FakeItem("Root");
        //    serializedRootItem.SetupGet(y => y.DatabaseName).Returns("flag");
        //    var serializedChildItem = new FakeItem("Child");
        //    serializedChildItem.SetupGet(y => y.DatabaseName).Returns("childflag");
        //    serializedRootItem.Setup(x => x.GetChildItems()).Returns(new[] { serializedChildItem });
        //    var predicate = CreateInclusiveTestPredicate();
        //    var serializationProvider = Substitute.For<ITargetDataStore>();
        //    serializationProvider.Setup(x => x.GetReference(root)).Returns(serializedRootItem);
        //    var sourceDataProvider = Substitute.For<ISourceDataProvider>();
        //    sourceDataProvider.Setup(x => x.GetItemById("flag", It.IsAny<ID>())).Returns(root);
        //    sourceDataProvider.Setup(x => x.GetItemById("childflag", It.IsAny<ID>())).Returns(root.Children[0]);
        //    var evaluator = Substitute.For<IEvaluator>();
        //    var loader = CreateTestLoader(sourceDataProvider, serializationProvider, predicate, evaluator, null);
        //    TestLoadTree(loader, serializedRootItem);
        //    evaluator.Verify(x => x.EvaluateOrphans(It.IsAny<ISourceItem[]>()), Times.Never());
        //}
        //[Fact]
        //public void LoadTree_DoesNotIdentifySkippedItemsAsOrphans()
        //{
        //    var root = CreateTestTree(2);
        //    var serializedRootItem = new FakeItem("Root");
        //    var predicate = CreateExclusiveTestPredicate(new[] { serializedRootItem }, new[] { root });
        //    var serializationProvider = Substitute.For<ITargetDataStore>();
        //    serializationProvider.Setup(x => x.GetReference(root)).Returns(serializedRootItem);
        //    var sourceDataProvider = Substitute.For<ISourceDataProvider>();
        //    sourceDataProvider.Setup(x => x.GetItemById(It.IsAny<string>(), It.IsAny<ID>())).Returns(root);
        //    var evaluator = Substitute.For<IEvaluator>();
        //    var loader = CreateTestLoader(sourceDataProvider, serializationProvider, predicate, evaluator, null);
        //    TestLoadTree(loader, serializedRootItem);
        //    evaluator.Verify(x => x.EvaluateOrphans(It.IsAny<ISourceItem[]>()), Times.Never());
        //}
        //[Fact]
        //public void LoadTree_UpdatesWhenItemDoesNotExistInSource()
        //{
        //    var root = CreateTestTree(1);
        //    var serializedRootItem = new FakeItem("Root");
        //    serializedRootItem.SetupGet(y => y.DatabaseName).Returns("flag");
        //    var serializedChildItem = new FakeItem("Child");
        //    serializedRootItem.Setup(x => x.GetChildItems()).Returns(new[] { serializedChildItem });
        //    var predicate = CreateInclusiveTestPredicate();
        //    var serializationProvider = Substitute.For<ITargetDataStore>();
        //    serializationProvider.Setup(x => x.GetReference(root)).Returns(serializedRootItem);
        //    var sourceDataProvider = Substitute.For<ISourceDataProvider>();
        //    sourceDataProvider.Setup(x => x.GetItemById("flag", It.IsAny<ID>())).Returns(root);
        //    var evaluator = Substitute.For<IEvaluator>();
        //    var loader = CreateTestLoader(sourceDataProvider, serializationProvider, predicate, evaluator, null);
        //    TestLoadTree(loader, serializedRootItem);
        //    evaluator.Verify(x => x.EvaluateNewSerializedItem(serializedChildItem));
        //}
        //[Fact]
        //public void LoadTree_AbortsWhenConsistencyCheckFails()
        //{
        //    var root = CreateTestTree(1);
        //    var serializedRootItem = new FakeItem("Test");
        //    serializedRootItem.Setup(x => x.Deserialize(false)).Returns(root);
        //    var predicate = CreateInclusiveTestPredicate();
        //    var serializationProvider = Substitute.For<ITargetDataStore>();
        //    serializationProvider.Setup(x => x.GetReference(It.IsAny<ISourceItem>())).Returns(serializedRootItem);
        //    var logger = Substitute.For<ISerializationLoaderLogger>();
        //    var consistencyChecker = Substitute.For<IConsistencyChecker>();
        //    consistencyChecker.Setup(x => x.IsConsistent(It.IsAny<IItemData>())).Returns(false);
        //    var loader = CreateTestLoader(null, serializationProvider, predicate, null, logger);
        //    Assert.Throws<ConsistencyException>((() => loader.LoadTree(serializedRootItem, Substitute.For<IDeserializeFailureRetryer>(), consistencyChecker)));
        //}
        private SerializationLoader CreateTestLoader(ISourceDataStore sourceDataStore = null, ITargetDataStore targetDataStore = null, IPredicate predicate = null, IEvaluator evaluator = null, ISyncConfiguration syncConfiguration = null, ISerializationLoaderLogger logger = null)
        {
            targetDataStore = targetDataStore ?? Substitute.For<ITargetDataStore>();
            sourceDataStore = sourceDataStore ?? Substitute.For<ISourceDataStore>();
            predicate = predicate ?? CreateInclusiveTestPredicate();
            evaluator = evaluator ?? Substitute.For<IEvaluator>();
            logger = logger ?? Substitute.For<ISerializationLoaderLogger>();
            syncConfiguration = syncConfiguration ?? new TestSyncConfiguration();

            var mockLogger2 = Substitute.For<ILogger>();

            var pathResolver = new PredicateRootPathResolver(predicate, targetDataStore, sourceDataStore, mockLogger2);

            return new SerializationLoader(sourceDataStore, targetDataStore, predicate, evaluator, logger, syncConfiguration, pathResolver);
        }
		public RemotingPackageWriter(ISerializationProvider serializationProvider, PredicateRootPathResolver pathResolver)
		{
			_serializationProvider = serializationProvider;
			_pathResolver = pathResolver;
		}
Exemple #8
0
        private SerializationLoader CreateTestLoader(ISerializationProvider serializationProvider, ISourceDataProvider sourceDataProvider, IPredicate predicate, IEvaluator evaluator, ISerializationLoaderLogger logger)
        {
            var mockSerializationProvider = new Mock<ISerializationProvider>();
            var mockSourceDataProvider = new Mock<ISourceDataProvider>();
            var mockPredicate = new Mock<IPredicate>();
            var mockEvaluator = new Mock<IEvaluator>();
            var mockLogger = new Mock<ISerializationLoaderLogger>();
            var mockLogger2 = new Mock<ILogger>();
            var pathResolver = new PredicateRootPathResolver(predicate ?? mockPredicate.Object, serializationProvider ?? mockSerializationProvider.Object, sourceDataProvider ?? mockSourceDataProvider.Object, mockLogger2.Object);

            return new SerializationLoader(serializationProvider ?? mockSerializationProvider.Object,
                sourceDataProvider ?? mockSourceDataProvider.Object,
                predicate ?? mockPredicate.Object,
                evaluator ?? mockEvaluator.Object,
                logger ?? mockLogger.Object,
                pathResolver);
        }