Immidiate ui reflection for calendar events and some more error handling.
This commit is contained in:
@@ -32,8 +32,10 @@ public sealed class CreateCalendarEventRequestTests
|
||||
|
||||
recipient.Added.Should().ContainSingle();
|
||||
recipient.Deleted.Should().ContainSingle();
|
||||
recipient.Added[0].Id.Should().Be(request.LocalCalendarItemId!.Value);
|
||||
recipient.Deleted[0].Id.Should().Be(request.LocalCalendarItemId!.Value);
|
||||
recipient.Added[0].CalendarItem.Id.Should().Be(request.LocalCalendarItemId!.Value);
|
||||
recipient.Deleted[0].CalendarItem.Id.Should().Be(request.LocalCalendarItemId!.Value);
|
||||
recipient.Added[0].Source.Should().Be(EntityUpdateSource.ClientUpdated);
|
||||
recipient.Deleted[0].Source.Should().Be(EntityUpdateSource.ClientReverted);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -117,11 +119,11 @@ public sealed class CreateCalendarEventRequestTests
|
||||
IRecipient<CalendarItemAdded>,
|
||||
IRecipient<CalendarItemDeleted>
|
||||
{
|
||||
public List<CalendarItem> Added { get; } = [];
|
||||
public List<CalendarItem> Deleted { get; } = [];
|
||||
public List<CalendarItemAdded> Added { get; } = [];
|
||||
public List<CalendarItemDeleted> Deleted { get; } = [];
|
||||
|
||||
public void Receive(CalendarItemAdded message) => Added.Add(message.CalendarItem);
|
||||
public void Receive(CalendarItemAdded message) => Added.Add(message);
|
||||
|
||||
public void Receive(CalendarItemDeleted message) => Deleted.Add(message.CalendarItem);
|
||||
public void Receive(CalendarItemDeleted message) => Deleted.Add(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public sealed class MailRequestStateTests
|
||||
|
||||
mailCopy.IsRead.Should().BeFalse();
|
||||
recipient.Updated.Should().HaveCount(2);
|
||||
recipient.Updated[0].Source.Should().Be(MailUpdateSource.ClientUpdated);
|
||||
recipient.Updated[1].Source.Should().Be(MailUpdateSource.ClientReverted);
|
||||
recipient.Updated[0].Source.Should().Be(EntityUpdateSource.ClientUpdated);
|
||||
recipient.Updated[1].Source.Should().Be(EntityUpdateSource.ClientReverted);
|
||||
recipient.Updated[1].UpdatedMail.IsRead.Should().BeFalse();
|
||||
}
|
||||
finally
|
||||
@@ -56,8 +56,8 @@ public sealed class MailRequestStateTests
|
||||
|
||||
mailCopy.IsFlagged.Should().BeFalse();
|
||||
recipient.Updated.Should().HaveCount(2);
|
||||
recipient.Updated[0].Source.Should().Be(MailUpdateSource.ClientUpdated);
|
||||
recipient.Updated[1].Source.Should().Be(MailUpdateSource.ClientReverted);
|
||||
recipient.Updated[0].Source.Should().Be(EntityUpdateSource.ClientUpdated);
|
||||
recipient.Updated[1].Source.Should().Be(EntityUpdateSource.ClientReverted);
|
||||
recipient.Updated[1].UpdatedMail.IsFlagged.Should().BeFalse();
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
using FluentAssertions;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Core.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace Wino.Core.Tests.Services;
|
||||
|
||||
public class SynchronizationResultTests
|
||||
{
|
||||
[Fact]
|
||||
public void Mail_result_merge_issues_should_mark_success_as_partial_and_set_exception()
|
||||
{
|
||||
var result = MailSynchronizationResult.Completed([]);
|
||||
var issues = new[]
|
||||
{
|
||||
new SynchronizationIssue
|
||||
{
|
||||
Message = "Create event failed",
|
||||
OperationType = "RequestExecution",
|
||||
Severity = SynchronizerErrorSeverity.Fatal
|
||||
}
|
||||
};
|
||||
|
||||
result.MergeIssues(issues);
|
||||
|
||||
result.CompletedState.Should().Be(SynchronizationCompletedState.PartiallyCompleted);
|
||||
result.Issues.Should().ContainSingle();
|
||||
result.Exception.Should().NotBeNull();
|
||||
result.Exception!.Message.Should().Be("Create event failed");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Calendar_result_merge_issues_should_mark_success_as_partial_and_preserve_issue()
|
||||
{
|
||||
var result = CalendarSynchronizationResult.Empty;
|
||||
var issues = new[]
|
||||
{
|
||||
new SynchronizationIssue
|
||||
{
|
||||
Message = "Calendar API rate limit",
|
||||
OperationType = "CalendarSync",
|
||||
Severity = SynchronizerErrorSeverity.Transient
|
||||
}
|
||||
};
|
||||
|
||||
result.MergeIssues(issues);
|
||||
|
||||
result.CompletedState.Should().Be(SynchronizationCompletedState.PartiallyCompleted);
|
||||
result.Issues.Should().ContainSingle(issue => issue.Message == "Calendar API rate limit");
|
||||
result.Exception.Should().NotBeNull();
|
||||
result.Exception!.Message.Should().Be("Calendar API rate limit");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Error_factory_should_record_handled_metadata_on_context()
|
||||
{
|
||||
var factory = new SynchronizerErrorHandlingFactory();
|
||||
factory.RegisterHandler(new TestErrorHandler());
|
||||
|
||||
var context = new SynchronizerErrorContext
|
||||
{
|
||||
ErrorMessage = "Handled sync error"
|
||||
};
|
||||
|
||||
var handled = await factory.HandleErrorAsync(context);
|
||||
|
||||
handled.Should().BeTrue();
|
||||
context.WasHandled.Should().BeTrue();
|
||||
context.HandledBy.Should().Be(nameof(TestErrorHandler));
|
||||
}
|
||||
|
||||
private sealed class TestErrorHandler : ISynchronizerErrorHandler
|
||||
{
|
||||
public bool CanHandle(SynchronizerErrorContext error) => true;
|
||||
|
||||
public Task<bool> HandleAsync(SynchronizerErrorContext error) => Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user