示例#1
0
        private static IQueryable <T> Select <T>(IQueryable <T> data, Dictionary <string, object> filter) where T : class, IGenericSortable
        {
            data = data.OrderBy(g => g.LocalOrdering);

            var dataType = typeof(T);

            foreach (var kvp in filter)
            {
                var propInfo = dataType.GetPropertiesRecursively(p => p.Name == kvp.Key).Single();
                var propType = propInfo.PropertyType;

                var paramExpr = Expression.Parameter(dataType);
                var propExpr  = Expression.Property(paramExpr, propInfo);

                var value = ValueTypeConverter.Convert(kvp.Value, propType);

                var valueExpr = Expression.Constant(value);
                var equalExpr = Expression.Equal(propExpr, valueExpr);
                var lambda    = Expression.Lambda <Func <T, bool> >(equalExpr, paramExpr);

                data = data.Where(lambda);
            }

            return(data);
        }
        public RelativeRoute GetRoute(TValue fieldValue, bool searchSignificant)
        {
            if (!typeof(TValue).IsValueType && fieldValue == null)
            {
                return(null);
            }

            string stringValue;

            if (IsGuidField)
            {
                stringValue = UrlUtils.CompressGuid((fieldValue as Guid?).Value);
            }
            else if (IsStringField)
            {
                stringValue = searchSignificant ? UrlUtils.EncodeUrlInvalidCharacters(fieldValue as string)
                                                : StringToUrlPart(fieldValue as string);
            }
            else
            {
                stringValue = ValueTypeConverter.Convert <string>(fieldValue);
            }


            return(new RelativeRoute {
                PathSegments = new[] { stringValue }
            });
        }
示例#3
0
        private static DataKeyPropertyCollection CopyFieldValues(DataType dataType, IData data, XElement addElement)
        {
            var dataKeyPropertyCollection = new DataKeyPropertyCollection();

            var properties = GetDataTypeProperties(dataType.InterfaceType);

            foreach (XAttribute attribute in addElement.Attributes())
            {
                string fieldName = attribute.Name.LocalName;
                if (IsObsoleteField(dataType, fieldName))
                {
                    continue;
                }

                PropertyInfo propertyInfo = properties[fieldName];

                object fieldValue = ValueTypeConverter.Convert(attribute.Value, propertyInfo.PropertyType);
                propertyInfo.SetValue(data, fieldValue, null);

                if (dataType.InterfaceType.GetKeyPropertyNames().Contains(fieldName))
                {
                    dataKeyPropertyCollection.AddKeyProperty(fieldName, fieldValue);
                }
            }

            return(dataKeyPropertyCollection);
        }
