From db82e45626e414f310eb265531402da016879620 Mon Sep 17 00:00:00 2001 From: Alberto Spelta Date: Mon, 4 Mar 2024 21:19:19 +0100 Subject: [PATCH] Upadate unit tests --- .../DaxModelObfuscatorTests.cs | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/tests/Dax.Vpax.Obfuscator.Tests/DaxModelObfuscatorTests.cs b/tests/Dax.Vpax.Obfuscator.Tests/DaxModelObfuscatorTests.cs index 06d2320..ee61bf2 100644 --- a/tests/Dax.Vpax.Obfuscator.Tests/DaxModelObfuscatorTests.cs +++ b/tests/Dax.Vpax.Obfuscator.Tests/DaxModelObfuscatorTests.cs @@ -95,27 +95,27 @@ public void ObfuscateExpression_ExtensionColumnNameFullyQualified_ReturnsObfusca } [Fact] - public void ObfuscateExpression_ExtensionColumnName_T1() + public void ObfuscateExpression_ExtensionColumnNameFullyQualified_ReturnsObfuscatedColumnNamePartsWithoutPreservingQuotationMarkEscapeChar() { - var expression = """ SUMX(ADDCOLUMNS({}, " col5 [%]", 1), col5 [%]) """; - var expected = """ SUMX(ADDCOLUMNS({}, "XXXX[Y]", 1), XXXX[Y]) """; + var expression = """ SELECTCOLUMNS(ADDCOLUMNS({}, "aaa[b""c]", 1), aaa[b"c]) """; + var expected = """ SELECTCOLUMNS(ADDCOLUMNS({}, "XXX[YYY]", 1), XXX[YYY]) """; var obfuscator = new DaxModelObfuscator(new Model()); - //obfuscator.Texts.Add(new DaxText("rate", "XXXX")); - //obfuscator.Texts.Add(new DaxText("%", "Y")); + obfuscator.Texts.Add(new DaxText("aaa", "XXX")); + obfuscator.Texts.Add(new DaxText("b\"c", "YYY")); var actual = obfuscator.ObfuscateExpression(expression); Assert.Equal(expected, actual); } [Fact] - public void ObfuscateExpression_ExtensionColumnNameFullyQualifiedWithSquareBracket_ReturnsObfuscatedColumnNameParts() + public void ObfuscateExpression_ExtensionColumnNameFullyQualifiedWithSquareBracket_Test1() { var expression = """ SUMX(ADDCOLUMNS({}, "@rate[%]", 1), [@rate[%]]]) """; - var expected = """ SUMX(ADDCOLUMNS({}, "XXXXX[Y]", 1), [XXXXX[Y]]]) """; + var expected = """ SUMX(ADDCOLUMNS({}, "-XXXXX[Y]", 1), [-XXXXX[Y]]]) """; var obfuscator = new DaxModelObfuscator(new Model()); - obfuscator.Texts.Add(new DaxText("@rate", "XXXXX")); + obfuscator.Texts.Add(new DaxText("-@rate", "-XXXXX")); obfuscator.Texts.Add(new DaxText("%", "Y")); var actual = obfuscator.ObfuscateExpression(expression); @@ -123,14 +123,28 @@ public void ObfuscateExpression_ExtensionColumnNameFullyQualifiedWithSquareBrack } [Fact] - public void ObfuscateExpression_ExtensionColumnNameFullyQualified_ReturnsObfuscatedColumnNamePartsWithoutPreservingQuotationMarkEscapeChar() + public void ObfuscateExpression_ExtensionColumnNameFullyQualifiedWithSquareBracket_Test2() { - var expression = """ SELECTCOLUMNS(ADDCOLUMNS({}, "aaa[b""c]", 1), aaa[b"c]) """; - var expected = """ SELECTCOLUMNS(ADDCOLUMNS({}, "XXX[YYY]", 1), XXX[YYY]) """; + var expression = """ SUMX(ADDCOLUMNS({}, " col11 [ a] b ] ", 1), [ col11 [ a]] b ]] ]) """; + var expected = """ SUMX(ADDCOLUMNS({}, "-XXXXX[YYYYYY]", 1), [-XXXXX[YYYYYY]]]) """; var obfuscator = new DaxModelObfuscator(new Model()); - obfuscator.Texts.Add(new DaxText("aaa", "XXX")); - obfuscator.Texts.Add(new DaxText("b\"c", "YYY")); + obfuscator.Texts.Add(new DaxText("-col11", "-XXXXX")); + obfuscator.Texts.Add(new DaxText(" a] b ", "YYYYYY")); + var actual = obfuscator.ObfuscateExpression(expression); + + Assert.Equal(expected, actual); + } + + [Fact] + public void ObfuscateExpression_ExtensionColumnNameFullyQualifiedWithSquareBracket_Test3() + { + var expression = """ SUMX(ADDCOLUMNS({}, " col15 [ a ""' b ] ", 1), col15[ a "' b ]) """; + var expected = """ SUMX(ADDCOLUMNS({}, "XXXXX[YYYYYYYY]", 1), XXXXX[YYYYYYYY]) """; + + var obfuscator = new DaxModelObfuscator(new Model()); + obfuscator.Texts.Add(new DaxText("col15", "XXXXX")); + obfuscator.Texts.Add(new DaxText(" a \"' b ", "YYYYYYYY")); var actual = obfuscator.ObfuscateExpression(expression); Assert.Equal(expected, actual);