Tortuga-TestMonkey
Tortuga-TestMonkey copied to clipboard
Old Helper Functions
System.Collections.Generic.Dictionary<string, object> GetValues(@Class.FullName objectUnderTest)
{
var result = new System.Collections.Generic.Dictionary<string, object>();
@{
foreach (var property in Class.Properties.Where(p => !p.IsIndexer && p.CanRead))
{
<text>result["@property.Name"] = [email protected];</text>
}
}
return result;
}
System.Collections.Generic.List<string> GetDiffs(System.Collections.Generic.Dictionary<string, object> originalValues, @Class.FullName objectUnderTest)
{
return GetDiffs(originalValues, GetValues(objectUnderTest));
}
System.Collections.Generic.List<string> GetDiffs(System.Collections.Generic.Dictionary<string, object> originalValues, System.Collections.Generic.Dictionary<string, object> newValues)
{
var result = new System.Collections.Generic.List<string>();
foreach(var item in originalValues)
{
if (!System.Object.Equals(item.Value, newValues[item.Key]))
result.Add(item.Key);
}
return result;
}
public @Class.FullName GetObject(int version)
{
var objectUnderTest = CreateObject();
SetValues(objectUnderTest, version);
return objectUnderTest;
}
public void SetValues(@Class.FullName objectUnderTest, int version)
{
@{
foreach (var property in Class.Properties.Where(p => !p.IsIndexer && p.CanRead && p.CanWrite && p.Type.HasCommonValues))
{
@{ foreach (var property in Class.Properties.Where(p => !p.IsIndexer && p.CanRead && p.CanWrite && p.Type.HasCommonValues)) {
<text>
//implement this to provide a custom list of known good values
partial void @("Helper_SetOverride_" + property.Name)(@Class.FullName objectUnderTest, int version, ref bool wasSet);
void @("Helper_Set_" + property.Name) (@Class.FullName objectUnderTest, int version)
{
var wasSet = false;
@("Helper_SetOverride_" + property.Name)(objectUnderTest, version, ref wasSet);
if (wasSet)
return;
var successCount = 0;
</text>
foreach (var testValue in property.Type.CommonValues)
{
<text>
try
{
[email protected] = @testValue;
successCount += 1;
if (successCount == version)
return;
}
catch (System.ArgumentException)
{
//Try the next value
}
</text>
}
<text>
if (successCount == 0)
@Assert.Inconclusive("\"Could not complete test, unable to set the property.\"")
else
@("Helper_Set_" + property.Name)(objectUnderTest, version-successCount);
}
</text>
}
}
}