Skip to main content
.NETFramework4.6.2net8.0net9.0

Implementation of data classification and redaction designed for testing.

Published
May 21, 2024
2y ago
Total Downloads
100.8K
100,767

Install

dotnet add package Microsoft.Extensions.Compliance.Testing --version 9.0.0-preview.4.24271.2
ProductVersions
.NET
net8.0net9.0
Other
.NETFramework4.6.2

README

Microsoft.Extensions.Compliance.Testing

This package provides test fakes for testing data classification and redaction.

Install the package

From the command-line:

dotnet add package Microsoft.Extensions.Compliance.Testing

Or directly in the C# project file:

<ItemGroup>
  <PackageReference Include="Microsoft.Extensions.Compliance.Testing" Version="[CURRENTVERSION]" />
</ItemGroup>

Usage

Fake Redactor

The FakeRedactor class provides options and services to verify redaction events.

The fake redactor services can be registered using one of the AddFakeRedaction overloads:

public static IServiceCollection AddFakeRedaction(this IServiceCollection services)
public static IServiceCollection AddFakeRedaction(this IServiceCollection services, Action<FakeRedactorOptions> configure)

For example:

IServiceCollection services = new ServiceCollection();
services = services.AddFakeRedaction(options => options.RedactionFormat = "Redacted: {0}");

It also registers an instance of Microsoft.Extensions.Compliance.Testing.FakeRedactionCollector which can be used to inspect what was redacted.

For example:

var serviceProvider = services.BuildServiceProvider();
var collector = serviceProvider.GetRequiredService<FakeRedactionCollector>();
Console.WriteLine(collector.AllRedactorRequests.Count); 

Fake Taxonomy

The Microsoft.Extensions.Compliance.Testing.FakeTaxonomy taxonomy class contains simple data classification values to use while testing redaction.

It consists of these data classification properties:

  • FakeTaxonomy.PublicData
  • FakeTaxonomy.PrivateData

These properties have their corresponding data classification attributes that can be used on method arguments and properties when features require it:

  • [PublicData] usually represents some data that should not be redacted.
  • [PrivateData] usually extensions to setup that should be redacted.

Example:

var redactionProvider = serviceProvider.GetFakeRedactionCollector();
var redactor = redactionProvider.GetRedactor(FakeTaxonomy.PublicData);
Console.WriteLine(redactor.Redact("Hello")); // "Redacted: Hello"

Feedback & Contributing

We welcome feedback and contributions in our GitHub repo.

Changes from Previous Version

No structural changes between v9.0.0-preview.3.24209.3 and v9.0.0-preview.4.24271.2.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 3 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.