示例#4
0
        private object ExtractKeyValue(string internalDataUrl)
        {
            int openBracketIndex = internalDataUrl.IndexOf("(", StringComparison.Ordinal);

            if (openBracketIndex < 0)
            {
                return(null);
            }

            int closingBracketOffset = internalDataUrl.IndexOf(")", openBracketIndex + 1, StringComparison.Ordinal);

            if (closingBracketOffset < 0)
            {
                return(null);
            }

            string dataIdStr = internalDataUrl.Substring(openBracketIndex + 1, closingBracketOffset - openBracketIndex - 1);

            object keyValue = ValueTypeConverter.Convert(dataIdStr, _keyType);

            if (keyValue == null || (keyValue is Guid && (Guid)keyValue == Guid.Empty))
            {
                return(null);
            }

            return(keyValue);
        }
        private void SetNewInstanceFieldDefaultValues(IData data)
        {
            Type interfaceType             = data.DataSourceId.InterfaceType;
            List <PropertyInfo> properties = interfaceType.GetPropertiesRecursively();

            foreach (PropertyInfo propertyInfo in properties)
            {
                try
                {
                    var attribute = propertyInfo.GetCustomAttributesRecursively <NewInstanceDefaultFieldValueAttribute>().SingleOrDefault();
                    if (attribute == null || !attribute.HasValue)
                    {
                        continue;
                    }
                    if (!propertyInfo.CanWrite)
                    {
                        Log.LogError(LogTitle, string.Format("The property '{0}' on the interface '{1}' has defined a standard value, but no setter", propertyInfo.Name, interfaceType));
                        continue;
                    }

                    object value = attribute.GetValue();
                    value = ValueTypeConverter.Convert(value, propertyInfo.PropertyType);

                    PropertyInfo targetPropertyInfo = data.GetType().GetProperties().Single(f => f.Name == propertyInfo.Name);
                    targetPropertyInfo.SetValue(data, value, null);
                }
                catch (Exception ex)
                {
                    Log.LogError(LogTitle, string.Format("Failed to set the standard value on the property '{0}' on the interface '{1}'", propertyInfo.Name, interfaceType));
                    Log.LogError(LogTitle, ex);
                }
            }
        }
        /// <exclude />
        public static object Deserialize(XAttribute attribute, Type type)
        {
            if (type == typeof(string))
            {
                return((string)attribute);
            }
            if (type == typeof(double) || type == typeof(double?))
            {
                return((double)attribute);
            }
            if (type == typeof(float) || type == typeof(float?))
            {
                return((float)attribute);
            }
            if (type == typeof(decimal) || type == typeof(decimal?))
            {
                return((decimal)attribute);
            }
            if (type == typeof(DateTime) || type == typeof(DateTime?))
            {
                return((DateTime)attribute);
            }
            if (type == typeof(DateTimeOffset) || type == typeof(DateTimeOffset?))
            {
                return((DateTimeOffset)attribute);
            }
            if (type == typeof(TimeSpan) || type == typeof(TimeSpan?))
            {
                return((TimeSpan)attribute);
            }

            return(ValueTypeConverter.Convert(attribute.Value, type));
        }
        private static XElement AddData(DataType dataType, CultureInfo cultureInfo)
        {
            XElement datasElement = new XElement("Datas");

            if (cultureInfo != null)
            {
                datasElement.Add(new XAttribute("locale", cultureInfo.Name));
            }

            foreach (XElement addElement in dataType.Dataset)
            {
                IData data = DataFacade.BuildNew(dataType.InterfaceType);

                if (!dataType.InterfaceType.IsInstanceOfType(data))
                {
                    dataType.InterfaceType = GetInstalledVersionOfPendingType(dataType.InterfaceType, data);
                }

                var properties = GetDataTypeProperties(dataType.InterfaceType);

                foreach (XAttribute attribute in addElement.Attributes())
                {
                    string fieldName = attribute.Name.LocalName;
                    if (IsObsoleteField(dataType, fieldName))
                    {
                        continue;
                    }

                    PropertyInfo propertyInfo = properties[fieldName];

                    propertyInfo.SetValue(data, ValueTypeConverter.Convert(attribute.Value, propertyInfo.PropertyType), null);
                }

                ILocalizedControlled localizedControlled = data as ILocalizedControlled;
                if (localizedControlled != null)
                {
                    localizedControlled.SourceCultureName = LocalizationScopeManager.MapByType(dataType.InterfaceType).Name;
                }

                DataFacade.AddNew(data, false, true, false); // Ignore validation, this should have been done in the validation face

                XElement keysElement = new XElement("Keys");

                foreach (PropertyInfo propertyInfo in data.GetKeyProperties())
                {
                    string keyName  = propertyInfo.Name;
                    object keyValue = propertyInfo.GetValue(data, null);

                    XElement keyElement = new XElement("Key",
                                                       new XAttribute("name", keyName),
                                                       new XAttribute("value", keyValue));

                    keysElement.Add(keyElement);
                }

                datasElement.Add(keysElement);
            }

            return(datasElement);
        }
