Skip to content

Commit 2aef099

Browse files
committed
feat: Add unit tests for KeepOperator, RedactOperator, and ReplaceOperator
1 parent a31e41c commit 2aef099

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Xunit;
2+
3+
namespace ManagedCode.Presidio.Anonymizer.Tests;
4+
5+
public sealed class KeepOperatorTests
6+
{
7+
[Fact]
8+
public void OperateReturnsOriginalText()
9+
{
10+
var op = new KeepOperator();
11+
var output = op.Operate("original", new Dictionary<string, object?>());
12+
13+
Assert.Equal("original", output);
14+
}
15+
16+
[Fact]
17+
public void ValidateDoesNotThrow()
18+
{
19+
var op = new KeepOperator();
20+
21+
var exception = Record.Exception(() => op.Validate(new Dictionary<string, object?>()));
22+
Assert.Null(exception);
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Xunit;
2+
3+
namespace ManagedCode.Presidio.Anonymizer.Tests;
4+
5+
public sealed class RedactOperatorTests
6+
{
7+
[Fact]
8+
public void OperateReturnsEmptyString()
9+
{
10+
var op = new RedactOperator();
11+
var output = op.Operate("secret", new Dictionary<string, object?>());
12+
13+
Assert.Equal(string.Empty, output);
14+
}
15+
16+
[Fact]
17+
public void ValidateDoesNothing()
18+
{
19+
var op = new RedactOperator();
20+
var exception = Record.Exception(() => op.Validate(new Dictionary<string, object?>()));
21+
22+
Assert.Null(exception);
23+
}
24+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Xunit;
2+
3+
namespace ManagedCode.Presidio.Anonymizer.Tests;
4+
5+
public sealed class ReplaceOperatorTests
6+
{
7+
[Fact]
8+
public void OperateUsesProvidedReplacement()
9+
{
10+
var op = new ReplaceOperator();
11+
var output = op.Operate(
12+
"secret",
13+
new Dictionary<string, object?>
14+
{
15+
[ReplaceOperator.NewValueKey] = "replacement",
16+
["entity_type"] = "PERSON",
17+
});
18+
19+
Assert.Equal("replacement", output);
20+
}
21+
22+
[Fact]
23+
public void OperateFallsBackToEntityPlaceholder()
24+
{
25+
var op = new ReplaceOperator();
26+
var output = op.Operate(
27+
"secret",
28+
new Dictionary<string, object?>
29+
{
30+
["entity_type"] = "PERSON",
31+
});
32+
33+
Assert.Equal("<PERSON>", output);
34+
}
35+
36+
[Fact]
37+
public void ValidateRejectsNonStringReplacement()
38+
{
39+
var op = new ReplaceOperator();
40+
var parameters = new Dictionary<string, object?>
41+
{
42+
[ReplaceOperator.NewValueKey] = 123,
43+
};
44+
45+
var exception = Assert.Throws<InvalidParamException>(() => op.Validate(parameters));
46+
Assert.Equal("Invalid parameter value for new_value. Expecting 'string', but got 'number'.", exception.Message);
47+
}
48+
}

0 commit comments

Comments
 (0)