• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JaCraig / Mecha / 14362848556

09 Apr 2025 05:00PM UTC coverage: 82.041% (+0.1%) from 81.924%
14362848556

push

github

web-flow
Merge pull request #319 from JaCraig/dependabot/nuget/Mecha.Core/dependencies-ca028a82c2

fix: bump System.Text.Json from 9.0.3 to 9.0.4 in /Mecha.Core in the dependencies group

758 of 1060 branches covered (71.51%)

Branch coverage included in aggregate %.

1348 of 1507 relevant lines covered (89.45%)

3852923.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/Mecha.Core/Generator/Helpers/EmptyFileStream.cs
1
using System;
2
using System.IO;
3
using System.Threading;
4
using System.Threading.Tasks;
5

6
namespace Mecha.Core.Generator.Helpers
7
{
8
    /// <summary>
9
    /// Empty file stream
10
    /// </summary>
11
    /// <seealso cref="System.IO.FileStream"/>
12
    public class EmptyFileStream : FileStream
13
    {
14
        /// <summary>
15
        /// Initializes a new instance of the <see cref="EmptyFileStream"/> class.
16
        /// </summary>
17
        public EmptyFileStream()
18
            : base($"./Mecha/mock-{Guid.NewGuid()}.txt", FileMode.OpenOrCreate)
7✔
19
        {
20
        }
7✔
21

22
        /// <summary>
23
        /// Gets a value that indicates whether the current stream supports reading.
24
        /// </summary>
25
        public override bool CanRead => true;
2✔
26

27
        /// <summary>
28
        /// Gets a value that indicates whether the current stream supports seeking.
29
        /// </summary>
30
        public override bool CanSeek => true;
2✔
31

32
        /// <summary>
33
        /// Gets a value that determines whether the current stream can time out.
34
        /// </summary>
35
        public override bool CanTimeout => true;
2✔
36

37
        /// <summary>
38
        /// Gets a value that indicates whether the current stream supports writing.
39
        /// </summary>
40
        public override bool CanWrite => true;
2✔
41

42
        /// <summary>
43
        /// Gets the operating system file handle for the file that the current object encapsulates.
44
        /// </summary>
45
        [Obsolete("Handle no longer used")]
46
        public override IntPtr Handle { get; }
2✔
47

48
        /// <summary>
49
        /// Gets a value that indicates whether the <see langword="FileStream"/> was opened
50
        /// asynchronously or synchronously.
51
        /// </summary>
52
        public override bool IsAsync => true;
2✔
53

54
        /// <summary>
55
        /// Gets the length in bytes of the stream.
56
        /// </summary>
57
        public override long Length => 1000;
2✔
58

59
        /// <summary>
60
        /// Gets or sets the current position of this stream.
61
        /// </summary>
62
        public override long Position { get; set; }
13✔
63

64
        /// <summary>
65
        /// Gets or sets a value, in milliseconds, that determines how long the stream will attempt
66
        /// to read before timing out.
67
        /// </summary>
68
        public override int ReadTimeout { get; set; }
13✔
69

70
        /// <summary>
71
        /// Gets or sets a value, in milliseconds, that determines how long the stream will attempt
72
        /// to write before timing out.
73
        /// </summary>
74
        public override int WriteTimeout { get; set; }
13✔
75

76
        /// <summary>
77
        /// Begins an asynchronous read operation. Consider using <see
78
        /// cref="M:System.IO.FileStream.ReadAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)"/> instead.
79
        /// </summary>
80
        /// <param name="array">The buffer to read data into.</param>
81
        /// <param name="offset">
82
        /// The byte offset in <paramref name="array"/> at which to begin reading.
83
        /// </param>
84
        /// <param name="numBytes">The maximum number of bytes to read.</param>
85
        /// <param name="callback">
86
        /// The method to be called when the asynchronous read operation is completed.
87
        /// </param>
88
        /// <param name="state">
89
        /// A user-provided object that distinguishes this particular asynchronous read request from
90
        /// other requests.
91
        /// </param>
92
        /// <returns>An object that references the asynchronous read.</returns>
93
        /// <exception cref="FileNotFoundException"></exception>
94
        public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback? callback, object? state) => null!;
11✔
95

96
        /// <summary>
97
        /// Begins an asynchronous write operation. Consider using <see
98
        /// cref="M:System.IO.FileStream.WriteAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)"/> instead.
99
        /// </summary>
100
        /// <param name="array">The buffer containing data to write to the current stream.</param>
101
        /// <param name="offset">
102
        /// The zero-based byte offset in <paramref name="array"/> at which to begin copying bytes
103
        /// to the current stream.
104
        /// </param>
105
        /// <param name="numBytes">The maximum number of bytes to write.</param>
106
        /// <param name="callback">
107
        /// The method to be called when the asynchronous write operation is completed.
108
        /// </param>
109
        /// <param name="state">
110
        /// A user-provided object that distinguishes this particular asynchronous write request
111
        /// from other requests.
112
        /// </param>
113
        /// <returns>An object that references the asynchronous write.</returns>
114
        /// <exception cref="EndOfStreamException"></exception>
115
        public override IAsyncResult BeginWrite(byte[] array, int offset, int numBytes, AsyncCallback? callback, object? state) => null!;
11✔
116

117
        /// <summary>
118
        /// Closes the current stream and releases any resources (such as sockets and file handles)
119
        /// associated with the current stream. Instead of calling this method, ensure that the
120
        /// stream is properly disposed.
121
        /// </summary>
122
        /// <exception cref="EndOfStreamException"></exception>
123
        public override void Close()
124
        {
125
        }
2✔
126

127
        /// <summary>
128
        /// Reads the bytes from the current stream and writes them to another stream, using a
129
        /// specified buffer size.
130
        /// </summary>
131
        /// <param name="destination">
132
        /// The stream to which the contents of the current stream will be copied.
133
        /// </param>
134
        /// <param name="bufferSize">
135
        /// The size of the buffer. This value must be greater than zero. The default size is 81920.
136
        /// </param>
137
        /// <exception cref="EndOfStreamException"></exception>
138
        public override void CopyTo(Stream destination, int bufferSize)
139
        {
140
        }
41✔
141

142
        /// <summary>
143
        /// Copies to asynchronous.
144
        /// </summary>
145
        /// <param name="destination">The destination.</param>
146
        /// <param name="bufferSize">Size of the buffer.</param>
147
        /// <param name="cancellationToken">The cancellation token.</param>
148
        /// <returns></returns>
149
        /// <exception cref="EndOfStreamException"></exception>
150
        public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) => Task.CompletedTask;
