-
Notifications
You must be signed in to change notification settings - Fork 308
/
ProductEventHandlerIntegrationTest.cs
78 lines (64 loc) · 3.18 KB
/
ProductEventHandlerIntegrationTest.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
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System.IO;
using iText.Commons.Actions.Confirmations;
using iText.Commons.Actions.Sequence;
using iText.Commons.Ecosystem;
using iText.Commons.Utils;
using iText.Test;
namespace iText.Commons.Actions {
public class ProductEventHandlerIntegrationTest : ExtendedITextTest {
private TextWriter outBackup;
[NUnit.Framework.SetUp]
public virtual void InitTest() {
outBackup = System.Console.Out;
ProductEventHandler.INSTANCE.ClearProcessors();
}
[NUnit.Framework.TearDown]
public virtual void AfterEach() {
System.Console.SetOut(outBackup);
ProductProcessorFactoryKeeper.RestoreDefaultProductProcessorFactory();
ProductEventHandler.INSTANCE.ClearProcessors();
}
[NUnit.Framework.Test]
public virtual void RemoveAGPLLoggingTest() {
MemoryStream testOut = new MemoryStream();
System.Console.SetOut(new FormattingStreamWriter(testOut));
EventManager.AcknowledgeAgplUsageDisableWarningMessage();
for (int i = 0; i < 10001; i++) {
ProductEventHandler handler = ProductEventHandler.INSTANCE;
SequenceId sequenceId = new SequenceId();
NUnit.Framework.Assert.IsTrue(handler.GetEvents(sequenceId).IsEmpty());
ITextTestEvent @event = new ITextTestEvent(sequenceId, null, "test-event",
ProductNameConstant.ITEXT_CORE);
EventManager.GetInstance().OnEvent(@event);
ConfirmEvent confirmEvent = new ConfirmEvent(sequenceId, @event);
EventManager.GetInstance().OnEvent(confirmEvent);
NUnit.Framework.Assert.AreEqual(1, handler.GetEvents(sequenceId).Count);
NUnit.Framework.Assert.IsTrue(handler.GetEvents(sequenceId)[0] is ConfirmedEventWrapper);
NUnit.Framework.Assert.AreEqual(@event, ((ConfirmedEventWrapper)handler.GetEvents(sequenceId)[0]).GetEvent
());
}
using (var reader = new StreamReader(testOut))
{
NUnit.Framework.Assert.AreEqual("", reader.ReadToEnd());
}
}
}
}