Skip to content

Commit bc77d16

Browse files
authored
Use strongly typed enums (#127)
* New strongly typed propertes of the Content: VersioningMode and InheritableVersioningMode. * ApprovingMode, InheritableApprovingMode * User.Gender and MaritalStatus * Fix tests. * Folder.PreviewEnabled * Task.Priority * Task.Status * Refactor. * Content.*Date nullable properties. * Generalize enum transformer methods.
1 parent cfd345a commit bc77d16

File tree

11 files changed

+1207
-72
lines changed

11 files changed

+1207
-72
lines changed

src/SenseNet.Client.IntegrationTests/ContentTests.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,6 @@ public class File : Content
208208
{
209209
public File(IRestCaller restCaller, ILogger<Content> logger) : base(restCaller, logger) { }
210210

211-
/*TODO: Use enum VersioningType, ApprovingType
212-
public enum VersioningType{Inherited, None, MajorOnly, MajorAndMinor}
213-
public enum ApprovingType{Inherited, False, True}
214-
public VersioningType VersioningMode { get; set; }
215-
public ApprovingType ApprovingMode { get; set; }
216-
*/
217-
public string[] VersioningMode { get; set; }
218-
public string[] ApprovingMode { get; set; }
219211
public string Version { get; set; }
220212
public Binary Binary { get; set; }
221213
}
@@ -243,8 +235,8 @@ await GetRepositoryCollection(
243235
};
244236

245237
var file = repository.CreateContent<File>(rootPath, null, fileName);
246-
file.VersioningMode = new[] { "3" }; // MajorAndMinor
247-
file.ApprovingMode = new[] { "2" }; // True
238+
file.VersioningMode = VersioningMode.MajorAndMinor;
239+
file.ApprovingMode = ApprovingEnabled.Yes;
248240
await file.SaveAsync(cancel).ConfigureAwait(false);
249241
await AssertFileVersion(repository, loadFileRequest, "V0.1.D", cancel);
250242

@@ -302,8 +294,8 @@ await GetRepositoryCollection(
302294
.GetRepositoryAsync("local", cancel).ConfigureAwait(false);
303295

304296
var file = repository.CreateContent<File>("/Root/Content", null, Guid.NewGuid().ToString());
305-
file.VersioningMode = new[] { "0" }; // Inherited
306-
file.ApprovingMode = new[] { "0" }; // Inherited
297+
file.VersioningMode = VersioningMode.Inherited;
298+
file.ApprovingMode = ApprovingEnabled.Inherited;
307299
await file.SaveAsync(cancel).ConfigureAwait(false);
308300
var fileId = file.Id;
309301
var loaded = await repository.LoadContentAsync(fileId, cancel).ConfigureAwait(false);
@@ -346,8 +338,8 @@ await GetRepositoryCollection(
346338
}
347339

348340
var file = repository.CreateContent<File>(source.Path, null, Guid.NewGuid().ToString());
349-
file.VersioningMode = new[] { "0" }; // Inherited
350-
file.ApprovingMode = new[] { "0" }; // Inherited
341+
file.VersioningMode = VersioningMode.Inherited;
342+
file.ApprovingMode = ApprovingEnabled.Inherited;
351343
await file.SaveAsync(cancel).ConfigureAwait(false);
352344
var fileId = file.Id;
353345
var fileText = Guid.NewGuid().ToString();
@@ -393,8 +385,8 @@ await GetRepositoryCollection(
393385
}
394386

395387
var file = repository.CreateContent<File>(source.Path, null, Guid.NewGuid().ToString());
396-
file.VersioningMode = new[] { "0" }; // Inherited
397-
file.ApprovingMode = new[] { "0" }; // Inherited
388+
file.VersioningMode = VersioningMode.Inherited;
389+
file.ApprovingMode = ApprovingEnabled.Inherited;
398390
await file.SaveAsync(cancel).ConfigureAwait(false);
399391
var fileId = file.Id;
400392
var fileText = Guid.NewGuid().ToString();

src/SenseNet.Client.IntegrationTests/UploadDownloadTests.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,6 @@ public class File : Content
182182
{
183183
public File(IRestCaller restCaller, ILogger<Content> logger) : base(restCaller, logger) { }
184184

185-
/*TODO: Use enum VersioningMode
186-
public enum VersioningType{Inherited, None, MajorOnly, MajorAndMinor}
187-
public VersioningType VersioningMode { get; set; }
188-
*/
189-
public string[] VersioningMode { get; set; }
190185
public string Version { get; set; }
191186
public Binary Binary { get; set; }
192187
}
@@ -311,29 +306,31 @@ await GetRepositoryCollection(
311306
var loadFileRequest = new LoadContentRequest
312307
{
313308
Path = filePath,
314-
Select = new[] { "Id", "Path", "Name", "Type", "Version", "VersioningMode", "Binary" }
309+
Select = new[] {"Id", "Path", "Name", "Type", "Version", "VersioningMode", "Binary"}
315310
};
316-
var uploadRequest = new UploadRequest { ParentPath = rootPath, ContentName = fileName };
311+
var uploadRequest = new UploadRequest {ParentPath = rootPath, ContentName = fileName};
317312

318313
// Prepare file versions
319314
var file = repository.CreateContent<File>(rootPath, null, fileName);
320-
file.VersioningMode = new[] { "3" }; // MajorAndMinor
315+
file.VersioningMode = VersioningMode.MajorAndMinor;
321316
await file.SaveAsync(cancel).ConfigureAwait(false);
322317

323318
await file.CheckOutAsync(cancel).ConfigureAwait(false); // V0.2.L
324319

325320
await using (var uploadStream = Tools.GenerateStreamFromString("File text 1"))
326-
uploadedResult = await repository.UploadAsync(uploadRequest, uploadStream, cancel).ConfigureAwait(false);
321+
uploadedResult =
322+
await repository.UploadAsync(uploadRequest, uploadStream, cancel).ConfigureAwait(false);
327323

328324
await file.CheckInAsync(cancel).ConfigureAwait(false); //V0.2.D
329325

330326
await file.CheckOutAsync(cancel).ConfigureAwait(false); // V0.3.L
331327

332328
await using (var uploadStream = Tools.GenerateStreamFromString("File text 2"))
333-
uploadedResult = await repository.UploadAsync(uploadRequest, uploadStream, cancel).ConfigureAwait(false);
329+
uploadedResult =
330+
await repository.UploadAsync(uploadRequest, uploadStream, cancel).ConfigureAwait(false);
334331

335332
await repository.GetResponseStringAsync(
336-
new ODataRequest(repository.Server) { ContentId = file.Id, ActionName = "Publish" }, // V1.0.A
333+
new ODataRequest(repository.Server) {ContentId = file.Id, ActionName = "Publish"}, // V1.0.A
337334
HttpMethod.Post, cancel).ConfigureAwait(false);
338335

339336
Assert.AreEqual(file.Id, uploadedResult.Id);
@@ -343,7 +340,8 @@ await repository.GetResponseStringAsync(
343340
await file.CheckOutAsync(cancel).ConfigureAwait(false); // V1.1.L
344341

345342
await using (var uploadStream = Tools.GenerateStreamFromString("File text 3"))
346-
uploadedResult = await repository.UploadAsync(uploadRequest, uploadStream, cancel).ConfigureAwait(false);
343+
uploadedResult =
344+
await repository.UploadAsync(uploadRequest, uploadStream, cancel).ConfigureAwait(false);
347345

348346
await file.CheckInAsync(cancel).ConfigureAwait(false); //V1.1.D
349347

@@ -352,21 +350,21 @@ await repository.GetResponseStringAsync(
352350
string? lastMajorText = null; // V1.0
353351
string? file_V0_2Text = null; // V0.2
354352
await repository.DownloadAsync(
355-
request: new DownloadRequest { ContentId = file.Id },
353+
request: new DownloadRequest {ContentId = file.Id},
356354
responseProcessor: async (stream, _) =>
357355
{
358356
using var reader = new StreamReader(stream);
359357
lastDraftText = await reader.ReadToEndAsync();
360358
}, cancel).ConfigureAwait(false);
361359
await repository.DownloadAsync(
362-
request: new DownloadRequest { ContentId = file.Id, Version = "LastMajor" },
360+
request: new DownloadRequest {ContentId = file.Id, Version = "LastMajor"},
363361
responseProcessor: async (stream, _) =>
364362
{
365363
using var reader = new StreamReader(stream);
366364
lastMajorText = await reader.ReadToEndAsync();
367365
}, cancel).ConfigureAwait(false);
368366
await repository.DownloadAsync(
369-
request: new DownloadRequest { ContentId = file.Id, Version = "V0.2" },
367+
request: new DownloadRequest {ContentId = file.Id, Version = "V0.2"},
370368
responseProcessor: async (stream, _) =>
371369
{
372370
using var reader = new StreamReader(stream);
@@ -378,6 +376,10 @@ await repository.DownloadAsync(
378376
Assert.AreEqual("File text 2", lastMajorText);
379377
Assert.AreEqual("File text 1", file_V0_2Text);
380378
}
379+
catch (Exception e)
380+
{
381+
var q = 1;
382+
}
381383
finally
382384
{
383385
await repository.DeleteContentAsync(filePath, true, cancel);

0 commit comments

Comments
 (0)