220✔
151

152
        /// <summary>
153
        /// Waits for the pending asynchronous read operation to complete. (Consider using <see
154
        /// cref="M:System.IO.FileStream.ReadAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)"/> instead.)
155
        /// </summary>
156
        /// <param name="asyncResult">
157
        /// The reference to the pending asynchronous request to wait for.
158
        /// </param>
159
        /// <returns>
160
        /// The number of bytes read from the stream, between 0 and the number of bytes you
161
        /// requested. Streams only return 0 at the end of the stream, otherwise, they should block
162
        /// until at least 1 byte is available.
163
        /// </returns>
164
        /// <exception cref="FileNotFoundException"></exception>
165
        public override int EndRead(IAsyncResult asyncResult) => 0;
3✔
166

167
        /// <summary>
168
        /// Ends an asynchronous write operation and blocks until the I/O operation is complete.
169
        /// (Consider using <see
170
        /// cref="M:System.IO.FileStream.WriteAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)"/> instead.)
171
        /// </summary>
172
        /// <param name="asyncResult">The pending asynchronous I/O request.</param>
173
        /// <exception cref="FileNotFoundException"></exception>
174
        public override void EndWrite(IAsyncResult asyncResult)
175
        {
176
        }
3✔
177

178
        /// <summary>
179
        /// Clears buffers for this stream and causes any buffered data to be written to the file.
180
        /// </summary>
181
        /// <exception cref="FileNotFoundException"></exception>
182
        public override void Flush()
183
        {
184
        }
2✔
185

186
        /// <summary>
187
        /// Clears buffers for this stream and causes any buffered data to be written to the file,
188
        /// and also clears all intermediate file buffers.
189
        /// </summary>
190
        /// <param name="flushToDisk">
191
        /// <see langword="true"/> to flush all intermediate file buffers; otherwise, <see langword="false"/>.
192
        /// </param>
193
        /// <exception cref="FileNotFoundException"></exception>
194
        public override void Flush(bool flushToDisk)
195
        {
196
        }
