openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
tests/Files/OpenAIFilesModelFactoryTests.cs
197lines · modecode
| 1 | using NUnit.Framework; |
| 2 | using OpenAI.Files; |
| 3 | using System; |
| 4 | using System.Collections.Generic; |
| 5 | using System.Linq; |
| 6 | |
| 7 | namespace OpenAI.Tests.Files; |
| 8 | |
| 9 | [Parallelizable(ParallelScope.All)] |
| 10 | [Category("Files")] |
| 11 | [Category("Smoke")] |
| 12 | public class OpenAIFilesModelFactoryTests |
| 13 | { |
| 14 | #pragma warning disable CS0618 |
| 15 | [Test] |
| 16 | public void FileDeletionResultWithNoPropertiesWorks() |
| 17 | { |
| 18 | FileDeletionResult fileDeletionResult = OpenAIFilesModelFactory.FileDeletionResult(); |
| 19 | |
| 20 | Assert.That(fileDeletionResult.FileId, Is.Null); |
| 21 | Assert.That(fileDeletionResult.Deleted, Is.EqualTo(false)); |
| 22 | } |
| 23 | |
| 24 | [Test] |
| 25 | public void FileDeletionResultWithFileIdWorks() |
| 26 | { |
| 27 | string fileId = "fileId"; |
| 28 | FileDeletionResult fileDeletionResult = OpenAIFilesModelFactory.FileDeletionResult(fileId: fileId); |
| 29 | |
| 30 | Assert.That(fileDeletionResult.FileId, Is.EqualTo(fileId)); |
| 31 | Assert.That(fileDeletionResult.Deleted, Is.EqualTo(false)); |
| 32 | } |
| 33 | |
| 34 | [Test] |
| 35 | public void FileDeletionResultWithDeletedWorks() |
| 36 | { |
| 37 | bool deleted = true; |
| 38 | FileDeletionResult fileDeletionResult = OpenAIFilesModelFactory.FileDeletionResult(deleted: deleted); |
| 39 | |
| 40 | Assert.That(fileDeletionResult.FileId, Is.Null); |
| 41 | Assert.That(fileDeletionResult.Deleted, Is.EqualTo(deleted)); |
| 42 | } |
| 43 | |
| 44 | [Test] |
| 45 | public void OpenAIFileInfoWithNoPropertiesWorks() |
| 46 | { |
| 47 | OpenAIFile openAIFileInfo = OpenAIFilesModelFactory.OpenAIFileInfo(); |
| 48 | |
| 49 | Assert.That(openAIFileInfo.Id, Is.Null); |
| 50 | Assert.That(openAIFileInfo.SizeInBytes, Is.Null); |
| 51 | Assert.That(openAIFileInfo.CreatedAt, Is.EqualTo(default(DateTimeOffset))); |
| 52 | Assert.That(openAIFileInfo.Filename, Is.Null); |
| 53 | Assert.That(openAIFileInfo.Purpose, Is.EqualTo(default(FilePurpose))); |
| 54 | Assert.That(openAIFileInfo.Status, Is.EqualTo(default(FileStatus))); |
| 55 | Assert.That(openAIFileInfo.StatusDetails, Is.Null); |
| 56 | } |
| 57 | #pragma warning restore CS0618 |
| 58 | |
| 59 | #pragma warning disable CS0618 |
| 60 | [Test] |
| 61 | public void OpenAIFileInfoWithIdWorks() |
| 62 | { |
| 63 | string id = "fileId"; |
| 64 | OpenAIFile openAIFileInfo = OpenAIFilesModelFactory.OpenAIFileInfo(id: id); |
| 65 | |
| 66 | Assert.That(openAIFileInfo.Id, Is.EqualTo(id)); |
| 67 | Assert.That(openAIFileInfo.SizeInBytes, Is.Null); |
| 68 | Assert.That(openAIFileInfo.CreatedAt, Is.EqualTo(default(DateTimeOffset))); |
| 69 | Assert.That(openAIFileInfo.Filename, Is.Null); |
| 70 | Assert.That(openAIFileInfo.Purpose, Is.EqualTo(default(FilePurpose))); |
| 71 | Assert.That(openAIFileInfo.Status, Is.EqualTo(default(FileStatus))); |
| 72 | Assert.That(openAIFileInfo.StatusDetails, Is.Null); |
| 73 | } |
| 74 | #pragma warning restore CS0618 |
| 75 | |
| 76 | #pragma warning disable CS0618 |
| 77 | [Test] |
| 78 | public void OpenAIFileInfoWithSizeInBytesWorks() |
| 79 | { |
| 80 | int sizeInBytes = 1025; |
| 81 | OpenAIFile openAIFile = OpenAIFilesModelFactory.OpenAIFileInfo(sizeInBytes: sizeInBytes); |
| 82 | |
| 83 | Assert.That(openAIFile.Id, Is.Null); |
| 84 | Assert.That(openAIFile.SizeInBytes, Is.EqualTo(sizeInBytes)); |
| 85 | Assert.That(openAIFile.CreatedAt, Is.EqualTo(default(DateTimeOffset))); |
| 86 | Assert.That(openAIFile.Filename, Is.Null); |
| 87 | Assert.That(openAIFile.Purpose, Is.EqualTo(default(FilePurpose))); |
| 88 | Assert.That(openAIFile.Status, Is.EqualTo(default(FileStatus))); |
| 89 | Assert.That(openAIFile.StatusDetails, Is.Null); |
| 90 | } |
| 91 | #pragma warning restore CS0618 |
| 92 | |
| 93 | #pragma warning disable CS0618 |
| 94 | [Test] |
| 95 | public void OpenAIFileInfoWithCreatedAtWorks() |
| 96 | { |
| 97 | DateTimeOffset createdAt = DateTimeOffset.UtcNow; |
| 98 | OpenAIFile openAIFileInfo = OpenAIFilesModelFactory.OpenAIFileInfo(createdAt: createdAt); |
| 99 | |
| 100 | Assert.That(openAIFileInfo.Id, Is.Null); |
| 101 | Assert.That(openAIFileInfo.SizeInBytes, Is.Null); |
| 102 | Assert.That(openAIFileInfo.CreatedAt, Is.EqualTo(createdAt)); |
| 103 | Assert.That(openAIFileInfo.Filename, Is.Null); |
| 104 | Assert.That(openAIFileInfo.Purpose, Is.EqualTo(default(FilePurpose))); |
| 105 | Assert.That(openAIFileInfo.Status, Is.EqualTo(default(FileStatus))); |
| 106 | Assert.That(openAIFileInfo.StatusDetails, Is.Null); |
| 107 | } |
| 108 | #pragma warning restore CS0618 |
| 109 | |
| 110 | #pragma warning disable CS0618 |
| 111 | [Test] |
| 112 | public void OpenAIFileInfoWithFilenameWorks() |
| 113 | { |
| 114 | string filename = "file.png"; |
| 115 | OpenAIFile openAIFile = OpenAIFilesModelFactory.OpenAIFileInfo(filename: filename); |
| 116 | |
| 117 | Assert.That(openAIFile.Id, Is.Null); |
| 118 | Assert.That(openAIFile.SizeInBytes, Is.Null); |
| 119 | Assert.That(openAIFile.CreatedAt, Is.EqualTo(default(DateTimeOffset))); |
| 120 | Assert.That(openAIFile.Filename, Is.EqualTo(filename)); |
| 121 | Assert.That(openAIFile.Purpose, Is.EqualTo(default(FilePurpose))); |
| 122 | Assert.That(openAIFile.Status, Is.EqualTo(default(FileStatus))); |
| 123 | Assert.That(openAIFile.StatusDetails, Is.Null); |
| 124 | } |
| 125 | #pragma warning restore CS0618 |
| 126 | |
| 127 | #pragma warning disable CS0618 |
| 128 | [Test] |
| 129 | public void OpenAIFileInfoWithPurposeWorks() |
| 130 | { |
| 131 | FilePurpose purpose = FilePurpose.Vision; |
| 132 | OpenAIFile openAIFile = OpenAIFilesModelFactory.OpenAIFileInfo(purpose: purpose); |
| 133 | |
| 134 | Assert.That(openAIFile.Id, Is.Null); |
| 135 | Assert.That(openAIFile.SizeInBytes, Is.Null); |
| 136 | Assert.That(openAIFile.CreatedAt, Is.EqualTo(default(DateTimeOffset))); |
| 137 | Assert.That(openAIFile.Filename, Is.Null); |
| 138 | Assert.That(openAIFile.Purpose, Is.EqualTo(purpose)); |
| 139 | Assert.That(openAIFile.Status, Is.EqualTo(default(FileStatus))); |
| 140 | Assert.That(openAIFile.StatusDetails, Is.Null); |
| 141 | } |
| 142 | #pragma warning restore CS0618 |
| 143 | |
| 144 | #pragma warning disable CS0618 |
| 145 | [Test] |
| 146 | public void OpenAIFileInfoWithStatusWorks() |
| 147 | { |
| 148 | FileStatus status = FileStatus.Uploaded; |
| 149 | OpenAIFile openAIFile = OpenAIFilesModelFactory.OpenAIFileInfo(status: status); |
| 150 | |
| 151 | Assert.That(openAIFile.Id, Is.Null); |
| 152 | Assert.That(openAIFile.SizeInBytes, Is.Null); |
| 153 | Assert.That(openAIFile.CreatedAt, Is.EqualTo(default(DateTimeOffset))); |
| 154 | Assert.That(openAIFile.Filename, Is.Null); |
| 155 | Assert.That(openAIFile.Purpose, Is.EqualTo(default(FilePurpose))); |
| 156 | Assert.That(openAIFile.Status, Is.EqualTo(status)); |
| 157 | Assert.That(openAIFile.StatusDetails, Is.Null); |
| 158 | } |
| 159 | #pragma warning restore CS0618 |
| 160 | |
| 161 | #pragma warning disable CS0618 |
| 162 | [Test] |
| 163 | public void OpenAIFileInfoWithStatusDetailsWorks() |
| 164 | { |
| 165 | string statusDetails = "There's something off about this file."; |
| 166 | OpenAIFile openAIFile = OpenAIFilesModelFactory.OpenAIFileInfo(statusDetails: statusDetails); |
| 167 | |
| 168 | Assert.That(openAIFile.Id, Is.Null); |
| 169 | Assert.That(openAIFile.SizeInBytes, Is.Null); |
| 170 | Assert.That(openAIFile.CreatedAt, Is.EqualTo(default(DateTimeOffset))); |
| 171 | Assert.That(openAIFile.Filename, Is.Null); |
| 172 | Assert.That(openAIFile.Purpose, Is.EqualTo(default(FilePurpose))); |
| 173 | Assert.That(openAIFile.Status, Is.EqualTo(default(FileStatus))); |
| 174 | Assert.That(openAIFile.StatusDetails, Is.EqualTo(statusDetails)); |
| 175 | } |
| 176 | #pragma warning restore CS0618 |
| 177 | |
| 178 | [Test] |
| 179 | public void OpenAIFileInfoCollectionWithNoPropertiesWorks() |
| 180 | { |
| 181 | OpenAIFileCollection openAIFileInfoCollection = OpenAIFilesModelFactory.OpenAIFileCollection(); |
| 182 | |
| 183 | Assert.That(openAIFileInfoCollection.Count, Is.EqualTo(0)); |
| 184 | } |
| 185 | |
| 186 | [Test] |
| 187 | public void OpenAIFileInfoCollectionWithItemsWorks() |
| 188 | { |
| 189 | IEnumerable<OpenAIFile> items = [ |
| 190 | OpenAIFilesModelFactory.OpenAIFileInfo(id: "firstFile"), |
| 191 | OpenAIFilesModelFactory.OpenAIFileInfo(id: "secondFile") |
| 192 | ]; |
| 193 | OpenAIFileCollection openAIFileCollection = OpenAIFilesModelFactory.OpenAIFileCollection(items: items); |
| 194 | |
| 195 | Assert.That(openAIFileCollection.SequenceEqual(items), Is.True); |
| 196 | } |
| 197 | } |
| 198 | |