示例#8
0
        public void ConvertFrom_Boolean_ReturnsBool()
        {
            var value  = new Boolean(true);
            var result = ValueTypeConverter.ConvertFrom <bool>(value);

            Assert.True(result);
        }
        /// <exclude />
        public object GetDefaultValue()
        {
            // Initializing the binding
            object value = null;

            try
            {
                var fallbackValueProvider = FallbackValueProvider;

                if (!(fallbackValueProvider is NoValueValueProvider))
                {
                    object defaultValue = fallbackValueProvider.GetValue();

                    if (defaultValue != null)
                    {
                        value = ValueTypeConverter.Convert(defaultValue, this.Type);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.LogWarning(typeof(ParameterProfile).Name, ex);
            }

            if (value == null)
            {
                if (this.Type == typeof(bool))
                {
                    value = false;
                }
            }
            return(value);
        }
示例#10
0
 internal ForeignPropertyInfo(PropertyInfo sourcePropertyInfo, Type targetType, string targetKeyPropertyName, bool allowCascadeDeletes, object nullReferenceValue, Type nullReferenceValueType, bool isNullableString)
     : this(sourcePropertyInfo, targetType, targetKeyPropertyName, allowCascadeDeletes, isNullableString)
 {
     this.NullReferenceValue      = ValueTypeConverter.Convert(nullReferenceValue, sourcePropertyInfo.PropertyType);
     this.NullReferenceValueType  = nullReferenceValueType;
     this.IsNullReferenceValueSet = true;
 }
        /// <exclude />
        public object GetParameterValue(string parameterName, Type targetType)
        {
            Verify.ArgumentNotNullOrEmpty(parameterName, "parameterName");

            if (_parameterList != null)
            {
                return(_parameterList.GetParameter(parameterName, targetType));
            }

            if (_parameterDictionary != null)
            {
                Verify.That(_parameterDictionary.ContainsKey(parameterName), "Parameter '{0}' hasn't been defined.", parameterName);

                object value = _parameterDictionary[parameterName];

                if (value != null && !targetType.IsInstanceOfType(value))
                {
                    return(ValueTypeConverter.Convert(value, targetType));
                }

                return(value);
            }

            throw new InvalidOperationException("Unable to get parameter values. This context has been constructed without parameters.");
        }
示例#12
0
        public bool AddPersistedAttachmentPoint(string treeId, Type interfaceType, object keyValue, ElementAttachingProviderPosition position = ElementAttachingProviderPosition.Top)
        {
            var attachmentPoint = DataFacade.BuildNew <IDataItemTreeAttachmentPoint>();

            attachmentPoint.Id            = Guid.NewGuid();
            attachmentPoint.TreeId        = treeId;
            attachmentPoint.Position      = position.ToString();
            attachmentPoint.InterfaceType = TypeManager.SerializeType(interfaceType);
            attachmentPoint.KeyValue      = ValueTypeConverter.Convert <string>(keyValue);

            bool added = false;

            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                bool exist =
                    (from d in DataFacade.GetData <IDataItemTreeAttachmentPoint>()
                     where d.InterfaceType == attachmentPoint.InterfaceType && d.KeyValue == attachmentPoint.KeyValue && d.TreeId == treeId
                     select d).Any();

                if (!exist)
                {
                    DataFacade.AddNew <IDataItemTreeAttachmentPoint>(attachmentPoint);
                    added = true;
                }

                transactionScope.Complete();
            }

            return(added);
        }
示例#13
0
        private XElement SerializeAction(ActionInformation action)
        {
            var result = new XElement("Action");

            result.Add(new XAttribute(Namespaces.XmlNs + "f", Namespaces.Function10.NamespaceName));

            result.Add(new XAttribute("name", action.ConfigurationElement.Name));

            foreach (var parameter in action.ParameterValues)
            {
                var profile = action.ParameterProfiles.Single(p => p.Name == parameter.Item1);

                object value = parameter.Item2;

                if (value == profile.GetDefaultValue())
                {
                    continue;
                }

                string serializedValue = (string)ValueTypeConverter.Convert(parameter.Item2, typeof(string));

                result.Add(new XElement(Namespaces.Function10 + "param",
                                        new XAttribute("name", parameter.Item1),
                                        new XAttribute("value", serializedValue)));
            }

            return(result);
        }
示例#14
0
        public void ConvertBytesToInteger()
        {
            var t_Converter = new ValueTypeConverter();
            var t_Integer   = t_Converter.ConvertBytesToValueType <int>(new Byte[] { 10, 0, 0, 0 });

            t_Integer.Should().Be(10);
        }
示例#15
0
        internal override void Initialize()
        {
            this.PropertyInfo = this.OwnerNode.InterfaceType.GetPropertiesRecursively().Where(f => f.Name == this.FieldName).SingleOrDefault();

            if (this.PropertyInfo == null)
            {
                AddValidationError("TreeValidationError.Common.MissingProperty", this.OwnerNode.InterfaceType, this.FieldName);
                return;
            }

            try
            {
                this.ConvertedValue = ValueTypeConverter.Convert(this.FieldValue, this.PropertyInfo.PropertyType);
            }
            catch
            {
                AddValidationError("TreeValidationError.FieldFilter.ValueCouldNotBeConverted", this.FieldValue, this.PropertyInfo.PropertyType);
            }

            if ((this.PropertyInfo.PropertyType == typeof(string)) || (this.PropertyInfo.PropertyType == typeof(Guid)))
            {
                if ((this.Operator != FieldFilterNodeOperator.Equal) && (this.Operator != FieldFilterNodeOperator.Inequal))
                {
                    AddValidationError("TreeValidationError.FieldFilter.OperatorNotSupportedForType", this.Operator, this.PropertyInfo.PropertyType);
                }
            }
        }
示例#16
0
        private static void OnDataItemDeleted(object sender, DataEventArgs dataEventArgs)
        {
            Type interfaceType = dataEventArgs.Data.DataSourceId.InterfaceType;

            if (typeof(IPublishControlled).IsAssignableFrom(interfaceType) &&
                !dataEventArgs.Data.DataSourceId.DataScopeIdentifier.Equals(DataScopeIdentifier.Administrated))
            {
                return; // Only remove attachment point if its the admin version of a publishable data item that have been delete
            }

            if (typeof(ILocalizedControlled).IsAssignableFrom(interfaceType) &&
                DataFacade.ExistsInAnyLocale(interfaceType, dataEventArgs.Data.DataSourceId.LocaleScope))
            {
                return; // Data exists in other locales, so do not remove this attachment point
            }

            PropertyInfo propertyInfo = interfaceType.GetKeyProperties()[0];
            string       keyValue     = ValueTypeConverter.Convert <string>(propertyInfo.GetValue(dataEventArgs.Data, null));

            IEnumerable <IDataItemTreeAttachmentPoint> attachmentPoints =
                from d in DataFacade.GetData <IDataItemTreeAttachmentPoint>()
                where
                d.InterfaceType == TypeManager.SerializeType(interfaceType) &&
                d.KeyValue == keyValue
                select d;

            DataFacade.Delete <IDataItemTreeAttachmentPoint>(attachmentPoints);
        }
        private static Dictionary <string, object> BuildTestParameterInput(IEnumerable <ManagedParameterDefinition> parameters)
        {
            Dictionary <string, object> inputValues = new Dictionary <string, object>();

            foreach (ManagedParameterDefinition parameterDefinition in parameters)
            {
                object value = null;
                if (string.IsNullOrEmpty(parameterDefinition.TestValueFunctionMarkup) == false)
                {
                    FunctionRuntimeTreeNode functionNode = (FunctionRuntimeTreeNode)FunctionTreeBuilder.Build(XElement.Parse(parameterDefinition.TestValueFunctionMarkup));
                    value = functionNode.GetValue();
                }
                else
                {
                    if (string.IsNullOrEmpty(parameterDefinition.DefaultValueFunctionMarkup) == false)
                    {
                        FunctionRuntimeTreeNode functionNode = (FunctionRuntimeTreeNode)FunctionTreeBuilder.Build(XElement.Parse(parameterDefinition.DefaultValueFunctionMarkup));
                        value = functionNode.GetValue();
                    }
                }

                if (value != null)
                {
                    if (parameterDefinition.Type.IsAssignableFrom(value.GetType()) == false)
                    {
                        value = ValueTypeConverter.Convert(value, parameterDefinition.Type);
                    }

                    inputValues.Add(parameterDefinition.Name, value);
                }
            }

            return(inputValues);
        }
示例#18
0
        public bool RemovePersistedAttachmentPoint(string treeId, Type interfaceType, object keyValue)
        {
            string serializedInterfaceType = TypeManager.SerializeType(interfaceType);
            string serializedKeyValue      = ValueTypeConverter.Convert <string>(keyValue);

            bool removed = false;

            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                IEnumerable <IDataItemTreeAttachmentPoint> dataItemTreeAttachmentPoints =
                    (from d in DataFacade.GetData <IDataItemTreeAttachmentPoint>()
                     where d.InterfaceType == serializedInterfaceType && d.KeyValue == serializedKeyValue && d.TreeId == treeId
                     select d).Evaluate();

                if (dataItemTreeAttachmentPoints.Any())
                {
                    DataFacade.Delete <IDataItemTreeAttachmentPoint>(dataItemTreeAttachmentPoints);
                    removed = true;
                }

                transactionScope.Complete();
            }

            return(removed);
        }
        private void LoadParameterValues()
        {
            _parameterValues = new List <Tuple <string, object> >();

            foreach (XElement parameterNode in _fieldXml.Elements())
            {
                string parameterName = (string)parameterNode.Attribute("name");

                var parameterProfile = _parameterProfiles.FirstOrDefault(p => p.Name == parameterName);

                Verify.IsNotNull(parameterProfile, "Parameter '{0}' hasn't been defined".FormatWith(parameterName));

                // TODO: Support for <f:paramelement ... />

                string stringValue = (string)parameterNode.Attribute("value");
                object value       = ValueTypeConverter.Convert(stringValue, parameterProfile.Type);

                _parameterValues.Add(new Tuple <string, object>(parameterName, value));
            }

            var parametersWithDefaultValues = _parameterProfiles.Where(p => !_parameterValues.Any(pv => pv.Item1 == p.Name));

            foreach (var parameterProfile in parametersWithDefaultValues)
            {
                var defaultValue = parameterProfile.GetDefaultValue();

                _parameterValues.Add(new Tuple <string, object>(parameterProfile.Name, defaultValue));
            }
        }
        private XElement SerializeFormElement()
        {
            var result = new XElement("Field");

            result.Add(new XAttribute(Namespaces.XmlNs + "f", Namespaces.Function10.NamespaceName));

            result.Add(new XAttribute("name", (string)_fieldXml.Attribute("name")));

            foreach (var parameter in _parameterValues)
            {
                var profile = _parameterProfiles.Single(p => p.Name == parameter.Item1);

                object value = parameter.Item2;

                if (value == profile.GetDefaultValue())
                {
                    continue;
                }

                string serializedValue = (string)ValueTypeConverter.Convert(parameter.Item2, typeof(string));

                result.Add(new XElement(Namespaces.Function10 + "param",
                                        new XAttribute("name", parameter.Item1),
                                        serializedValue != null ? new XAttribute("value", serializedValue) : null));
            }

            return(result);
        }
