-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into permissions
- Loading branch information
Showing
25 changed files
with
2,633 additions
and
1,188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
server/Korga.Tests/Migrations/09_PersonFilterList/InboxEmail.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
|
||
namespace Korga.Tests.Migrations.PersonFilterList; | ||
|
||
public class InboxEmail | ||
{ | ||
public long Id { get; set; } | ||
|
||
public long? DistributionListId { get; set; } | ||
public DistributionList? DistributionList { get; set; } | ||
|
||
public uint? UniqueId { get; set; } | ||
public required string Subject { get; set; } | ||
public required string From { get; set; } | ||
public string? Sender { get; set; } | ||
public string? ReplyTo { get; set; } | ||
public required string To { get; set; } | ||
public string? Receiver { get; set; } | ||
public byte[]? Header { get; set; } | ||
public byte[]? Body { get; set; } | ||
public DateTime DownloadTime { get; set; } | ||
public DateTime ProcessingCompletedTime { get; set; } | ||
} |
10 changes: 10 additions & 0 deletions
10
server/Korga.Tests/Migrations/10_NullableEmailHeaders/DatabaseContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Korga.Tests.Migrations.NullableEmailHeaders; | ||
|
||
public class DatabaseContext : DbContext | ||
{ | ||
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) { } | ||
|
||
public DbSet<InboxEmail> InboxEmails => Set<InboxEmail>(); | ||
} |
22 changes: 22 additions & 0 deletions
22
server/Korga.Tests/Migrations/10_NullableEmailHeaders/InboxEmail.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
|
||
namespace Korga.Tests.Migrations.NullableEmailHeaders; | ||
|
||
public class InboxEmail | ||
{ | ||
public long Id { get; set; } | ||
|
||
public long? DistributionListId { get; set; } | ||
|
||
public uint? UniqueId { get; set; } | ||
public string? Subject { get; set; } | ||
public string? From { get; set; } | ||
public string? Sender { get; set; } | ||
public string? ReplyTo { get; set; } | ||
public string? To { get; set; } | ||
public string? Receiver { get; set; } | ||
public byte[]? Header { get; set; } | ||
public byte[]? Body { get; set; } | ||
public DateTime DownloadTime { get; set; } | ||
public DateTime ProcessingCompletedTime { get; set; } | ||
} |
122 changes: 122 additions & 0 deletions
122
server/Korga.Tests/Migrations/10_NullableEmailHeadersMigrationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Korga.Tests.Migrations; | ||
|
||
public class NullableEmailHeadersMigrationTests : MigrationTestBase<PersonFilterList.DatabaseContext, NullableEmailHeaders.DatabaseContext> | ||
{ | ||
public NullableEmailHeadersMigrationTests(ITestOutputHelper testOutput) : base(testOutput) { } | ||
|
||
[Fact] | ||
public async Task TestUpgrade() | ||
{ | ||
PersonFilterList.InboxEmail reference = new() | ||
{ | ||
Id = 1, | ||
Subject = "Test", | ||
From = "[email protected]", | ||
To = "[email protected]", | ||
}; | ||
PersonFilterList.InboxEmail emptyFields = new() | ||
{ | ||
Id = 2, | ||
Subject = string.Empty, | ||
From = string.Empty, | ||
To = string.Empty, | ||
}; | ||
IMigrator migrator = databaseContext.GetInfrastructure().GetRequiredService<IMigrator>(); | ||
|
||
// Create database schema of last migration before the one to test | ||
await migrator.MigrateAsync("PersonFilterList"); | ||
|
||
// Add test data | ||
before.InboxEmails.Add(reference); | ||
before.InboxEmails.Add(emptyFields); | ||
await before.SaveChangesAsync(); | ||
|
||
// Run migration at test | ||
await migrator.MigrateAsync("NullableEmailHeaders"); | ||
|
||
// Verify that data has been migrated as expected | ||
List<NullableEmailHeaders.InboxEmail> inboxEmails = await after.InboxEmails.ToListAsync(); | ||
Assert.Contains(inboxEmails, email => email.Id == reference.Id); | ||
Assert.Contains(inboxEmails, email => email.Id == emptyFields.Id); | ||
Assert.Equal(2, inboxEmails.Count); | ||
} | ||
|
||
[Fact] | ||
public async Task TestDowngrade() | ||
{ | ||
NullableEmailHeaders.InboxEmail reference = new() | ||
{ | ||
Id = 1, | ||
Subject = "Test", | ||
From = "[email protected]", | ||
To = "[email protected]", | ||
}; | ||
NullableEmailHeaders.InboxEmail emptyFields = new() | ||
{ | ||
Id = 2, | ||
Subject = string.Empty, | ||
From = string.Empty, | ||
To = string.Empty, | ||
}; | ||
NullableEmailHeaders.InboxEmail nullSubject = new() | ||
{ | ||
Id = 3, | ||
Subject = null, | ||
From = "[email protected]", | ||
To = "[email protected]", | ||
}; | ||
NullableEmailHeaders.InboxEmail nullFrom = new() | ||
{ | ||
Id = 4, | ||
Subject = "Test", | ||
From = null, | ||
To = "[email protected]", | ||
}; | ||
NullableEmailHeaders.InboxEmail nullTo = new() | ||
{ | ||
Id = 5, | ||
Subject = "Test", | ||
From = "[email protected]", | ||
To = null, | ||
}; | ||
IMigrator migrator = databaseContext.GetInfrastructure().GetRequiredService<IMigrator>(); | ||
|
||
// Create database schema of the migration to test | ||
await migrator.MigrateAsync("NullableEmailHeaders"); | ||
|
||
// Add test data | ||
after.InboxEmails.Add(reference); | ||
after.InboxEmails.Add(emptyFields); | ||
after.InboxEmails.Add(nullSubject); | ||
after.InboxEmails.Add(nullFrom); | ||
after.InboxEmails.Add(nullTo); | ||
await after.SaveChangesAsync(); | ||
|
||
// Reset change tracker before upgrading the schema again to avoid caching | ||
after.ChangeTracker.Clear(); | ||
|
||
// Migrate to migration before the one to test and thereby revert it | ||
await migrator.MigrateAsync("PersonFilterList"); | ||
|
||
// Verify that data has been migrated as expected | ||
List<PersonFilterList.InboxEmail> inboxEmails = await before.InboxEmails.ToListAsync(); | ||
Assert.Contains(inboxEmails, email => email.Id == reference.Id); | ||
Assert.Contains(inboxEmails, email => email.Id == emptyFields.Id); | ||
Assert.DoesNotContain(inboxEmails, email => email.Id == nullSubject.Id); | ||
Assert.DoesNotContain(inboxEmails, email => email.Id == nullFrom.Id); | ||
Assert.DoesNotContain(inboxEmails, email => email.Id == nullTo.Id); | ||
Assert.Equal(2, inboxEmails.Count); | ||
|
||
// Upgrade database again to verify rollback worked | ||
await migrator.MigrateAsync("NullableEmailHeaders"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.