-
-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathInputFileContent.cs
More file actions
63 lines (52 loc) · 1.92 KB
/
Copy pathInputFileContent.cs
File metadata and controls
63 lines (52 loc) · 1.92 KB
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
using System.Text;
namespace Bunit;
/// <summary>
/// Represents a file which can be uploaded.
/// </summary>
public class InputFileContent
{
private InputFileContent(byte[] content, string? filename, DateTimeOffset? lastModified, string? contentType)
{
Content = content;
Filename = filename;
LastModified = lastModified;
ContentType = contentType;
}
internal byte[] Content { get; set; }
internal string? Filename { get; set; }
internal DateTimeOffset? LastModified { get; set; }
internal long Size => Content.Length;
internal string? ContentType { get; set; }
/// <summary>
/// Creates an <see cref="InputFileContent"/> instance which has string content.
/// </summary>
/// <param name="fileContent">The string content.</param>
/// <param name="fileName">The name of the file.</param>
/// <param name="lastChanged">The last modified date of the file.</param>
/// <param name="contentType">The mime type of the file.</param>
public static InputFileContent CreateFromText(
string fileContent,
string? fileName = null,
DateTimeOffset? lastChanged = null,
string? contentType = null)
{
ArgumentNullException.ThrowIfNull(fileContent);
return new InputFileContent(Encoding.Default.GetBytes(fileContent), fileName, lastChanged, contentType);
}
/// <summary>
/// Creates an <see cref="InputFileContent"/> instance which has binary content.
/// </summary>
/// <param name="fileContent">The binary content.</param>
/// <param name="fileName">The name of the file.</param>
/// <param name="lastChanged">The last modified date of the file.</param>
/// <param name="contentType">The mime type of the file.</param>
public static InputFileContent CreateFromBinary(
byte[] fileContent,
string? fileName = null,
DateTimeOffset? lastChanged = null,
string? contentType = null)
{
ArgumentNullException.ThrowIfNull(fileContent);
return new InputFileContent(fileContent, fileName, lastChanged, contentType);
}
}