Exemplo n.º 1
0
        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);
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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.");
        }
Exemplo n.º 6
0
        public void SetTargetTypeNamePropertyToEmptyString()
        {
            TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime));

            Assert.Throws <ArgumentNullException>(() => tsv.TargetTypeName = "  ");
        }
Exemplo n.º 7
0
        public void HasTargetType()
        {
            TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime));

            Assert.IsTrue(tsv.HasTargetType);
        }