示例#21
0
        public Expression <Func <TField, bool> > GetPredicate(Guid pageId, RelativeRoute relativeRoute)
        {
            var dataPredicate = _dataTypeMapper.GetPredicate(pageId, relativeRoute);

            if (dataPredicate == null)
            {
                return(null);
            }


            var data = DataFacade.GetData <TDataType>(dataPredicate).Evaluate();

            if (data.Count == 0)
            {
                return(null);
            }

            if (data.Count > 1)
            {
                throw new DataUrlCollisionException(typeof(TDataType), relativeRoute);
            }

            var keyObject = data.First().GetUniqueKey();
            var key       = ValueTypeConverter.Convert <TField>(keyObject);

            var paramExpr = Expression.Parameter(typeof(TField));
            var body      = Expression.Equal(paramExpr, Expression.Constant(key));

            return(Expression.Lambda <Func <TField, bool> >(body, paramExpr));
        }
示例#22
0
        private void LoadParameterValues(ActionInformation action)
        {
            var parameterValues = new List <Tuple <string, object> >();

            if (action.Element != null)
            {
                foreach (XElement parameterNode in action.Element.Elements())
                {
                    string parameterName = (string)parameterNode.Attribute("name");

                    var parameterProfile = action.ParameterProfiles.FirstOrDefault(p => p.Name == parameterName);

                    Verify.IsNotNull(parameterProfile, "There's no parameter named '{0}' on the function representing action '{1}'", parameterName, action.ConfigurationElement.Name);

                    // TODO: Support for <f:paramelement ... />

                    string stringValue = (string)parameterNode.Attribute("value");
                    object value       = ValueTypeConverter.Convert(stringValue, parameterProfile.Type);

                    parameterValues.Add(new Tuple <string, object>(parameterName, value));
                }
            }

            action.ParameterValues = parameterValues;
        }
