public CompareColumnResult GoGoCompareColumnAction(object target, string tableValue) { if (tableValue == ConstantStrings.IgnoreCell) { return(new CompareColumnResult()); } var compareResult = new CompareColumnResult(); var expectedValue = Translator.Translate(_info, tableValue); expectedValue = SetTranslator.Translate(_info, target, expectedValue); var actualValue = GetActual(target); compareResult.ExpectedPrint = ToStringHelper.SafeToString(expectedValue); compareResult.ActualPrint = ToStringHelper.SafeToString(actualValue); // Refactor to be blah = blah try { Assert.AreEqual(TypeConversion.SafeConvert(expectedValue, actualValue), actualValue); } catch (Exception) { compareResult.IsError = true; compareResult.ErrorMessage = "Error on Property " + _info.Name + ", Expected '" + compareResult.ExpectedPrint + "', Actual '" + compareResult.ActualPrint + "'"; } return(compareResult); }
public void GoGoCreateColumnAction(object target, string tableValue) { if (tableValue == ConstantStrings.IgnoreCell) { return; } var value = Translator.Translate(_info, tableValue); value = SetTranslator.Translate(_info, target, value); try { _info.SetValue(target, value, new object[] { _lookUp }); } catch (ArgumentException e) { var message = string.Format( "Unable to set value of indexer on {0} to value of \"{1}\" to type {2}", target.GetType(), value == null ? "null" : value.ToString(), _info.PropertyType.FullName); throw new Exception(message, e); } }
public void GoGoCreateColumnAction(object target, string tableValue) { if (tableValue == ConstantStrings.IgnoreCell) { return; } var value = Translator.Translate(_info, tableValue); // Convert the Translated value to the type of the targeted property. // Translators guilty of not honoring the PropertyInfo ... Tag, Deep Link, Dates, etcetera value = SetTranslator.Translate(_info, target, value); try { _info.SetValue(target, value, null); } catch (ArgumentException e) { var message = string.Format( "Unable to set value of property {0} on {1} to value of \"{2}\" to type {3}", _info.Name, target.GetType(), value == null ? "null" : value.ToString(), _info.PropertyType.FullName); throw new Exception(message, e); } }
[Test] public void Merges() { var parsedSet1 = JsonPacker.ExtractDataAs <ParsedSet>(@" { 'Name' : 'Forest', 'Declares' : { 'timeStepOneDay' : [ 'day += [0, 1]' ] } } "); var parsedSet2 = JsonPacker.ExtractDataAs <ParsedSet>(@" { 'Name' : 'Grass', 'Uses' : ['Forest'], 'Declares' : { 'initialGrass' : [ 'initialGrassPopulation = 15' ], 'factorsGrass' : [ 'grassGrowSpeed = 3' ] }, 'Expressions' : [ 'grassPopulation += initialGrassPopulation + day * grassGrowSpeed' ] } "); var forest = new SetTranslator(parsedSet1).Translate(); var grass = new SetTranslator(parsedSet2).Translate(); try { var grassPopulation = grass.__("grassPopulation").Value; Assert.Fail(); } catch { } forest.Merge(grass); forest.Get <Iterator>("day").MoveNextValue(); Assert.IsTrue(forest.__("grassPopulation").Value == 18); }
[Test] public void SingleSet() { var parsedSet = JsonPacker.ExtractDataAs <ParsedSet>(@" { 'Name' : 'LinearMove', 'Declares' : { 'initial' : [ 'position = 0', 'A = 0', 'V = 1' ], 'timeStep' : [ 'T += [0, 1]' ] }, 'Expressions': [ 'V += A * T', 'distance += position + V * T' ] }" ); var linearMove = new SetTranslator(parsedSet).Translate(); linearMove.__("A").Value = 4; var time = linearMove.Get <Iterator>("T"); while (linearMove.__("distance").Value <= 20) { time.MoveNextValue(); } Assert.IsTrue(linearMove.__("T").Value == 3); }