3✔
197

198
        /// <summary>
199
        /// Asynchronously clears all buffers for this stream, causes any buffered data to be
200
        /// written to the underlying device, and monitors cancellation requests.
201
        /// </summary>
202
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
203
        /// <returns>A task that represents the asynchronous flush operation.</returns>
204
        /// <exception cref="FileNotFoundException"></exception>
205
        public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask;
220✔
206

207
        /// <summary>
208
        /// Obtains a lifetime service object to control the lifetime policy for this instance.
209
        /// </summary>
210
        /// <returns>
211
        /// An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease"/> used to
212
        /// control the lifetime policy for this instance. This is the current lifetime service
213
        /// object for this instance if one exists; otherwise, a new lifetime service object
214
        /// initialized to the value of the <see
215
        /// cref="P:System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseManagerPollTime"/> property.
216
        /// </returns>
217
        [Obsolete("This Remoting API is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0010", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
218
        public override object InitializeLifetimeService() => null!;
2✔
219

220
        /// <summary>
221
        /// Prevents other processes from reading from or writing to the <see cref="T:System.IO.FileStream"/>.
222
        /// </summary>
223
        /// <param name="position">
224
        /// The beginning of the range to lock. The value of this parameter must be equal to or
225
        /// greater than zero (0).
226
        /// </param>
227
        /// <param name="length">The range to be locked.</param>
228
        public override void Lock(long position, long length)
229
        {
230
        }
11✔
231

232
        /// <summary>
233
        /// Reads a block of bytes from the stream and writes the data in a given buffer.
234
        /// </summary>
235
        /// <param name="array">
236
        /// When this method returns, contains the specified byte array with the values between
237
        /// <paramref name="offset"/> and ( <paramref name="offset"/> + <paramref name="count"/> - 1
238
        /// <c>)</c> replaced by the bytes read from the current source.
239
        /// </param>
240
        /// <param name="offset">
241
        /// The byte offset in <paramref name="array"/> at which the read bytes will be placed.
242
        /// </param>
243
        /// <param name="count">The maximum number of bytes to read.</param>
244
        /// <returns>
245
        /// The total number of bytes read into the buffer. This might be less than the number of
246
        /// bytes requested if that number of bytes are not currently available, or zero if the end
247
        /// of the stream is reached.
248
        /// </returns>
249
        /// <exception cref="FileNotFoundException"></exception>
250
        public override int Read(byte[] array, int offset, int count) => 0;
11✔
251

252
        /// <summary>
253
        /// Reads the specified buffer.
254
        /// </summary>
255
        /// <param name="buffer">The buffer.</param>
256
        /// <returns></returns>
257
        /// <exception cref="FileNotFoundException"></exception>
258
        public override int Read(Span<byte> buffer) => 0;
11✔
259

260
        /// <summary>
261
        /// Asynchronously reads a sequence of bytes from the current file stream and writes them to
262
        /// a byte array beginning at a specified offset, advances the position within the file
263
        /// stream by the number of bytes read, and monitors cancellation requests.
264
        /// </summary>
265
        /// <param name="buffer">The buffer to write the data into.</param>
266
        /// <param name="offset">
267
        /// The byte offset in <paramref name="buffer"/> at which to begin writing data from the stream.
268
        /// </param>
269
        /// <param name="count">The maximum number of bytes to read.</param>
270
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
271
        /// <returns>
272
        /// A task that represents the asynchronous read operation and wraps the total number of
273
        /// bytes read into the buffer. The result value can be less than the number of bytes
274
        /// requested if the number of bytes currently available is less than the requested number,
275
        /// or it can be 0 (zero) if the end of the stream has been reached.
276
        /// </returns>
277
        /// <exception cref="FileNotFoundException"></exception>
278
        public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => Task.FromResult(0);
220✔
279

280
        /// <summary>
281
        /// Reads the asynchronous.
282
        /// </summary>
283
        /// <param name="buffer">The buffer.</param>
284
        /// <param name="cancellationToken">The cancellation token.</param>
285
        /// <returns></returns>
286
        /// <exception cref="FileNotFoundException"></exception>
287
        public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) => new(0);
220✔
288

289
        /// <summary>
290
        /// Reads a byte from the file and advances the read position one byte.
291
        /// </summary>
292
        /// <returns>
293
        /// The byte, cast to an <see cref="T:System.Int32"/>, or -1 if the end of the stream has
294
        /// been reached.
295
        /// </returns>
296
        /// <exception cref="FileNotFoundException"></exception>
297
        public override int ReadByte() => 0;
2✔
298

299
        /// <summary>
300
        /// Sets the current position of this stream to the given value.
301
        /// </summary>
302
        /// <param name="offset">
303
        /// The point relative to <paramref name="origin"/> from which to begin seeking.
304
        /// </param>
305
        /// <param name="origin">
306
        /// Specifies the beginning, the end, or the current position as a reference point for
307
        /// <paramref name="offset"/>, using a value of type <see cref="T:System.IO.SeekOrigin"/>.
308
        /// </param>
309
        /// <returns>The new position in the stream.</returns>
310
        /// <exception cref="FileNotFoundException"></exception>
311
        public override long Seek(long offset, SeekOrigin origin) => 0;
11✔
312

313
        /// <summary>
314
        /// Sets the length of this stream to the given value.
315
        /// </summary>
316
        /// <param name="value">The new length of the stream.</param>
317
        public override void SetLength(long value)
318
        {
319
        }
2✔
320

321
        /// <summary>
322
        /// Allows access by other processes to all or part of a file that was previously locked.
323
        /// </summary>
324
        /// <param name="position">The beginning of the range to unlock.</param>
325
        /// <param name="length">The range to be unlocked.</param>
326
        public override void Unlock(long position, long length)
327
        {
328
        }
2✔
329

330
        /// <summary>
331
        /// Writes a block of bytes to the file stream.
332
        /// </summary>
333
        /// <param name="array">The buffer containing data to write to the stream.</param>
334
        /// <param name="offset">
335
        /// The zero-based byte offset in <paramref name="array"/> from which to begin copying bytes
336
        /// to the stream.
337
        /// </param>
338
        /// <param name="count">The maximum number of bytes to write.</param>
339
        /// <exception cref="FileNotFoundException"></exception>
340
        public override void Write(byte[] array, int offset, int count)
341
        {
342
        }
2✔
343

344
        /// <summary>
345
        /// Writes the specified buffer.
346
        /// </summary>
347
        /// <param name="buffer">The buffer.</param>
348
        /// <exception cref="FileNotFoundException"></exception>
349
        public override void Write(ReadOnlySpan<byte> buffer)
350
        {
351
        }
2✔
352

353
        /// <summary>
354
        /// Asynchronously writes a sequence of bytes to the current stream, advances the current
355
        /// position within this stream by the number of bytes written, and monitors cancellation requests.
356
        /// </summary>
357
        /// <param name="buffer">The buffer to write data from.</param>
358
        /// <param name="offset">
359
        /// The zero-based byte offset in <paramref name="buffer"/> from which to begin copying
360
        /// bytes to the stream.
361
        /// </param>
362
        /// <param name="count">The maximum number of bytes to write.</param>
363
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
364
        /// <returns>A task that represents the asynchronous write operation.</returns>
365
        /// <exception cref="FileNotFoundException"></exception>
366
        public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => Task.CompletedTask;
220✔
367

368
        /// <summary>
369
        /// Writes the asynchronous.
370
        /// </summary>
371
        /// <param name="buffer">The buffer.</param>
372
        /// <param name="cancellationToken">The cancellation token.</param>
373
        /// <returns></returns>
374
        /// <exception cref="FileNotFoundException"></exception>
375
        public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) => new();
220✔
376

377
        /// <summary>
378
        /// Writes a byte to the current position in the file stream.
379
        /// </summary>
380
        /// <param name="value">A byte to write to the stream.</param>
381
        /// <exception cref="FileNotFoundException"></exception>
382
        public override void WriteByte(byte value)
383
        {
384
        }
2✔
385

386
        /// <summary>
387
        /// Finalizes an instance of the <see cref="FaultyFileStream"/> class.
388
        /// </summary>
389
        ~EmptyFileStream()
390
        {
391
            foreach (FileCurator.Interfaces.IFile File in new FileCurator.DirectoryInfo("./Mecha/").EnumerateFiles())
6!
392
            {
393
                try
394
                {
395
                    _ = File.Delete();
×
396
                }
×
397
                catch { }
×
398
            }
399
        }
6✔
400
    }
401
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc