public void ResolveTargetType() { TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime).FullName); Assert.IsFalse(tsv.HasTargetType); Assert.AreEqual(typeof(DateTime), tsv.ResolveTargetType()); Assert.IsTrue(tsv.HasTargetType); }
/// <summary> /// Resolves the given value taken from an object definition according to its type /// </summary> /// <param name="value">the value to resolve</param> /// <returns>the resolved value</returns> protected virtual object ResolveValue(object value) { if (value is IObjectDefinition) { VisitObjectDefinition((IObjectDefinition)value); } else if (value is ObjectDefinitionHolder) { VisitObjectDefinition(((ObjectDefinitionHolder)value).ObjectDefinition); } else if (value is RuntimeObjectReference) { RuntimeObjectReference ror = (RuntimeObjectReference)value; //name has to be of string type. string newObjectName = ResolveStringValue(ror.ObjectName); if (!newObjectName.Equals(ror.ObjectName)) { return(new RuntimeObjectReference(newObjectName)); } } else if (value is ManagedList) { VisitManagedList((ManagedList)value); } else if (value is ManagedSet) { VisitManagedSet((ManagedSet)value); } else if (value is ManagedDictionary) { VisitManagedDictionary((ManagedDictionary)value); } else if (value is NameValueCollection) { VisitNameValueCollection((NameValueCollection)value); } else if (value is TypedStringValue) { TypedStringValue typedStringValue = (TypedStringValue)value; String stringValue = typedStringValue.Value; if (stringValue != null) { String visitedString = ResolveStringValue(stringValue); typedStringValue.Value = visitedString; } } else if (value is string) { return(ResolveStringValue((string)value)); } else if (value is ExpressionHolder) { ExpressionHolder holder = (ExpressionHolder)value; string newExpressionString = ResolveStringValue(holder.ExpressionString); return(new ExpressionHolder(newExpressionString)); } return(value); }
public void HasTargetTypeReturnsFalseWhenTargetTypeNotResolved() { TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime).FullName); Assert.IsFalse(tsv.HasTargetType); tsv = new TypedStringValue(string.Empty, typeof(DateTime)); Assert.IsTrue(tsv.HasTargetType); tsv.TargetTypeName = typeof(DateTime).FullName; Assert.IsFalse(tsv.HasTargetType); }
public void Instantiation() { string expectedNow = DateTime.Now.ToShortDateString(); TypedStringValue tsv = new TypedStringValue(expectedNow, typeof(DateTime)); Assert.AreEqual(expectedNow, tsv.Value); Assert.AreEqual(typeof(DateTime), tsv.TargetType); tsv = new TypedStringValue(expectedNow); Assert.AreEqual(expectedNow, tsv.Value); tsv = new TypedStringValue(expectedNow, typeof(DateTime).FullName); Assert.AreEqual(expectedNow, tsv.Value); Assert.AreEqual(typeof(DateTime).FullName, tsv.TargetTypeName); }
public void Serialization() { TypedStringValue value = new TypedStringValue(); Type expectedType = typeof(string); value.TargetType = expectedType; const string expectedValue = "rilo-kiley"; value.Value = expectedValue; object foo = SerializationTestUtils.SerializeAndDeserialize(value); Assert.IsNotNull(foo, "Serialization roundtrip must never result in null."); TypedStringValue deser = foo as TypedStringValue; Assert.IsNotNull(deser, "Serialization roundtrip yielded the wrong Type of object."); Assert.AreEqual(expectedType, deser.TargetType, "Serialization roundtrip yielded the wrong TargetType."); Assert.AreEqual(expectedValue, deser.Value, "Serialization roundtrip yielded the wrong Value."); }
public void SetTargetTypeNamePropertyToEmptyString() { TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime)); Assert.Throws <ArgumentNullException>(() => tsv.TargetTypeName = " "); }
public void HasTargetType() { TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime)); Assert.IsTrue(tsv.HasTargetType); }