summaryrefslogtreecommitdiff
path: root/src/dtf/test/WixToolsetTests.Dtf.Compression/MisbehavingStreamContext.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-03-31 11:56:14 -0700
committerRob Mensching <rob@firegiant.com>2022-03-31 18:01:06 -0700
commit47582b162368e8edf7a3b11c13b8e9dabc5f0a26 (patch)
tree2c4063eff325684bed39de0edacd7866a257ae02 /src/dtf/test/WixToolsetTests.Dtf.Compression/MisbehavingStreamContext.cs
parent167296c42497c4e95f0d5d71168542d747655981 (diff)
downloadwix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.tar.gz
wix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.tar.bz2
wix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.zip
Provide managed CA and Embedded UI DTF libraries via NuGet
Lots of refactoring to bring the SFX tooling back into the 'dtf' layer since they are (in the end) tightly coupled to some DTF assemblies. Also refactored the DTF tests into their own folder and added a couple integration tests to build using the new CA/UI NuGet package. Closes wixtoolset/issues#6080
Diffstat (limited to 'src/dtf/test/WixToolsetTests.Dtf.Compression/MisbehavingStreamContext.cs')
-rw-r--r--src/dtf/test/WixToolsetTests.Dtf.Compression/MisbehavingStreamContext.cs202
1 files changed, 202 insertions, 0 deletions
diff --git a/src/dtf/test/WixToolsetTests.Dtf.Compression/MisbehavingStreamContext.cs b/src/dtf/test/WixToolsetTests.Dtf.Compression/MisbehavingStreamContext.cs
new file mode 100644
index 00000000..2531f3bc
--- /dev/null
+++ b/src/dtf/test/WixToolsetTests.Dtf.Compression/MisbehavingStreamContext.cs
@@ -0,0 +1,202 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3using System;
4using System.IO;
5using System.Collections.Generic;
6using WixToolset.Dtf.Compression;
7
8namespace WixToolset.Dtf.Test
9{
10 public class MisbehavingStreamContext : ArchiveFileStreamContext
11 {
12 public const string EXCEPTION = "Test exception.";
13
14 private bool throwEx;
15 private bool getName;
16 private bool openArchive;
17 private bool closeArchive;
18 private bool openFile;
19 private bool closeFile;
20 private int closeFileCount;
21
22 public MisbehavingStreamContext(
23 string cabinetFile,
24 string directory,
25 IDictionary<string, string> files,
26 bool throwEx,
27 bool getName,
28 bool openArchive,
29 bool closeArchive,
30 bool openFile,
31 bool closeFile)
32 : base(cabinetFile, directory, files)
33 {
34 this.throwEx = throwEx;
35 this.getName = getName;
36 this.openArchive = openArchive;
37 this.closeArchive = closeArchive;
38 this.openFile = openFile;
39 this.closeFile = closeFile;
40 }
41
42 public override string GetArchiveName(int archiveNumber)
43 {
44 if (!this.getName)
45 {
46 if (throwEx)
47 {
48 throw new Exception(EXCEPTION);
49 }
50 else
51 {
52 return null;
53 }
54 }
55 return base.GetArchiveName(archiveNumber);
56 }
57
58 public override Stream OpenArchiveWriteStream(
59 int archiveNumber,
60 string archiveName,
61 bool truncate,
62 CompressionEngine compressionEngine)
63 {
64 if (!this.openArchive)
65 {
66 if (throwEx)
67 {
68 throw new Exception(EXCEPTION);
69 }
70 else
71 {
72 return null;
73 }
74 }
75 return base.OpenArchiveWriteStream(
76 archiveNumber, archiveName, truncate, compressionEngine);
77 }
78
79 public override void CloseArchiveWriteStream(
80 int archiveNumber,
81 string archiveName,
82 Stream stream)
83 {
84 if (!this.closeArchive)
85 {
86 if (throwEx)
87 {
88 this.closeArchive = true;
89 throw new Exception(EXCEPTION);
90 }
91 return;
92 }
93 base.CloseArchiveWriteStream(archiveNumber, archiveName, stream);
94 }
95
96 public override Stream OpenFileReadStream(
97 string path,
98 out FileAttributes attributes,
99 out DateTime lastWriteTime)
100 {
101 if (!this.openFile)
102 {
103 if (throwEx)
104 {
105 throw new Exception(EXCEPTION);
106 }
107 else
108 {
109 attributes = FileAttributes.Normal;
110 lastWriteTime = DateTime.MinValue;
111 return null;
112 }
113 }
114 return base.OpenFileReadStream(path, out attributes, out lastWriteTime);
115 }
116
117 public override void CloseFileReadStream(string path, Stream stream)
118 {
119 if (!this.closeFile && ++closeFileCount == 2)
120 {
121 if (throwEx)
122 {
123 throw new Exception(EXCEPTION);
124 }
125 return;
126 }
127 base.CloseFileReadStream(path, stream);
128 }
129
130 public override Stream OpenArchiveReadStream(
131 int archiveNumber,
132 string archiveName,
133 CompressionEngine compressionEngine)
134 {
135 if (!this.openArchive)
136 {
137 if (throwEx)
138 {
139 throw new Exception(EXCEPTION);
140 }
141 else
142 {
143 return null;
144 }
145 }
146 return base.OpenArchiveReadStream(archiveNumber, archiveName, compressionEngine);
147 }
148
149 public override void CloseArchiveReadStream(
150 int archiveNumber,
151 string archiveName,
152 Stream stream)
153 {
154 if (!this.closeArchive)
155 {
156 if (throwEx)
157 {
158 this.closeArchive = true;
159 throw new Exception(EXCEPTION);
160 }
161 return;
162 }
163 base.CloseArchiveReadStream(archiveNumber, archiveName, stream);
164 }
165
166 public override Stream OpenFileWriteStream(
167 string path,
168 long fileSize,
169 DateTime lastWriteTime)
170 {
171 if (!this.openFile)
172 {
173 if (throwEx)
174 {
175 throw new Exception(EXCEPTION);
176 }
177 else
178 {
179 return null;
180 }
181 }
182 return base.OpenFileWriteStream(path, fileSize, lastWriteTime);
183 }
184
185 public override void CloseFileWriteStream(
186 string path,
187 Stream stream,
188 FileAttributes attributes,
189 DateTime lastWriteTime)
190 {
191 if (!this.closeFile && ++closeFileCount == 2)
192 {
193 if (throwEx)
194 {
195 throw new Exception(EXCEPTION);
196 }
197 return;
198 }
199 base.CloseFileWriteStream(path, stream, attributes, lastWriteTime);
200 }
201 }
202}