示例#23
0
        private void PackPageTree(PackageCreator pc, Guid pageId, bool isRoot = false)
        {
            var page = PageManager.GetPageById(pageId, true);

            if (page == null)             // Page does not exists in current locale
            {
                return;
            }

            foreach (var childPageId in PageManager.GetChildrenIDs(pageId))
            {
                if (pc.ExcludedIds.Contains(childPageId))
                {
                    continue;
                }

                PackPageTree(pc, childPageId);
            }

            foreach (var dataScopeIdentifier in DataFacade.GetSupportedDataScopes(typeof(IPage)))
            {
                using (new DataScope(dataScopeIdentifier))
                {
                    var pageinScope = PageManager.GetPageById(pageId, true);
                    if (pageinScope != null)
                    {
                        pc.AddData(pageinScope);
                        pc.AddData <IPagePlaceholderContent>(dataScopeIdentifier, d => d.PageId == pageId);
                    }
                }
            }

            if (isRoot)
            {
                using (new DataScope(DataScopeIdentifier.Public))
                {
                    var pageStructure = DataFacade.BuildNew <IPageStructure>();
                    pageStructure.Id            = pageId;
                    pageStructure.ParentId      = Guid.Empty;
                    pageStructure.LocalOrdering = PageManager.GetLocalOrdering(pageId);
                    pc.AddData(pageStructure);
                }
            }
            else
            {
                pc.AddData <IPageStructure>(d => d.Id == pageId);
            }

            if (IncludeData)
            {
                pc.AddData <IDataItemTreeAttachmentPoint>(d => d.KeyValue == ValueTypeConverter.Convert <string>(pageId));
                pc.AddData <IPageFolderDefinition>(d => d.PageId == pageId);

                foreach (Type folderType in page.GetDefinedFolderTypes())
                {
                    pc.AddData(folderType, d => (d as IPageRelatedData).PageId == pageId);
                }
            }
        }
 public void ConvertFromString_GivenGuid_ShouldConvert()
 {
     var converter = new ValueTypeConverter<Guid>();
     var guid = (Guid)converter.ConvertFromString(GuidString);
     guid
         .Should()
         .Be(new Guid(GuidString));
 }
