-
Notifications
You must be signed in to change notification settings - Fork 51
Move Raven ID out of persisence contract #5705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rbev
wants to merge
4
commits into
master
Choose a base branch
from
rhys/notifications
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4fe7aa5
Add test coverage for notification data store, move raven ID out of p…
rbev 2323f66
Disable setting email field, update broken test
rbev 0bc8ee0
Change IDataSessionManager to IAsyncDisposable
rbev caf1b04
Remove unused raven cache timeout override
rbev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
9 changes: 9 additions & 0 deletions
9
src/ServiceControl.Persistence.RavenDB/Editing/NotificationSettingsDocument.cs
This file contains hidden or 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,9 @@ | ||
| namespace ServiceControl.Persistence.RavenDB.Editing; | ||
|
|
||
| using Notifications; | ||
|
|
||
| class NotificationsSettingsDocument | ||
| { | ||
| public string Id { get; set; } | ||
| public EmailNotifications Email { get; set; } = new(); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
167 changes: 167 additions & 0 deletions
167
src/ServiceControl.Persistence.Tests/NotificationsDataStoreTests.cs
This file contains hidden or 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,167 @@ | ||
| namespace ServiceControl.Persistence.Tests; | ||
|
|
||
| using System.Threading.Tasks; | ||
| using NUnit.Framework; | ||
|
|
||
| class NotificationsDataStoreTests : PersistenceTestBase | ||
| { | ||
| [Test, CancelAfter(30_000)] | ||
| public async Task LoadSettings_returns_defaults_when_no_settings_exist() | ||
| { | ||
| await using var manager = await NotificationsStore.CreateNotificationsManager(); | ||
|
|
||
| var settings = await manager.LoadSettings(); | ||
|
|
||
| using (Assert.EnterMultipleScope()) | ||
| { | ||
| Assert.That(settings, Is.Not.Null); | ||
| Assert.That(settings.Email, Is.Not.Null); | ||
| Assert.That(settings.Email.Enabled, Is.False); | ||
| Assert.That(settings.Email.SmtpServer, Is.Null); | ||
| Assert.That(settings.Email.SmtpPort, Is.Null); | ||
| Assert.That(settings.Email.EnableTLS, Is.False); | ||
| Assert.That(settings.Email.From, Is.Null); | ||
| Assert.That(settings.Email.To, Is.Null); | ||
| Assert.That(settings.Email.AuthenticationAccount, Is.Null); | ||
| Assert.That(settings.Email.AuthenticationPassword, Is.Null); | ||
| } | ||
| } | ||
|
|
||
| [Test, CancelAfter(30_000)] | ||
| public async Task SaveChanges_persists_email_settings_round_trip() | ||
| { | ||
| await using (var manager = await NotificationsStore.CreateNotificationsManager()) | ||
| { | ||
| var settings = await manager.LoadSettings(); | ||
|
|
||
| settings.Email.Enabled = true; | ||
| settings.Email.SmtpServer = "smtp.example.com"; | ||
| settings.Email.SmtpPort = 587; | ||
| settings.Email.EnableTLS = true; | ||
| settings.Email.From = "sc@example.com"; | ||
| settings.Email.To = "ops@example.com"; | ||
| settings.Email.AuthenticationAccount = "user"; | ||
| settings.Email.AuthenticationPassword = "p@ssw0rd"; | ||
|
|
||
| await manager.SaveChanges(); | ||
| } | ||
|
|
||
| await CompleteDatabaseOperation(); | ||
|
|
||
| await using var verifyManager = await NotificationsStore.CreateNotificationsManager(); | ||
| var loaded = await verifyManager.LoadSettings(); | ||
|
|
||
| using (Assert.EnterMultipleScope()) | ||
| { | ||
| Assert.That(loaded.Email.Enabled, Is.True); | ||
| Assert.That(loaded.Email.SmtpServer, Is.EqualTo("smtp.example.com")); | ||
| Assert.That(loaded.Email.SmtpPort, Is.EqualTo(587)); | ||
| Assert.That(loaded.Email.EnableTLS, Is.True); | ||
| Assert.That(loaded.Email.From, Is.EqualTo("sc@example.com")); | ||
| Assert.That(loaded.Email.To, Is.EqualTo("ops@example.com")); | ||
| Assert.That(loaded.Email.AuthenticationAccount, Is.EqualTo("user")); | ||
| Assert.That(loaded.Email.AuthenticationPassword, Is.EqualTo("p@ssw0rd")); | ||
| } | ||
| } | ||
|
|
||
| [Test, CancelAfter(30_000)] | ||
| public async Task Toggling_enabled_is_persisted() | ||
| { | ||
| await using (var manager = await NotificationsStore.CreateNotificationsManager()) | ||
| { | ||
| var settings = await manager.LoadSettings(); | ||
| settings.Email.Enabled = true; | ||
| await manager.SaveChanges(); | ||
| } | ||
|
|
||
| await CompleteDatabaseOperation(); | ||
|
|
||
| await using (var manager = await NotificationsStore.CreateNotificationsManager()) | ||
| { | ||
| var settings = await manager.LoadSettings(); | ||
| Assert.That(settings.Email.Enabled, Is.True); | ||
|
|
||
| settings.Email.Enabled = false; | ||
| await manager.SaveChanges(); | ||
| } | ||
|
|
||
| await CompleteDatabaseOperation(); | ||
|
|
||
| await using var verifyManager = await NotificationsStore.CreateNotificationsManager(); | ||
| var final = await verifyManager.LoadSettings(); | ||
| Assert.That(final.Email.Enabled, Is.False); | ||
| } | ||
|
|
||
| [Test, CancelAfter(30_000)] | ||
| public async Task LoadSettings_returns_previously_saved_settings() | ||
| { | ||
| await using (var manager = await NotificationsStore.CreateNotificationsManager()) | ||
| { | ||
| var settings = await manager.LoadSettings(); | ||
| settings.Email.SmtpServer = "configured.server"; | ||
| settings.Email.SmtpPort = 2525; | ||
| await manager.SaveChanges(); | ||
| } | ||
|
|
||
| await CompleteDatabaseOperation(); | ||
|
|
||
| await using var manager2 = await NotificationsStore.CreateNotificationsManager(); | ||
| var loaded = await manager2.LoadSettings(); | ||
|
|
||
| using (Assert.EnterMultipleScope()) | ||
| { | ||
| Assert.That(loaded.Email.SmtpServer, Is.EqualTo("configured.server")); | ||
| Assert.That(loaded.Email.SmtpPort, Is.EqualTo(2525)); | ||
| // Untouched fields keep their defaults | ||
| Assert.That(loaded.Email.Enabled, Is.False); | ||
| Assert.That(loaded.Email.EnableTLS, Is.False); | ||
| } | ||
| } | ||
|
|
||
| [Test, CancelAfter(30_000)] | ||
| public async Task Updating_individual_fields_preserves_others() | ||
| { | ||
| await using (var manager = await NotificationsStore.CreateNotificationsManager()) | ||
| { | ||
| var settings = await manager.LoadSettings(); | ||
| settings.Email.Enabled = true; | ||
| settings.Email.SmtpServer = "original.smtp"; | ||
| settings.Email.SmtpPort = 25; | ||
| settings.Email.EnableTLS = false; | ||
| settings.Email.From = "from@orig"; | ||
| settings.Email.To = "to@orig"; | ||
| settings.Email.AuthenticationAccount = "acct"; | ||
| settings.Email.AuthenticationPassword = "secret"; | ||
| await manager.SaveChanges(); | ||
| } | ||
|
|
||
| await CompleteDatabaseOperation(); | ||
|
|
||
| await using (var manager = await NotificationsStore.CreateNotificationsManager()) | ||
| { | ||
| var settings = await manager.LoadSettings(); | ||
| settings.Email.SmtpServer = "updated.smtp"; | ||
| settings.Email.EnableTLS = true; | ||
| await manager.SaveChanges(); | ||
| } | ||
|
|
||
| await CompleteDatabaseOperation(); | ||
|
|
||
| await using var verifyManager = await NotificationsStore.CreateNotificationsManager(); | ||
| var loaded = await verifyManager.LoadSettings(); | ||
|
|
||
| using (Assert.EnterMultipleScope()) | ||
| { | ||
| // Updated fields | ||
| Assert.That(loaded.Email.SmtpServer, Is.EqualTo("updated.smtp")); | ||
| Assert.That(loaded.Email.EnableTLS, Is.True); | ||
| // Preserved fields | ||
| Assert.That(loaded.Email.Enabled, Is.True); | ||
| Assert.That(loaded.Email.SmtpPort, Is.EqualTo(25)); | ||
| Assert.That(loaded.Email.From, Is.EqualTo("from@orig")); | ||
| Assert.That(loaded.Email.To, Is.EqualTo("to@orig")); | ||
| Assert.That(loaded.Email.AuthenticationAccount, Is.EqualTo("acct")); | ||
| Assert.That(loaded.Email.AuthenticationPassword, Is.EqualTo("secret")); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,11 +1,10 @@ | ||
| namespace ServiceControl.Persistence | ||
| { | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Notifications; | ||
|
|
||
| public interface INotificationsManager : IDataSessionManager | ||
| { | ||
| Task<NotificationsSettings> LoadSettings(TimeSpan? cacheTimeout = null); | ||
| Task<NotificationsSettings> LoadSettings(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should Raven have its own version of
EmailNotifications?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That depends, if we are going to just serialise
EmailNotificationsas the type in the SQL settings table then they will effectively be the same.I'm not opposed to it, but EmailNotifications is a pretty simple POCO and unlikely to change significantly so I don't know how much value will be gained from replicating it in each persistence along with object-object mapping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough