public void CrSubfieldsRetrieverBaseAddSystemSourceFieldsShouldCallAddVersionFieldsByPublishedProcessInfo()
        {
            var vm = new ExpressionDesignerWindowViewModelBase.CrSubfieldsRetrieverBase(1);

            var sourceFields = new SourceField(new SourceFieldList());

            var fields = new FieldList();
            Mock.Arrange(() => fields.IsReadOnly).Returns(false);
            Mock.Arrange(() => FieldList.BeginGetFieldList(1, Arg.IsAny<EventHandler<DataPortalResult<FieldList>>>())).DoInstead<int, EventHandler<DataPortalResult<FieldList>>>((pid, evt) => evt(null, new DataPortalResult<FieldList>(fields, null, null)));

            IEnumerable<IExpressionField> expressionFields = null;

            var processInfo = new PublishedProcessInfo();
            Mock.Arrange(() => processInfo.ProcessId).Returns(1);
            Mock.Arrange(() => processInfo.ProcessOption).Returns(ProcessOption.VersionEnabled);

            vm.BeginLoadWorker(sourceFields, (f, fl) => { expressionFields = fl; }, processInfo);

            Assert.IsTrue(expressionFields.Any(x => x.Name == "Version Date"));
            Assert.IsTrue(expressionFields.Any(x => x.Name == Constants.VersionNumberName));
            Assert.IsTrue(expressionFields.Any(x => x.Name == "Version Master Id"));

            expressionFields = null;

            var processInfo2 = new PublishedProcessInfo();
            Mock.Arrange(() => processInfo2.ProcessId).Returns(1);
            Mock.Arrange(() => processInfo2.ProcessOption).Returns(ProcessOption.None);

            vm.BeginLoadWorker(sourceFields, (f, fl) => { expressionFields = fl; }, processInfo2);

            Assert.IsFalse(expressionFields.Any(x => x.Name == "Version Date"));
            Assert.IsFalse(expressionFields.Any(x => x.Name == Constants.VersionNumberName));
            Assert.IsFalse(expressionFields.Any(x => x.Name == "Version Master Id"));
        }
        public void CrSubfieldsRetrieverBaseAddSystemSourceFieldsShouldCallAddIdFieldByProcessInfo()
        {
            var vm = new ExpressionDesignerWindowViewModelBase.CrSubfieldsRetrieverBase(1);

            var sourceFields = new SourceField(new SourceFieldList());

            var fields = new FieldList();
            Mock.Arrange(() => fields.IsReadOnly).Returns(false);
            Mock.Arrange(() => FieldList.BeginGetFieldList(1, Arg.IsAny<EventHandler<DataPortalResult<FieldList>>>())).DoInstead<int, EventHandler<DataPortalResult<FieldList>>>((pid, evt) => evt(null, new DataPortalResult<FieldList>(fields, null, null)));

            IEnumerable<IExpressionField> expressionFields = null;

            var processInfo = new PublishedProcessInfo();
            Mock.Arrange(() => processInfo.ProcessId).Returns(1);

            vm.BeginLoadWorker(sourceFields, (f, fl) => { expressionFields = fl; }, processInfo);

            Assert.IsNotNull(expressionFields.First(x => x.Name == "Id"));
        }
        public void CrSubfieldsRetrieverBaseBeginLoadWorkerShouldCallCanUseFieldType()
        {
            // Arrange.
            var vm = new ExpressionDesignerWindowViewModelBase.CrSubfieldsRetrieverBase(1);
            var sourceFields = new SourceField(new SourceFieldList()) { SystemName = "Ref" };
            var fields = new FieldList();
            Mock.Arrange(() => fields.IsReadOnly).Returns(false);
            fields.Add(new FieldInfo(1, "F", "F", new FieldTypeInfo("String", "String", false), string.Empty, ColumnTypes.String, Guid.Empty, false, false, false));

            Mock.Arrange(() => FieldList.BeginGetFieldList(1, Arg.IsAny<EventHandler<DataPortalResult<FieldList>>>())).DoInstead<int, EventHandler<DataPortalResult<FieldList>>>((pid, evt) => evt(null, new DataPortalResult<FieldList>(fields, null, null)));
            IEnumerable<IExpressionField> expressionFields = null;

            Mock.Arrange(() => ExpressionDesignerWindowViewModelBase.CrSubfieldsRetrieverBase.CanUseFieldType(Arg.IsAny<FieldTypeInfo>())).Returns(true);

            var processInfo = new PublishedProcessInfo();
            Mock.Arrange(() => processInfo.ProcessId).Returns(1);
            vm.BeginLoadWorker(sourceFields, (f, fl) => { expressionFields = fl; }, processInfo);

            Assert.AreEqual(2, expressionFields.Count());

            Mock.Arrange(() => ExpressionDesignerWindowViewModelBase.CrSubfieldsRetrieverBase.CanUseFieldType(Arg.IsAny<FieldTypeInfo>())).Returns(false);

            var processInfo2 = new PublishedProcessInfo();
            Mock.Arrange(() => processInfo2.ProcessId).Returns(1);
            vm.BeginLoadWorker(sourceFields, (f, fl) => { expressionFields = fl; }, processInfo2);

            Assert.AreEqual(1, expressionFields.Count());
        }
        public void CrSubfieldsRetrieverBaseBeginLoadWorkerShouldCallAddSystemSourceFields()
        {
            var vm = new ExpressionDesignerWindowViewModelBase.CrSubfieldsRetrieverBase(1);

            var sourceFields = new SourceField(new SourceFieldList());

            var fields = new FieldList();
            Mock.Arrange(() => fields.IsReadOnly).Returns(false);
            Mock.Arrange(() => FieldList.BeginGetFieldList(1, Arg.IsAny<EventHandler<DataPortalResult<FieldList>>>())).DoInstead<int, EventHandler<DataPortalResult<FieldList>>>((pid, evt) => evt(null, new DataPortalResult<FieldList>(fields, null, null)));

            IEnumerable<IExpressionField> expressionFields = null;

            var processInfo = new PublishedProcessInfo();
            Mock.Arrange(() => processInfo.ProcessId).Returns(1);

            var isCalled = false;
            Mock.NonPublic.Arrange(vm, "AddSystemSourceFields", ArgExpr.IsAny<PublishedProcessInfo>(), ArgExpr.IsAny<List<IExpressionField>>()).DoInstead(() => { isCalled = true; });
            vm.BeginLoadWorker(sourceFields, (f, fl) => { expressionFields = fl; }, processInfo);

            Assert.IsTrue(isCalled);
        }
        public void CrSubfieldsRetrieverBaseBeginLoadWorkerShouldCreateStringForMultiCrossRef()
        {
            // Arrange.
            var vm = new ExpressionDesignerWindowViewModelBase.CrSubfieldsRetrieverBase(1);
            var sourceFields = new SourceField(new SourceFieldList()) { SystemName = "Ref" };
            var fields = new FieldList();
            Mock.Arrange(() => fields.IsReadOnly).Returns(false);
            fields.Add(new FieldInfo(1, "Ref", "Ref", new FieldTypeInfo("MultiReference", "MultiReference", false), string.Empty, ColumnTypes.MultiReference, Guid.Empty, false, false, false));

            Mock.Arrange(() => FieldList.BeginGetFieldList(1, Arg.IsAny<EventHandler<DataPortalResult<FieldList>>>())).DoInstead<int, EventHandler<DataPortalResult<FieldList>>>((pid, evt) => evt(null, new DataPortalResult<FieldList>(fields, null, null)));

            IEnumerable<IExpressionField> expressionFields = null;
            var processInfo = new PublishedProcessInfo();
            Mock.Arrange(() => processInfo.ProcessId).Returns(1);
            vm.BeginLoadWorker(sourceFields, (f, fl) => { expressionFields = fl; }, processInfo);

            Assert.AreEqual(2, expressionFields.Count());

            var firstField = expressionFields.First(x => x.Name == "Ref") as SourceField;
            Assert.AreEqual(NodeDataType.String, firstField.DataType);
            Assert.AreEqual(NodeDataType.String, firstField.Connector.DataType);
            Assert.AreEqual("Ref.Ref", firstField.SystemName);
            Assert.IsNull(firstField.SubfieldsRetriever);
        }