-
Notifications
You must be signed in to change notification settings - Fork 732
/
FakeRedactionCollector.cs
101 lines (90 loc) · 2.66 KB
/
FakeRedactionCollector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using Microsoft.Shared.Diagnostics;
namespace Microsoft.Extensions.Compliance.Testing;
/// <summary>
/// Usage history of fake redaction types.
/// </summary>
public class FakeRedactionCollector
{
private readonly List<RedactorRequested> _redactorRequestedLog = [];
private readonly List<RedactedData> _dataRedactedLog = [];
/// <summary>
/// Gets the last redactor request "event".
/// </summary>
/// <exception cref="InvalidOperationException">There has been no previous redactor request event.</exception>
public RedactorRequested LastRedactorRequested
{
get
{
lock (_redactorRequestedLog)
{
if (_redactorRequestedLog.Count == 0)
{
Throw.InvalidOperationException("No redactor requested.");
}
return _redactorRequestedLog[_redactorRequestedLog.Count - 1];
}
}
}
/// <summary>
/// Gets the full log of all redactor request events that happened.
/// </summary>
public IReadOnlyList<RedactorRequested> AllRedactorRequests
{
get
{
lock (_redactorRequestedLog)
{
return _redactorRequestedLog.ToArray();
}
}
}
/// <summary>
/// Gets the last redaction "event".
/// </summary>
/// <exception cref="InvalidOperationException">There has been no previous redaction event.</exception>
public RedactedData LastRedactedData
{
get
{
lock (_dataRedactedLog)
{
if (_dataRedactedLog.Count == 0)
{
Throw.InvalidOperationException("No data redacted.");
}
return _dataRedactedLog[_dataRedactedLog.Count - 1];
}
}
}
/// <summary>
/// Gets the full log of all redaction events that happened.
/// </summary>
public IReadOnlyList<RedactedData> AllRedactedData
{
get
{
lock (_dataRedactedLog)
{
return _dataRedactedLog.ToArray();
}
}
}
internal void Append(RedactedData redactedData)
{
lock (_dataRedactedLog)
{
_dataRedactedLog.Add(redactedData);
}
}
internal void Append(RedactorRequested redactorRequested)
{
lock (_redactorRequestedLog)
{
_redactorRequestedLog.Add(redactorRequested);
}
}
}