public void TestGeneralParametersProcessing() { TParameterList parameters = new TParameterList(); TVariant value = new TVariant(); value.ApplyFormatString("Currency"); Assert.AreEqual("0", value.ToFormattedString(), "null value for currency should be 0"); value = new TVariant(value.ToFormattedString()); parameters.Add("amountdue", value, -1, 2, null, null, ReportingConsts.CALCULATIONPARAMETERS); parameters.Save("testDebug.csv", true); Assert.AreEqual(true, parameters.Exists("amountdue", -1, 1, eParameterFit.eBestFitEvenLowerLevel), "can find added parameter"); Assert.AreEqual("0", parameters.Get("amountdue", -1, 2, eParameterFit.eBestFit).ToFormattedString(), "currency parameter is stored not correctly"); //Assert.AreEqual("0", parameters.Get("amountdue", -1, 1, eParameterFit.eBestFit).ToFormattedString(), "currency parameter is stored not correctly"); Assert.AreEqual("0", parameters.Get("amountdue", -1, 1, eParameterFit.eBestFitEvenLowerLevel).ToFormattedString(), "currency parameter cannot be accessed from level up"); parameters.Add("IntegerList", "300,400"); parameters.Save("test.csv", false); parameters.Load(Path.GetFullPath("test.csv")); Assert.AreEqual("eString:300,400", parameters.Get( "IntegerList").EncodeToString(), "integers separated by comma should be treated as string"); parameters.Save("test2.csv", true); }
public void TestVariantCurrencies() { CultureInfo oldCulture; ArrayList cultures; String DecimalSeparator; String ThousandsOperator; TVariant v; oldCulture = Thread.CurrentThread.CurrentCulture; cultures = new ArrayList(); cultures.Add("en-GB"); cultures.Add("en-US"); cultures.Add("de-DE"); /* opposite meaning of , and . */ cultures.Add("ru-RU"); /* funny thousand separator: space */ foreach (string s in cultures) { Thread.CurrentThread.CurrentCulture = new CultureInfo(s, false); DecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator; ThousandsOperator = CultureInfo.CurrentCulture.NumberFormat.CurrencyGroupSeparator; Assert.AreEqual("#,##0;(#,##0);0;0", StringHelper.GetFormatString("Currency", "CurrencyWithoutDecimals"), "find correct format string, CurrencyWithoutDecimals"); Assert.AreEqual("#,#;(#,#);0;0", StringHelper.GetFormatString("Currency", "CurrencyThousands"), "find correct format string thousands"); Assert.AreEqual("#,##0.00;(#,##0.00);0.00;0", StringHelper.GetFormatString("", "Currency"), "Problem currency string"); /* console.writeLine(CultureInfo.CurrentCulture.TwoLetterISOLanguageName); */ Assert.AreEqual("0", new TVariant(0.00M, "Currency").ToFormattedString( "CurrencyWithoutDecimals"), "format currency 0 without decimals"); Assert.AreEqual("0", new TVariant(0.00M, "Currency").ToFormattedString("CurrencyThousands"), "format currency 0 thousands"); Assert.AreEqual("0", new TVariant(0.00M, "->>>,>>>,>>>,>>9.99").ToFormattedString( "CurrencyWithoutDecimals"), "format progress currency 0 without decimals"); Assert.AreEqual("0", new TVariant(0.00M, "->>>,>>>,>>>,>>9.99").ToFormattedString( "CurrencyThousands"), "format progress currency 0 thousands"); Assert.AreEqual("", new TVariant("", true).ToFormattedString( "Currency"), "format empty string in the column heading of a column that has currency values"); Assert.AreEqual("eString:text:", new TVariant(new TVariant("", true)).EncodeToString(), "format empty string in the column heading of a column that has currency values 2"); Assert.AreEqual("", new TVariant(new TVariant("", true)).ToFormattedString( "Currency"), "format empty string in the column heading of a column that has currency values 3"); Assert.AreEqual("eString:text:", new TVariant("", true).EncodeToString(), "format empty string in the column heading of a column that has currency values 4"); v = new TVariant("", true); Assert.AreEqual("eString:text:", v.EncodeToString(), "format empty string in the column heading of a column that has currency values 5"); v = new TVariant(); v.Add(new TVariant("", true)); Assert.AreEqual("eEmpty:text:", v.EncodeToString(), "format empty string in the column heading of a column that has currency values 6"); Assert.AreEqual("", v.ToFormattedString( "Currency"), "format empty string in the column heading of a column that has currency values 7"); v = new TVariant(); v.ApplyFormatString("partnerkey"); Assert.AreEqual("eInt64:partnerkey:-1", v.EncodeToString(), "format empty partnerkey 1"); Assert.AreEqual("0000000000", v.ToFormattedString(), "format empty partnerkey 2"); v = new TVariant(0.00M, "Currency"); v.ApplyFormatString("partnerkey"); Assert.AreEqual("eInt64:partnerkey:0", v.EncodeToString(), "format empty partnerkey 3"); Assert.AreEqual("0000000000", v.ToFormattedString(), "format empty partnerkey 4"); Assert.AreEqual("100" + DecimalSeparator + "00%", TVariant.DecodeFromString( "eDecimal:percentage2decimals:4636737291354636288").ToFormattedString(), "format percentage"); v = new TVariant(-1003.25M, "Currency"); Assert.AreEqual("eCurrency:Currency:-4571336140711264256", v.EncodeToString(), "format negative number with format that only prints negative values 1"); Assert.AreEqual("(1" + ThousandsOperator + "003" + DecimalSeparator + "25)", v.ToFormattedString(), "format negative number with format that only prints negative values 2"); v.ApplyFormatString("#,##0.00; ; ; ;"); Assert.AreEqual("eEmpty:#,##0.00; ; ; ;:", v.EncodeToString(), "format negative number with format that only prints negative values 3"); Assert.AreEqual("", v.ToFormattedString(), "format negative number with format that only prints negative values 4"); Assert.AreEqual("12" + ThousandsOperator + "346", new TVariant(12345.67M, "Currency").ToFormattedString( "CurrencyWithoutDecimals"), "Problem D format currency"); Assert.AreEqual("eCurrency:Currency:4668012718187306025", new TVariant(12345.67M, "Currency").EncodeToString(), "Problem E format currency"); Assert.AreEqual("12" + ThousandsOperator + "345" + DecimalSeparator + "67", StringHelper.FormatCurrency(new TVariant(12345.67), "Currency"), "Problem F format currency"); Assert.AreEqual("12345" + DecimalSeparator + "67", new TVariant(12345.67).ToString(), "Problem G format currency"); Assert.AreEqual("12" + ThousandsOperator + "345" + DecimalSeparator + "67", TVariant.DecodeFromString(new TVariant(12345.67M, "Currency").EncodeToString()).ToFormattedString( "Currency"), "Problem H format currency"); Assert.AreEqual("12", TVariant.DecodeFromString(new TVariant(12345.67M, "Currency").EncodeToString()).ToFormattedString( "CurrencyThousands"), "Problem I format currency"); Assert.AreEqual("12", TVariant.DecodeFromString(new TVariant(12345.67M, "CurrencyThousands").EncodeToString()).ToFormattedString( ""), "Problem J format currency"); Assert.AreEqual("12", TVariant.DecodeFromString(new TVariant(12345.67M, "#,##0.00;(#,##0.00);0.00;0").EncodeToString()).ToFormattedString( "CurrencyThousands"), "Problem J2 access format currency thousands"); /* we don't support thousands only with the progress format, too complicated */ /* Assert.AreEqual('12', TVariant.DecodeFromString(TVariant.CreateCurrency(12345.67,'>>>,>>>,>>>,>>9.99').EncodeToString("CurrencyThousands")).toFormattedString(''), 'Problem J3 progress format currency thousands'); */ Assert.AreEqual("12" + ThousandsOperator + "346", TVariant.DecodeFromString(new TVariant(12345.67M, "#,##0.00;(#,##0.00);0.00;0").EncodeToString()).ToFormattedString( "CurrencyWithoutDecimals"), "Problem J2 access format currency w/o decimals"); Assert.AreEqual("12" + ThousandsOperator + "346", TVariant.DecodeFromString(new TVariant(12345.67M, "->>>,>>>,>>>,>>9.99").EncodeToString()).ToFormattedString( "CurrencyWithoutDecimals"), "Problem J3 progress format currency w/o decimals"); Assert.AreEqual("12" + ThousandsOperator + "346", TVariant.DecodeFromString(new TVariant(12345.67M, "CurrencyWithoutDecimals").EncodeToString()).ToFormattedString( ""), "Problem K format currency"); } Thread.CurrentThread.CurrentCulture = oldCulture; }
public void TestVariantComposite() { CultureInfo oldCulture; TVariant v; TVariant v2; TVariant v3; String encodedString; String s; oldCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB", false); v = new TVariant("test"); Assert.AreEqual("eString:test", v.EncodeToString(), "before EncodeToString1"); v.Add(new TVariant(true)); Assert.AreEqual("eComposite::\"eString:test|eBoolean:true\"", v.EncodeToString(), "EncodeToString1"); v.Add(new TVariant(2.23M, "Currency")); v.Add(new TVariant(2.23M)); v.Add(new TVariant(2)); Assert.AreEqual( "eComposite::\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2\"", v.EncodeToString(), "EncodeToString2"); v.Add(new TVariant(" test ")); Assert.AreEqual( "eComposite::\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|eString: test \"", v.EncodeToString(), "EncodeToString3"); v.Add(new TVariant(new DateTime(2004, 03, 29))); v2 = new TVariant(v); // copy constructor Assert.AreEqual( "eComposite::\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|eString: test |\"\"eDateTime:\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"", v2.EncodeToString(), "EncodeToString4"); Assert.AreEqual("eComposite::\"eString:test|eBoolean:true\"", TVariant.DecodeFromString( "eComposite::\"eString:test|eBoolean:true\"").EncodeToString(), "DecodeFromString"); Assert.AreEqual("eComposite::\"eString: test |eBoolean:true\"", TVariant.DecodeFromString( "eComposite::\"eString: test |eBoolean:true\"").EncodeToString(), "DecodeFromString with spaces in string"); Assert.AreEqual(v2.EncodeToString(), TVariant.DecodeFromString(v2.EncodeToString()).EncodeToString(), "DecodeFromString2"); v = new TVariant(); v.Add(new TVariant(2)); Assert.AreEqual(2.00, v.ToDouble(), "Variant Composite Double"); v.Add(new TVariant(" test ")); v3 = new TVariant(); v3.Add(new TVariant(1)); v3.Add(v); v3.Add(v2); s = "eInteger:1|\"eComposite::\"\"eInteger:2|\"\"\"\"eString:\"\"\"\"\"\"\"\" test \"\"\"\"\"\"\"\"\"\"\"\"\"\"\"|\"eComposite::\"\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|\"\"\"\"eString:\"\"\"\"\"\"\"\" test \"\"\"\"\"\"\"\"\"\"\"\"|\"\"\"\"eDateTime:\"\"\"\"\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"\"\"\"\"\"\"\"\""; Assert.AreEqual("eInteger:1", StringHelper.GetNextCSV(ref s, "|"), "split composite CSV 1"); Assert.AreEqual("eComposite::\"eInteger:2|\"\"eString:\"\"\"\" test \"\"\"\"\"\"\"", StringHelper.GetNextCSV(ref s, "|"), "split composite CSV 2"); Assert.AreEqual( "\"eComposite::\"\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|\"\"\"\"eString:\"\"\"\"\"\"\"\" test \"\"\"\"\"\"\"\"\"\"\"\"|\"\"\"\"eDateTime:\"\"\"\"\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"", s, "split composite CSV 4"); Assert.AreEqual( "eComposite::\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|\"\"eString:\"\"\"\" test \"\"\"\"\"\"|\"\"eDateTime:\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"", StringHelper.GetNextCSV(ref s, "|"), "split composite CSV 6"); Assert.AreEqual( "eComposite::\"eInteger:1|\"\"eComposite::\"\"\"\"eInteger:2|eString: test \"\"\"\"\"\"|\"\"eComposite::\"\"\"\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|eString: test |\"\"\"\"\"\"\"\"eDateTime:\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"", v3.EncodeToString(), "EncodeToString1 with Composite containing Composite"); Assert.AreEqual(v3.EncodeToString(), TVariant.DecodeFromString( v3.EncodeToString()).EncodeToString(), "DecodeFromString with Composite containing Composite"); v = new TVariant(); v.Add(new TVariant(2)); v.Add(new TVariant(" test")); v3 = new TVariant(); v3.Add(v); v3.Add(v2); Assert.AreEqual( "eComposite::\"eInteger:2|eString: test|\"\"eComposite::\"\"\"\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|eString: test |\"\"\"\"\"\"\"\"eDateTime:\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"", v3.EncodeToString(), "EncodeToString2 with Composite containing Composite"); Assert.AreEqual(v3.EncodeToString(), TVariant.DecodeFromString( v3.EncodeToString()).EncodeToString(), "DecodeFromString with Composite containing Composite"); v = new TVariant("test\"1"); v.Add(new TVariant(" test\"2")); v2 = new TVariant("test\"3"); v2.Add(new TVariant("test\"4")); Assert.AreEqual("eString:\"test\"\"3test\"\"4\"", v2.EncodeToString(), "Test Cascading Composite 1"); Assert.AreEqual("eString:\"test\"\"3test\"\"4\"", TVariant.DecodeFromString( v2.EncodeToString()).EncodeToString(), "Test Cascading Composite 2"); v.Add(v2); Assert.AreEqual("eString:\"test\"\"1 test\"\"2test\"\"3test\"\"4\"", v.EncodeToString(), "Test Cascading Composite 3"); Assert.AreEqual("eString:\"test\"\"1 test\"\"2test\"\"3test\"\"4\"", TVariant.DecodeFromString( v.EncodeToString()).EncodeToString(), "Test Cascading Composite 4"); v = new TVariant("test1\""); v.Add(new TVariant(" test2\"")); v2 = new TVariant(); v2.Add(new TVariant("2900")); v.Add(v2); v.Add(new TVariant("test3")); Assert.AreEqual("eComposite::\"\"\"eString:\"\"\"\"test1\"\"\"\"\"\"\"\" test2\"\"\"\"\"\"\"\"\"\"\"\"\"\"|eInteger:2900|eString:test3\"", v.EncodeToString(), "Test Cascading Composite2"); Assert.AreEqual("eString:\"\"\" ) ))\"", TVariant.DecodeFromString("eString:\"\"\" ) ))\"").EncodeToString(), "problem decoding string"); v = new TVariant(); v.Add(new TVariant("test\"")); v.Add(new TVariant("2900")); v.Add(new TVariant("test")); Assert.AreEqual("eComposite::\"\"\"eString:\"\"\"\"test\"\"\"\"\"\"\"\"\"\"\"\"\"\"|eInteger:2900|eString:test\"", v.EncodeToString(), "problem encoding 1b"); Assert.AreEqual(v.EncodeToString(), TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), "problem encoding1a"); v = new TVariant(); v.Add(new TVariant("SELECT DISTINCT WHERE ( ( cc.a_cost_centre_code_c = \"")); v.Add(new TVariant("2900")); v.Add(new TVariant("\" ) ))")); encodedString = "eComposite::\"\"\"eString:\"\"\"\"SELECT DISTINCT " + " WHERE ( ( cc.a_cost_centre_code_c = \"\"\"\"\"\"\"\"\"\"\"\"\"\"|eInteger:2900|\"\"eString:\"\"\"\"\"\"\"\"\"\"\"\" ) ))\"\"\"\"\"\"\""; Assert.AreEqual(encodedString, v.EncodeToString(), "problem encoding1"); Assert.AreEqual(v.EncodeToString(), TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), "problem encoding2"); Assert.AreEqual(encodedString, TVariant.DecodeFromString(encodedString).EncodeToString(), "problem encoding3"); v = new TVariant(); v.Add(new TVariant("29001234", "partnerkey")); v.Add(new TVariant("29001235", "partnerkey")); v.Add(new TVariant("29001236", "partnerkey")); v.FormatString = "csvlistslash"; Assert.AreEqual("eComposite:csvlistslash:\"eInteger:partnerkey:29001234|eInteger:partnerkey:29001235|eInteger:partnerkey:29001236\"", v.EncodeToString(), "format list with slash separator 1"); Assert.AreEqual("0029001234/0029001235/0029001236", v.ToFormattedString(""), "format list with slash separator 2"); v = new TVariant(435082450); Assert.AreEqual("eInteger:435082450", v.EncodeToString(), "test integer with text format 1"); v.ApplyFormatString("text"); Assert.AreEqual("eString:text:435082450", v.EncodeToString(), "test integer with text format 2"); Assert.AreEqual("eString:text:435082450", TVariant.DecodeFromString( v.EncodeToString()).EncodeToString(), "test integer with text format 3"); v2 = new TVariant(v); Assert.AreEqual("eString:text:435082450", v2.EncodeToString(), "test integer with text format 4"); v = new TVariant(); v.Add(new TVariant((Object)(29015041.0))); v.Add(new TVariant((Object)(29017453.0))); Assert.AreEqual("eComposite:Currency:\"eCurrency:Currency:4718553875991232512|eCurrency:Currency:4718554523457552384\"", v.EncodeToString(), "test composite partner key"); Assert.AreEqual("eComposite:Currency:\"eCurrency:Currency:4718553875991232512|eCurrency:Currency:4718554523457552384\"", TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), "test composite partner key 4"); v.ApplyFormatString("csvlistslash:partnerkey"); Assert.AreEqual("eComposite:csvlistslash:\"eInt64:partnerkey:29015041|eInt64:partnerkey:29017453\"", v.EncodeToString(), "test composite partner key 2"); Assert.AreEqual("0029015041/0029017453", v.ToFormattedString(" "), "test composite partner key 3"); v = TVariant.DecodeFromString("eComposite:csvlistslash:\"eString:text:de Vries, Rianne|eString:text:Visser, W. and K.K.J.\""); Assert.AreEqual("de Vries, Rianne/Visser, W. and K.K.J.", v.ToFormattedString("")); Assert.AreEqual("de Vries, Rianne/Visser, W. and K.K.J.", v.ToFormattedString("", "CSV")); v = new TVariant(); v.Add(new TVariant("From Gift-Batch#: ")); v.Add(new TVariant(8351)); Assert.AreEqual("From Gift-Batch#: 8351", v.ToFormattedString(""), "colon in text"); Assert.AreEqual("eComposite::\"\"\"eString:\"\"\"\"From Gift-Batch#: \"\"\"\"\"\"|eInteger:8351\"", v.EncodeToString(), "colon in text2"); Assert.AreEqual("From Gift-Batch#: 8351", TVariant.DecodeFromString(v.EncodeToString()).ToFormattedString(""), "colon in text3"); v = new TVariant(); v.Add(new TVariant("Total for Account ")); v.Add(new TVariant(1000)); v.Add(new TVariant(':')); Assert.AreEqual("Total for Account 1000:", v.ToFormattedString(), "colon in text on its own"); Assert.AreEqual(v.EncodeToString(), TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), "colon in text on its own 2"); Assert.AreEqual(TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), v.EncodeToString(), "Composite with two empty strings encoding decoding encoding"); v = new TVariant(); v.Add(new TVariant("t"), "", false); v.Add(new TVariant("|"), "", false); Assert.AreEqual("eComposite::\"eString:t|\"\"eString:|\"\"\"", v.EncodeToString(), "Composite with pipe encoding"); Assert.AreEqual(TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), v.EncodeToString(), "Composite with pipe encoding decoding encoding"); v = new TVariant("", true); Assert.AreEqual("eString:text:", v.EncodeToString(), "empty string encoding"); Assert.AreEqual(v.EncodeToString(), TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), "empty string decoding"); Assert.AreEqual(v.ToString(), "", "empty string identity"); Assert.AreEqual("", TVariant.DecodeFromString(v.EncodeToString()).ToString(), "empty string decoding identity"); Assert.AreEqual(eVariantTypes.eString, TVariant.DecodeFromString(v.EncodeToString()).TypeVariant, "empty string decoding type"); v = new TVariant(" ", true); Assert.AreEqual(v.ToString(), " ", "one-space string identity"); Assert.AreEqual("eString:text: ", v.EncodeToString(), "one-space string encoding"); Assert.AreEqual(v.EncodeToString(), TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), "one-space string decoding"); Assert.AreEqual(" ", TVariant.DecodeFromString(v.EncodeToString()).ToString(), "one-space string decoding identity"); Assert.AreEqual(eVariantTypes.eString, TVariant.DecodeFromString(v.EncodeToString()).TypeVariant, "one-space string decoding type"); Thread.CurrentThread.CurrentCulture = oldCulture; }