Skip to content

Commit

Permalink
Upadate unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albertospelta committed Mar 4, 2024
1 parent 77bdf72 commit db82e45
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions tests/Dax.Vpax.Obfuscator.Tests/DaxModelObfuscatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,42 +95,56 @@ 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);

Assert.Equal(expected, actual);
}

[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);
Expand Down

0 comments on commit db82e45

Please sign in to comment.