本文整理汇总了C#中PropDef.AddPropRule方法的典型用法代码示例。如果您正苦于以下问题:C# PropDef.AddPropRule方法的具体用法?C# PropDef.AddPropRule怎么用?C# PropDef.AddPropRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropDef
的用法示例。
在下文中一共展示了PropDef.AddPropRule方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: init
public void init()
{
mBOPropCol = new BOPropCol();
mPropDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadWrite, null);
mBOPropCol.Add(mPropDef.CreateBOProp(false));
mPropDef = new PropDef("Prop2", typeof(string), PropReadWriteRule.ReadWrite, null);
mPropDef.AddPropRule(new PropRuleString(mPropDef.PropertyName, "Test Message", 1, 10, null));
mBOPropCol.Add(mPropDef.CreateBOProp(false));
BOPropCol anotherPropCol = new BOPropCol();
PropDef anotherPropDef =
new PropDef("TestAddPropCol", typeof(string), PropReadWriteRule.ReadWrite, null);
anotherPropCol.Add(anotherPropDef.CreateBOProp(false));
mBOPropCol.Add(anotherPropCol);
}
示例2: Test_ValidateProp_WhenPropNotValid_IsValidFalse
public void Test_ValidateProp_WhenPropNotValid_IsValidFalse()
{
//---------------Set up test pack-------------------
//Test compulsory with no default set
PropDef lPropDefWithRules = new PropDef("PropNameWithRules", "System", "String",
PropReadWriteRule.ReadWrite, null, null, true, false);
lPropDefWithRules.AddPropRule(new PropRuleString(lPropDefWithRules.PropertyName, "", -1, -1, null));
IBOProp lBOProp = lPropDefWithRules.CreateBOProp(true);
//---------------Assert Precondition----------------
Assert.IsTrue(lBOProp.IsValid);
Assert.AreEqual("", lBOProp.InvalidReason);
//---------------Execute Test ----------------------
lBOProp.Validate();
//---------------Test Result -----------------------
Assert.IsFalse(lBOProp.IsValid);
StringAssert.Contains("'Prop Name With Rules' is a compulsory field and has no value.", lBOProp.InvalidReason);
}
示例3: TestPropBrokenRuleRestore
public void TestPropBrokenRuleRestore()
{
//Test compulsory with no default set
PropDef lPropDefWithRules = new PropDef("PropNameWithRules", typeof(string),
PropReadWriteRule.ReadWrite, null);
lPropDefWithRules.AddPropRule( new PropRuleString(lPropDefWithRules.PropertyName, "", 50, 51, null));
IBOProp lBOProp = lPropDefWithRules.CreateBOProp(true);
Assert.IsTrue(lBOProp.IsValid);
try
{
lBOProp.Value = "New Value";
}
catch (InvalidPropertyValueException)
{
//do nothing
}
Assert.IsFalse(lBOProp.IsValid);
lBOProp.RestorePropValue();
Assert.IsTrue(lBOProp.IsValid);
}
示例4: Test_RestoreValidPropToInvalidState
public void Test_RestoreValidPropToInvalidState()
{
//---------------Set up test pack-------------------
//Test compulsory with no default set
PropDef lPropDefWithRules = new PropDef("PropNameWithRules", "System", "String",
PropReadWriteRule.ReadWrite, null, null, true, false);
lPropDefWithRules.AddPropRule(new PropRuleString(lPropDefWithRules.PropertyName, "", -1, -1, null));
IBOProp lBOProp = lPropDefWithRules.CreateBOProp(true);
//Do validate
lBOProp.Validate();
lBOProp.Value = "New Value";
//---------------Assert Precondition----------------
Assert.IsTrue(lBOProp.IsValid);
Assert.IsFalse(lBOProp.InvalidReason.Length > 0);
//---------------Execute Test ----------------------
lBOProp.RestorePropValue();
//---------------Test Result -----------------------
Assert.IsFalse(lBOProp.IsValid);
Assert.IsTrue(lBOProp.InvalidReason.Length > 0);
}
示例5: Test_AddPropRule_Null
public void Test_AddPropRule_Null()
{
//---------------Set up test pack-------------------
IPropDef propDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadOnly, null);
//---------------Assert Precondition----------------
Assert.AreEqual(0, propDef.PropRules.Count);
//---------------Execute Test ----------------------
try
{
propDef.AddPropRule(null);
Assert.Fail("expected Err");
}
//---------------Test Result -----------------------
catch (HabaneroApplicationException ex)
{
StringAssert.Contains("You cannot add a null property rule to a property def", ex.Message);
}
}
示例6: Test_IsValueValid_TwoPropRule_InValidValue_FirstRulePass_FirstRuleFail
public void Test_IsValueValid_TwoPropRule_InValidValue_FirstRulePass_FirstRuleFail()
{
//---------------Set up test pack-------------------
PropDef propDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadOnly, null);
propDef.AddPropRule(new PropRuleString("StringRule", "Rule 1", 1, 3, ""));
propDef.AddPropRule(new PropRuleString("StringRule", "Rule 2", 3, 10, ""));
//---------------Assert Precondition----------------
Assert.AreEqual(2, propDef.PropRules.Count);
//---------------Execute Test ----------------------
string errMsg = "";
bool valid = propDef.IsValueValid("Long String", ref errMsg);
//---------------Test Result -----------------------
Assert.IsFalse(valid);
StringAssert.Contains("'Long String' for property 'Prop Name' is not valid for the rule 'StringRule'", errMsg);
StringAssert.Contains("Rule 1", errMsg);
}
示例7: Test_IsValueValid_TwoPropRule_ValidValue
public void Test_IsValueValid_TwoPropRule_ValidValue()
{
//---------------Set up test pack-------------------
PropDef propDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadOnly, null);
propDef.AddPropRule(new PropRuleString("StringRule", "Rule 1", 1, 3, ""));
propDef.AddPropRule(new PropRuleString("StringRule", "Rule 2", 3, 10, ""));
//---------------Assert Precondition----------------
Assert.AreEqual(2, propDef.PropRules.Count);
//---------------Execute Test ----------------------
string errMsg = "";
bool valid = propDef.IsValueValid("ABC", ref errMsg);
//---------------Test Result -----------------------
Assert.IsTrue(valid);
Assert.AreEqual("", errMsg);
}
示例8: Test_AddTwoPropRules
public void Test_AddTwoPropRules()
{
//---------------Set up test pack-------------------
IPropDef propDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadOnly, null);
//---------------Assert Precondition----------------
Assert.AreEqual(0, propDef.PropRules.Count);
//---------------Execute Test ----------------------
PropRuleString rule = new PropRuleString("StringRule", "My Message", 1, 3, "");
propDef.AddPropRule(rule);
propDef.AddPropRule(new PropRuleString("StringRule", "My Message", 1, 3, ""));
//---------------Test Result -----------------------
Assert.AreEqual(2, propDef.PropRules.Count);
}
示例9: CreateBOPropDef
protected static PropDefCol CreateBOPropDef()
{
PropDefCol lPropDefCol = new PropDefCol();
PropDef propDef = new PropDef("Surname", typeof (String), PropReadWriteRule.ReadWrite, null);
propDef.AddPropRule( new PropRuleString("ContactPerson-" + propDef.PropertyName, "", 2, 50, null));
lPropDefCol.Add(propDef);
propDef = new PropDef("FirstName", typeof (String), PropReadWriteRule.ReadWrite, null);
lPropDefCol.Add(propDef);
propDef = new PropDef("DateOfBirth", typeof (DateTime), PropReadWriteRule.WriteOnce, null);
lPropDefCol.Add(propDef);
//Create concurrency control properties
propDef = new PropDef("DateLastUpdated", typeof (DateTime), PropReadWriteRule.ReadWrite, DateTime.Now);
lPropDefCol.Add(propDef);
propDef = new PropDef("UserLastUpdated", typeof (string), PropReadWriteRule.ReadWrite, null);
lPropDefCol.Add(propDef);
propDef = new PropDef("MachineLastUpdated", typeof (string), PropReadWriteRule.ReadWrite, null);
lPropDefCol.Add(propDef);
propDef = new PropDef("VersionNumber", typeof (int), PropReadWriteRule.ReadWrite, 1);
lPropDefCol.Add(propDef);
propDef = new PropDef(PK1_PROP1_NAME, typeof (string), PropReadWriteRule.ReadWrite, "PK1_Prop1", null);
lPropDefCol.Add(propDef);
propDef = new PropDef(PK1_PROP2_NAME, typeof (string), PropReadWriteRule.ReadWrite, "PK1_Prop2", null);
lPropDefCol.Add(propDef);
return lPropDefCol;
}
示例10: MapProperty
/// <summary>
/// Will attempt to map a PropertyInfo to an IPropDef.
/// If it cannot be mapped then will return null.
/// </summary>
/// <returns></returns>
public IPropDef MapProperty()
{
if (MustMapProperty)
{
var propertyType = this.PropertyWrapper.UnderlyingPropertyType;
string displayName = "";
if (this.PropertyWrapper.HasDisplayNameAttribute)
{
displayName = this.PropertyWrapper.GetAttribute<AutoMapDisplayNameAttribute>().DisplayName;
}
var propDef = new PropDef(this.PropertyWrapper.Name, propertyType, PropReadWriteRule.ReadWrite, null, null, false, false, int.MaxValue, displayName, "")
{
Compulsory = this.PropertyWrapper.HasCompulsoryAttribute
};
if (this.PropertyWrapper.HasDefaultAttribute)
{
propDef.DefaultValueString =
this.PropertyWrapper.GetAttribute<AutoMapDefaultAttribute>().DefaultValue;
}
if (this.PropertyWrapper.HasReadWriteRuleAttribute)
{
propDef.ReadWriteRule =
this.PropertyWrapper.GetAttribute<AutoMapReadWriteRuleAttribute>().ReadWriteRule;
}
if (this.PropertyWrapper.HasIntPropRuleAttribute)
{
var intPropRule = CreateIntPropRule();
propDef.AddPropRule(intPropRule);
}else if (this.PropertyWrapper.HasShortPropRuleAttribute)
{
var shortPropRule = CreateShortPropRule();
propDef.AddPropRule(shortPropRule);
} else if (this.PropertyWrapper.HasDateTimeRuleAttribute)
{
var propRuleDate = CreateDateTimePropRule();
propDef.AddPropRule(propRuleDate);
} else if (this.PropertyWrapper.HasDateTimeStringRuleAttribute)
{
var propRuleDate = CreateDateTimeStringPropRule();
propDef.AddPropRule(propRuleDate);
}
if (this.PropertyWrapper.HasStringLengthRuleAttribute)
{
var stringPropRule = CreateStringLengthPropRule();
propDef.AddPropRule(stringPropRule);
} else if (this.PropertyWrapper.HasStringPatternMatchRuleAttribute)
{
var stringPropRule = CreatePatternMatchPropRule();
propDef.AddPropRule(stringPropRule);
}
if (this.PropertyWrapper.HasKeepValuePrivateAttribute)
{
propDef.KeepValuePrivate = true;
}
if (this.PropertyWrapper.HasAttribute<AutoMapFieldNameAttribute>())
{
var autoMapFieldNameAttribute = this.PropertyWrapper.GetAttribute<AutoMapFieldNameAttribute>();
propDef.DatabaseFieldName = autoMapFieldNameAttribute.FieldName;
}
propDef.AutoIncrementing = this.PropertyWrapper.HasAutoIncrementingAttribute;
return propDef;
}
return null;
}
示例11: CreateBOPropDef
protected static PropDefCol CreateBOPropDef()
{
PropDefCol lPropDefCol = new PropDefCol();
PropDef propDef = new PropDef("Surname", typeof(String), PropReadWriteRule.ReadWrite, null);
propDef.AddPropRule(new PropRuleString("ContactPerson-" + propDef.PropertyName, "", 2, 50, null));
lPropDefCol.Add(propDef);
propDef = new PropDef("FirstName", typeof(String), PropReadWriteRule.ReadWrite, null);
lPropDefCol.Add(propDef);
propDef = new PropDef("DateOfBirth", typeof(DateTime), PropReadWriteRule.WriteOnce, null);
lPropDefCol.Add(propDef);
return lPropDefCol;
}
示例12: TestDirtyXml
public void TestDirtyXml()
{
mProp = mBOPropCol["Prop2"];
mProp.InitialiseProp("Prop2-Orig");
mProp.Value = "Prop2-New";
Assert.IsTrue(mProp.IsDirty);
mProp = mBOPropCol["PropName"];
mProp.InitialiseProp("Propn-Orig");
mProp.Value = "PropName-new";
Assert.IsTrue(mProp.IsDirty);
mPropDef = new PropDef("Prop3", typeof(string), PropReadWriteRule.ReadOnly, null);
mPropDef.AddPropRule( new PropRuleString(mPropDef.PropertyName, "Test", 1, 40, null));
mBOPropCol.Add(mPropDef.CreateBOProp(false));
mProp = mBOPropCol["Prop3"];
mProp.InitialiseProp("Prop3-new");
Assert.IsFalse(mProp.IsDirty);
const string dirtyXml = "<Properties><Prop2><PreviousValue>Prop2-Orig</PreviousValue><NewValue>Prop2-New</NewValue></Prop2><PropName><PreviousValue>Propn-Orig</PreviousValue><NewValue>PropName-new</NewValue></PropName></Properties>";
Assert.AreEqual(dirtyXml, mBOPropCol.DirtyXml);
}
示例13: CreateBOPropDef
private static PropDefCol CreateBOPropDef()
{
PropDefCol lPropDefCol = new PropDefCol();
PropDef propDef =
new PropDef("Surname", "System", "String", PropReadWriteRule.ReadWrite, "Surname_field", null, true, false);
propDef.AddPropRule(new PropRuleString("ContactPerson-" + propDef.PropertyName, "", 2, 50, null));
lPropDefCol.Add(propDef);
propDef = new PropDef("FirstName", typeof(String), PropReadWriteRule.ReadWrite, "FirstName_field", null);
lPropDefCol.Add(propDef);
propDef = new PropDef("DateOfBirth", typeof (DateTime), PropReadWriteRule.WriteOnce, null);
lPropDefCol.Add(propDef);
//Create concurrency control properties
propDef = new PropDef("DateLastUpdated", typeof(DateTime), PropReadWriteRule.ReadWrite, DateTime.Now);
lPropDefCol.Add(propDef);
propDef = new PropDef("UserLastUpdated", typeof(string), PropReadWriteRule.ReadWrite, null);
lPropDefCol.Add(propDef);
propDef = new PropDef("MachineLastUpdated", typeof(string), PropReadWriteRule.ReadWrite, null);
lPropDefCol.Add(propDef);
propDef = new PropDef("VersionNumber", typeof(int), PropReadWriteRule.ReadWrite, 1);
lPropDefCol.Add(propDef);
propDef = new PropDef("PK2Prop1", typeof(string), PropReadWriteRule.ReadWrite, "PK2_Prop1", null);
lPropDefCol.Add(propDef);
propDef = new PropDef("PK2Prop2", typeof(string), PropReadWriteRule.ReadWrite, "PK2_Prop2", null);
lPropDefCol.Add(propDef);
propDef = new PropDef("PK3Prop", typeof (string), PropReadWriteRule.WriteNew, "PK3_Prop", null);
lPropDefCol.Add(propDef);
lPropDefCol.Add("ContactPersonID", typeof (Guid), PropReadWriteRule.WriteOnce, null);
return lPropDefCol;
}