Пример #1
0
        public UdpFilterViewModel(FilterValue filterValue, FilterFormatType type, string crProcess, DynamicTypeManager theDynamicTypeManager, string name, string crFieldName, FilterList filterList)
        {
            if (theDynamicTypeManager == null)
            {
                throw new ArgumentNullException("theDynamicTypeManager");
            }

            Name = name;
            Type = type != null ? GetTypeForView(type.MemberType.Name != "Nullable`1" ? type.MemberType : type.MemberType.GenericTypeArguments[0]) : "Text";

            if (crProcess != null)
            {
                //Type itemType = theDynamicTypeManager.GetInfoType<IInfoClass>(crProcess);
                //PropertyInfo guidProperty = itemType.GetPropertyByName("Guid");
               // PropertyInfo crFieldProperty = itemType.GetPropertyByName(crFieldName);

                if (crProcess == Constants.StateProcessName)
                {
                    Values = theDynamicTypeManager.GetList<IInfoList>(crProcess, string.Empty, 0, int.MaxValue, null, filterList)
                            .Cast<IStateInfo>()
                            .Select(x => new IdValuePair
                            {
                                Id = x.Id.ToString(CultureInfo.InvariantCulture),//guidProperty.With(v => v.GetValue(x)).Return(v => v.ToString(), string.Empty),
                                //Value = crFieldProperty.GetValue(x)
                                Value = x.GetValueByPropertyName(crFieldName)

                            })
                            .ToList();
                }
                else
                {
                    Values = theDynamicTypeManager.GetList<IInfoList>(crProcess, string.Empty, 0, int.MaxValue)
                        .Cast<IInfoClass>()
                        .Select(x => new IdValuePair
                        {
                            Id = x.Id.ToString(CultureInfo.InvariantCulture),
                            Value = x.GetValueByPropertyName(crFieldName)
                        })
                        .ToList();
                }
            }
            else
            {
                if (Type == "Approval")
                {
                    Values = Enum.GetValues(typeof(ApprovalStates)).Cast<ApprovalStates>().Select(x => new IdValuePair { Id = x.ToString(), Value = x.GetDescription() }).ToList();
                }
                else
                {
                    Values = null;
                }
            }

            DefaultValue = filterValue != null && filterValue.DefaultValue != null ? Convert.ToString(filterValue.DefaultValue, CultureInfo.InvariantCulture) : string.Empty;
        }
Пример #2
0
        public void GetList_WhenThrowsException_CallsLogger()
        {
            var processName = Guid.NewGuid().ToString();
            var dynamicTypeManager = new DynamicTypeManager();
            var loggerMock = Mock.Create<ILogger>();
            dynamicTypeManager.Logger = loggerMock;
            dynamicTypeManager.GetList<IInfoList>(processName);

            Mock.Assert(() => loggerMock.Log(Arg.IsAny<LogSeverity>(), Arg.IsAny<string>(), Arg.IsAny<string>()), Occurs.AtLeastOnce());
        }