fix(sms): S2 review — add DeleteSmsConfigurationAsync + schema/repo tests + doc nit
This commit is contained in:
@@ -124,6 +124,12 @@ public interface INotificationRepository
|
|||||||
/// <returns>A task representing the asynchronous operation.</returns>
|
/// <returns>A task representing the asynchronous operation.</returns>
|
||||||
Task UpdateSmsConfigurationAsync(SmsConfiguration smsConfiguration, CancellationToken cancellationToken = default);
|
Task UpdateSmsConfigurationAsync(SmsConfiguration smsConfiguration, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
/// <summary>Deletes an SMS configuration by ID.</summary>
|
||||||
|
/// <param name="id">The SMS configuration ID.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
/// <returns>A task representing the asynchronous operation.</returns>
|
||||||
|
Task DeleteSmsConfigurationAsync(int id, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>Saves pending changes to the repository.</summary>
|
/// <summary>Saves pending changes to the repository.</summary>
|
||||||
/// <param name="cancellationToken">Cancellation token.</param>
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
/// <returns>The number of entities saved.</returns>
|
/// <returns>The number of entities saved.</returns>
|
||||||
|
|||||||
+1
-2
@@ -57,8 +57,7 @@ public class NotificationRecipientConfiguration : IEntityTypeConfiguration<Notif
|
|||||||
|
|
||||||
public class SmsConfigurationConfiguration : IEntityTypeConfiguration<SmsConfiguration>
|
public class SmsConfigurationConfiguration : IEntityTypeConfiguration<SmsConfiguration>
|
||||||
{
|
{
|
||||||
/// <summary>Configures the EF Core mapping for <see cref="SmsConfiguration"/>.</summary>
|
/// <inheritdoc />
|
||||||
/// <param name="builder">The entity type builder.</param>
|
|
||||||
public void Configure(EntityTypeBuilder<SmsConfiguration> builder)
|
public void Configure(EntityTypeBuilder<SmsConfiguration> builder)
|
||||||
{
|
{
|
||||||
builder.HasKey(s => s.Id);
|
builder.HasKey(s => s.Id);
|
||||||
|
|||||||
@@ -104,6 +104,13 @@ public class NotificationRepository : INotificationRepository
|
|||||||
public Task UpdateSmsConfigurationAsync(SmsConfiguration smsConfiguration, CancellationToken cancellationToken = default)
|
public Task UpdateSmsConfigurationAsync(SmsConfiguration smsConfiguration, CancellationToken cancellationToken = default)
|
||||||
{ _context.Set<SmsConfiguration>().Update(smsConfiguration); return Task.CompletedTask; }
|
{ _context.Set<SmsConfiguration>().Update(smsConfiguration); return Task.CompletedTask; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task DeleteSmsConfigurationAsync(int id, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var entity = await _context.Set<SmsConfiguration>().FindAsync(new object[] { id }, cancellationToken);
|
||||||
|
if (entity != null) _context.Set<SmsConfiguration>().Remove(entity);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
public async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||||
=> await _context.SaveChangesAsync(cancellationToken);
|
=> await _context.SaveChangesAsync(cancellationToken);
|
||||||
|
|||||||
@@ -211,6 +211,10 @@ public class SiteNotificationRepository : INotificationRepository
|
|||||||
public Task UpdateSmsConfigurationAsync(SmsConfiguration smsConfiguration, CancellationToken cancellationToken = default)
|
public Task UpdateSmsConfigurationAsync(SmsConfiguration smsConfiguration, CancellationToken cancellationToken = default)
|
||||||
=> throw new NotSupportedException("Managed via artifact deployment from Central");
|
=> throw new NotSupportedException("Managed via artifact deployment from Central");
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task DeleteSmsConfigurationAsync(int id, CancellationToken cancellationToken = default)
|
||||||
|
=> throw new NotSupportedException("Managed via artifact deployment from Central");
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
public Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||||
=> throw new NotSupportedException("Managed via artifact deployment from Central");
|
=> throw new NotSupportedException("Managed via artifact deployment from Central");
|
||||||
|
|||||||
@@ -226,6 +226,34 @@ public class NotificationRepositoryTests : IDisposable
|
|||||||
Assert.Null(await _repository.GetNotificationListByIdAsync(list.Id));
|
Assert.Null(await _repository.GetNotificationListByIdAsync(list.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task AddSmsConfiguration_RoundTrips()
|
||||||
|
{
|
||||||
|
var sms = new SmsConfiguration("ACtest123", "+14155550100");
|
||||||
|
await _repository.AddSmsConfigurationAsync(sms);
|
||||||
|
await _repository.SaveChangesAsync();
|
||||||
|
|
||||||
|
var loaded = await _repository.GetSmsConfigurationAsync();
|
||||||
|
Assert.NotNull(loaded);
|
||||||
|
Assert.Equal("ACtest123", loaded!.AccountSid);
|
||||||
|
Assert.Equal("+14155550100", loaded.FromNumber);
|
||||||
|
|
||||||
|
// Update a field and verify GetAllSmsConfigurationsAsync reflects it.
|
||||||
|
loaded.FromNumber = "+14155550199";
|
||||||
|
await _repository.UpdateSmsConfigurationAsync(loaded);
|
||||||
|
await _repository.SaveChangesAsync();
|
||||||
|
|
||||||
|
var all = await _repository.GetAllSmsConfigurationsAsync();
|
||||||
|
Assert.Single(all);
|
||||||
|
Assert.Equal("+14155550199", all[0].FromNumber);
|
||||||
|
|
||||||
|
// Delete and verify removal.
|
||||||
|
await _repository.DeleteSmsConfigurationAsync(loaded.Id);
|
||||||
|
await _repository.SaveChangesAsync();
|
||||||
|
|
||||||
|
Assert.Null(await _repository.GetSmsConfigurationAsync());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task NotificationList_PersistsType()
|
public async Task NotificationList_PersistsType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public class DbContextTests : IDisposable
|
|||||||
Assert.NotNull(_context.NotificationLists);
|
Assert.NotNull(_context.NotificationLists);
|
||||||
Assert.NotNull(_context.NotificationRecipients);
|
Assert.NotNull(_context.NotificationRecipients);
|
||||||
Assert.NotNull(_context.SmtpConfigurations);
|
Assert.NotNull(_context.SmtpConfigurations);
|
||||||
|
Assert.NotNull(_context.SmsConfigurations);
|
||||||
Assert.NotNull(_context.SharedScripts);
|
Assert.NotNull(_context.SharedScripts);
|
||||||
Assert.NotNull(_context.LdapGroupMappings);
|
Assert.NotNull(_context.LdapGroupMappings);
|
||||||
Assert.NotNull(_context.SiteScopeRules);
|
Assert.NotNull(_context.SiteScopeRules);
|
||||||
|
|||||||
Reference in New Issue
Block a user