示例#25
0
        public void ConvertIntegerToBytes()
        {
            var t_Converter = new ValueTypeConverter();
            var t_Bytes     = t_Converter.ConvertValueTypeToBytes(10);

            t_Bytes.Length.Should().Be(4, "We converted an integer.");
            t_Bytes[0].Should().Be(10);
        }
示例#26
0
        /// <exclude />
        public Dictionary <string, string> BindingsToObject(Dictionary <string, object> bindings, IData dataObject)
        {
            var errorMessages = new Dictionary <string, string>();

            foreach (var fieldDescriptor in _dataTypeDescriptor.Fields)
            {
                if (_readOnlyFields.Contains(fieldDescriptor.Name))
                {
                    continue;
                }

                var bindingName = GetBindingName(fieldDescriptor);

                if (!bindings.ContainsKey(bindingName))
                {
                    Verify.That(fieldDescriptor.IsNullable, "Missing value for field '{0}'", fieldDescriptor.Name);
                    continue;
                }

                var propertyInfo = dataObject.GetType().GetProperty(fieldDescriptor.Name);

                if (propertyInfo.CanWrite)
                {
                    var newValue = bindings[bindingName];

                    if (newValue is string && (newValue as string) == "" && IsNullableStringReference(propertyInfo))
                    {
                        newValue = null;
                    }

                    try
                    {
                        newValue = ValueTypeConverter.Convert(newValue, propertyInfo.PropertyType);

                        propertyInfo.GetSetMethod().Invoke(dataObject, new[] { newValue });
                    }
                    catch (Exception ex)
                    {
                        errorMessages.Add(bindingName, ex.Message);
                    }
                }
            }

            if (_showPublicationStatusSelector &&
                _dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled)))
            {
                var publishControlled = dataObject as IPublishControlled;

                publishControlled.PublicationStatus = (string)bindings[PublicationStatusBindingName];
            }

            if (errorMessages.Count > 0)
            {
                return(errorMessages);
            }

            return(null);
        }
        public void ConvertToString_GivenGuid_ShouldConvert()
        {
            var converter = new ValueTypeConverter<Guid>();
            var guidString = converter.ConvertToString(new Guid(GuidString));

            guidString
                .Should()
                .Be(GuidString);
        }
		public void SerializeWithConverter()
		{
			var serializer = new NewtonsoftJSONSerializer();

			var p = new Person { Name = "Json", Age = 23 };

			var converter = new ValueTypeConverter();
            Assert.AreEqual("{\"Age\":23}", serializer.Serialize(p, converter));
		}
        public void ConvertToString_GivenGuid_ShouldConvert()
        {
            var converter  = new ValueTypeConverter <Guid>();
            var guidString = converter.ConvertToString(new Guid(GuidString));

            guidString
            .Should()
            .Be(GuidString);
        }
        public void ConvertFromString_GivenGuid_ShouldConvert()
        {
            var converter = new ValueTypeConverter <Guid>();
            var guid      = (Guid)converter.ConvertFromString(GuidString);

            guid
            .Should()
            .Be(new Guid(GuidString));
        }
        /// <exclude />
        public IEnumerable <IData> GetDataList()
        {
            Type type = TypeManager.GetType(this.Type);

            object id = ValueTypeConverter.Convert(this.Id, type.GetKeyProperties()[0].PropertyType);

            var datas = DataFacade.TryGetDataVersionsByUniqueKey(type, id);

            return(datas);
        }
        /// <exclude />
        public IData GetData()
        {
            Type type = TypeManager.GetType(this.Type);

            object id = ValueTypeConverter.Convert(this.Id, type.GetKeyProperties()[0].PropertyType);

            IData data = DataFacade.TryGetDataByUniqueKey(type, id);

            return(data);
        }
        public void Should_match_a_string_to_an_integer()
        {
            Value<int> left = Conditionals.Constant(42);
            Value<string> right = Conditionals.Constant("42");

            var converter = new ValueTypeConverter<int, string>(right);

            var comparator = new ValueEqualComparator<int>();

            bool equal = comparator.Compare(left, converter);

            Assert.IsTrue(equal);
        }
示例#34
0
        public void Should_match_a_string_to_an_integer()
        {
            Value<int> left = Conditional.Constant(42);
            Value<string> right = Conditional.Constant("42");

            var converter = new ValueTypeConverter<int, string>(right);

            var comparator = new ValueEqualComparator<int>();

            int xx = 0;
            int yy = 0;

            comparator.Match(left, converter, (x, y) =>
                {
                    xx = x;
                    yy = y;
                });

            Assert.AreEqual(42, xx);
            Assert.AreEqual(42, yy);
        }