public void IsConsistent_ReturnsTrue_WhenEmpty()
        {
            var testLogger = Substitute.For<IDuplicateIdConsistencyCheckerLogger>();

            var testChecker = new DuplicateIdConsistencyChecker(testLogger);

            var testItem = new FakeItem(ID.NewID.Guid);

            Assert.True(testChecker.IsConsistent(testItem));
        }
        public void IsConsistent_ReturnsTrue_WhenEmpty()
        {
            var testLogger = new Mock<IDuplicateIdConsistencyCheckerLogger>();

            var testChecker = new DuplicateIdConsistencyChecker(testLogger.Object);

            var testItem = new Mock<ISerializedItem>();
            testItem.SetupGet(x => x.Id).Returns(() => ID.NewID);

            Assert.IsTrue(testChecker.IsConsistent(testItem.Object));
        }
		public void IsConsistent_ReturnsTrue_WhenNotDuplicated()
		{
			var testLogger = Substitute.For<IDuplicateIdConsistencyCheckerLogger>();

			var testChecker = new DuplicateIdConsistencyChecker(testLogger);

			var testItem1 = CreateTestItem(ID.NewID.Guid);

			var testItem2 = CreateTestItem(ID.NewID.Guid);

			testChecker.AddProcessedItem(testItem1);
			Assert.True(testChecker.IsConsistent(testItem2));
		}
        public void IsConsistent_ReturnsTrue_WhenDuplicatedIdsAreInDifferentDatabases()
        {
            var testLogger = Substitute.For<IDuplicateIdConsistencyCheckerLogger>();

            var testChecker = new DuplicateIdConsistencyChecker(testLogger);

            var duplicatedId = ID.NewID.Guid;

            var testItem1 = new FakeItem(duplicatedId, "master");

            var testItem2  = new FakeItem(duplicatedId, "core");

            testChecker.AddProcessedItem(testItem1);
            Assert.True(testChecker.IsConsistent(testItem2));
        }
        public void IsConsistent_ReturnsFalse_WhenDuplicated()
        {
            var testLogger = Substitute.For<IDuplicateIdConsistencyCheckerLogger>();

            var testChecker = new DuplicateIdConsistencyChecker(testLogger);

            var duplicatedId = ID.NewID.Guid;

            var testItem1 = new FakeItem(duplicatedId);

            var testItem2 = new FakeItem(duplicatedId);

            testChecker.AddProcessedItem(testItem1);
            Assert.False(testChecker.IsConsistent(testItem2));
        }
		public void IsConsistent_ReturnsTrue_WhenDuplicatedIdsAreInDifferentDatabases()
		{
			var testLogger = Substitute.For<IDuplicateIdConsistencyCheckerLogger>();

			var testChecker = new DuplicateIdConsistencyChecker(testLogger);

			var duplicatedId = ID.NewID.Guid;

			// ReSharper disable once RedundantArgumentDefaultValue
			var testItem1 = CreateTestItem(duplicatedId, "master");

			var testItem2 = CreateTestItem(duplicatedId, "core");

			testChecker.AddProcessedItem(testItem1);
			Assert.True(testChecker.IsConsistent(testItem2));
		}
        public void IsConsistent_ReturnsFalse_WhenDuplicated()
        {
            var testLogger = new Mock<IDuplicateIdConsistencyCheckerLogger>();

            var testChecker = new DuplicateIdConsistencyChecker(testLogger.Object);

            var duplicatedId = ID.NewID;

            var testItem1 = new Mock<ISerializedItem>();
            testItem1.SetupGet(x => x.Id).Returns(duplicatedId);

            var testItem2 = new Mock<ISerializedItem>();
            testItem2.SetupGet(x => x.Id).Returns(duplicatedId);

            testChecker.AddProcessedItem(testItem1.Object);
            Assert.IsFalse(testChecker.IsConsistent(testItem2.Object));
        }
        public void IsConsistent_LogsError_WhenDuplicated()
        {
            var testLogger = Substitute.For<IDuplicateIdConsistencyCheckerLogger>();

            var testChecker = new DuplicateIdConsistencyChecker(testLogger);

            var duplicatedId = ID.NewID.Guid;

            var testItem1 = new FakeItem(duplicatedId);

            var testItem2 = new FakeItem(duplicatedId);

            testChecker.AddProcessedItem(testItem1);
            testChecker.IsConsistent(testItem2);

            testLogger.Received().DuplicateFound(Arg.Any<DuplicateIdConsistencyChecker.DuplicateIdEntry>(), testItem2);
        }
        public void IsConsistent_ReturnsTrue_WhenDuplicatedIdsAreInDifferentDatabases()
        {
            var testLogger = new Mock<IDuplicateIdConsistencyCheckerLogger>();

            var testChecker = new DuplicateIdConsistencyChecker(testLogger.Object);

            var duplicatedId = ID.NewID;

            var testItem1 = new Mock<ISerializedItem>();
            testItem1.SetupGet(x => x.Id).Returns(duplicatedId);
            testItem1.SetupGet(x => x.DatabaseName).Returns("master");

            var testItem2 = new Mock<ISerializedItem>();
            testItem2.SetupGet(x => x.Id).Returns(duplicatedId);
            testItem2.SetupGet(x => x.DatabaseName).Returns("core");

            testChecker.AddProcessedItem(testItem1.Object);
            Assert.IsTrue(testChecker.IsConsistent(testItem2.Object));
        }
        public void IsConsistent_LogsError_WhenDuplicated()
        {
            var testLogger = new Mock<IDuplicateIdConsistencyCheckerLogger>();

            var testChecker = new DuplicateIdConsistencyChecker(testLogger.Object);

            var duplicatedId = ID.NewID;

            var testItem1 = new Mock<ISerializedItem>();
            testItem1.SetupGet(x => x.Id).Returns(duplicatedId);

            var testItem2 = new Mock<ISerializedItem>();
            testItem2.SetupGet(x => x.Id).Returns(duplicatedId);

            testChecker.AddProcessedItem(testItem1.Object);
            testChecker.IsConsistent(testItem2.Object);

            testLogger.Verify(x => x.DuplicateFound(testItem1.Object, testItem2.Object), Times.Once());
        }
		public virtual void DuplicateFound(DuplicateIdConsistencyChecker.DuplicateIdEntry existingItemData, IItemData duplicateItemData)
		{
			_logger.Error("Duplicate serialized item IDs were detected ({0}) - this usually indicates corruption in the serialization provider data.<br>Item 1: {1}<br> Item 1 ProviderId: {2}<br>Item 2: {3}<br>Item 2 ProviderId: {4}".FormatWith(duplicateItemData.Id, existingItemData.DisplayName, existingItemData.SerializedItemId, duplicateItemData.GetDisplayIdentifier(), duplicateItemData.SerializedItemId));
		}
        public void IsConsistent_ReturnsTrue_WhenNotDuplicated()
        {
            var testLogger = new Mock<IDuplicateIdConsistencyCheckerLogger>();

            var testChecker = new DuplicateIdConsistencyChecker(testLogger.Object);

            var testItem1 = new Mock<ISerializableItem>();
            testItem1.SetupGet(x => x.Id).Returns(() => ID.NewID.Guid);

            var testItem2 = new Mock<ISerializableItem>();
            testItem2.SetupGet(x => x.Id).Returns(() => ID.NewID.Guid);

            testChecker.AddProcessedItem(testItem1.Object);
            Assert.IsTrue(testChecker.IsConsistent(testItem2.Object));
        }