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 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 HasTargetType() { TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime)); Assert.IsTrue(tsv.HasTargetType); }
/// <summary> /// Resolve the target type of the passed <see cref="TypedStringValue"/>. /// </summary> /// <param name="value">The <see cref="TypedStringValue"/> who's target type is to be resolved</param> /// <returns>The resolved target type, if any. <see lang="null" /> otherwise.</returns> protected virtual Type ResolveTargetType(TypedStringValue value) { if (value.HasTargetType) { return value.TargetType; } return value.ResolveTargetType(); }
public void SetTargetTypeNamePropertyToEmptyString() { TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime)); tsv.TargetTypeName = " "; }
public void SetTargetTypePropertyToNullType() { TypedStringValue tsv = new TypedStringValue(string.Empty, typeof (DateTime)); tsv.TargetType = null; }
public void SetTargetTypeNamePropertyToEmptyString() { TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime)); Assert.Throws<ArgumentNullException>(() => tsv.TargetTypeName = " "); }
public void SetTargetTypePropertyToNullType() { TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime)); tsv.TargetType = null; }
/// <summary> /// Resolve the target type of the passed <see cref="TypedStringValue"/>. /// </summary> /// <param name="value">The <see cref="TypedStringValue"/> who's target type is to be resolved</param> /// <returns>The resolved target type, if any. <see lang="null" /> otherwise.</returns> protected virtual Type ResolveTargetType(TypedStringValue value) { if (value.HasTargetType) { return value.TargetType; } else { return null; } }
private AbstractObjectDefinition ParseAttributeSource(XmlElement element, ParserContext parserContext) { XmlNodeList methods = element.SelectNodes("*[local-name()='method' and namespace-uri()='" + element.NamespaceURI + "']"); ManagedDictionary transactionAttributeMap = new ManagedDictionary(); foreach (XmlElement methodElement in methods) { string name = GetAttributeValue(methodElement, "name"); TypedStringValue nameHolder = new TypedStringValue(name); RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute(); string propagation = GetAttributeValue(methodElement, PROPAGATION); string isolation = GetAttributeValue(methodElement, ISOLATION); string timeout = GetAttributeValue(methodElement, TIMEOUT); string readOnly = GetAttributeValue(methodElement, READ_ONLY); if (StringUtils.HasText(propagation)) { attribute.PropagationBehavior = (TransactionPropagation) Enum.Parse(typeof (TransactionPropagation), propagation, true); } if (StringUtils.HasText(isolation)) { attribute.TransactionIsolationLevel = (IsolationLevel) Enum.Parse(typeof (IsolationLevel), isolation, true); } if (StringUtils.HasText(timeout)) { try { attribute.TransactionTimeout = Int32.Parse(timeout); } catch (FormatException ex) { parserContext.ReaderContext.ReportException(methodElement,"tx advice","timeout must be an integer value: [" + timeout + "]", ex); } } if (StringUtils.HasText(readOnly)) { attribute.ReadOnly = Boolean.Parse(GetAttributeValue(methodElement, READ_ONLY)); } IList rollbackRules = new LinkedList(); if (methodElement.HasAttribute(ROLLBACK_FOR)) { string rollbackForValue = GetAttributeValue(methodElement, ROLLBACK_FOR); AddRollbackRuleAttributesTo(rollbackRules, rollbackForValue); } if (methodElement.HasAttribute(NO_ROLLBACK_FOR)) { string noRollbackForValue = GetAttributeValue(methodElement, NO_ROLLBACK_FOR); AddNoRollbackRuleAttributesTo(rollbackRules, noRollbackForValue); } attribute.RollbackRules = rollbackRules; transactionAttributeMap[nameHolder] = attribute; } ObjectDefinitionBuilder builder = parserContext .ParserHelper .CreateRootObjectDefinitionBuilder(typeof (NameMatchTransactionAttributeSource)); builder.AddPropertyValue(NAME_MAP, transactionAttributeMap); return builder.ObjectDefinition; }
public void SetTargetTypeNamePropertyToEmptyString() { TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime)); Assert.Throws <ArgumentNullException>(() => tsv.TargetTypeName = " "); }