public void InitializeTest()
        {
            // Arrange.
            const string ProcessName = "TestProcess";

            var dtm = Mock.Create<IDynamicTypeManager>();
            Mock.Arrange(() => dtm.GetEditableRootType(ProcessName)).Returns(typeof(TestEdit));

            var retriever = new SingleCrossReferenceSourceItemsRetriever { DynamicTypeManager = dtm };

            // Act.
            retriever.Initialize(ProcessName, TestsHelper.ExtractPropertyName(() => new TestEdit().CR));

            // Assert.
            Assert.AreEqual(TestsHelper.ExtractPropertyName(() => new TestEdit().CR), retriever.FieldName);
            Assert.AreEqual(ReferencedProcess, retriever.ReferencedProcess);
        }
        public void GetNewItemsTest()
        {
            // Arrange.
            var refEdit = Mock.Create<IEditableRoot>();
            Mock.Arrange(() => refEdit.Id).Returns(2);

            SetupGetEditableRoot(ReferencedProcess, refEdit);

            var retriever = new SingleCrossReferenceSourceItemsRetriever
                                {
                                    DynamicTypeManager = _dtm,
                                    FieldName = TestsHelper.ExtractPropertyName(() => new TestEdit().CR),
                                    ReferencedProcess = ReferencedProcess
                                };

            var oldItem = new TestEdit { CR = 1 };
            var newItem1 = new TestEdit { CR = null };
            var newItem2 = new TestEdit { CR = 1 };
            var newItem3 = new TestEdit { CR = 2 };

            // Act.
            var result = retriever.GetNewItems(newItem1, oldItem);

            // Assert.
            Assert.AreEqual(0, result.Count);

            // Act.
            result = retriever.GetNewItems(newItem2, oldItem);

            // Assert.
            Assert.AreEqual(0, result.Count);

            // Act.
            result = retriever.GetNewItems(newItem3, oldItem);

            // Assert.
            Assert.AreEqual(1, result.Count);
            Assert.AreSame(refEdit, result[0]);

            var refEdit1 = Mock.Create<IEditableRoot>();
            var refEdit2 = Mock.Create<IEditableRoot>();

            var innerRetriever = Mock.Create<ISourceItemsRetriever>();
            Mock.Arrange(() => innerRetriever.GetAllItems(refEdit)).Returns(() => new[] { refEdit1, refEdit2 });

            retriever.Subretriever = innerRetriever;

            // Act.
            result = retriever.GetNewItems(newItem1, oldItem);

            // Assert.
            Assert.AreEqual(0, result.Count);

            // Act.
            result = retriever.GetNewItems(newItem2, oldItem);

            // Assert.
            Assert.AreEqual(0, result.Count);

            // Act.
            result = retriever.GetNewItems(newItem3, oldItem);

            // Assert.
            Assert.AreEqual(2, result.Count);
            Assert.IsTrue(result.Contains(refEdit1));
            Assert.IsTrue(result.Contains(refEdit2));
        }