diff --git a/Sample/AnotherPage.xaml.cs b/Sample/AnotherPage.xaml.cs index e91d9fc..11d16af 100644 --- a/Sample/AnotherPage.xaml.cs +++ b/Sample/AnotherPage.xaml.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace Sample; + public partial class AnotherPage : ContentPage { public AnotherPage() { - InitializeComponent(); + this.InitializeComponent(); } } \ No newline at end of file diff --git a/Sample/App.xaml b/Sample/App.xaml index 1bbfcb4..ed460fe 100644 --- a/Sample/App.xaml +++ b/Sample/App.xaml @@ -1,7 +1,6 @@  diff --git a/Sample/EventPage.xaml.cs b/Sample/EventPage.xaml.cs index 12e61e9..5025b81 100644 --- a/Sample/EventPage.xaml.cs +++ b/Sample/EventPage.xaml.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace Sample; public partial class EventPage : ContentPage { public EventPage() { - InitializeComponent(); + this.InitializeComponent(); } } \ No newline at end of file diff --git a/tests/Shiny.Mediator.Tests/CacheRequestMiddlewareTests.cs b/tests/Shiny.Mediator.Tests/CacheRequestMiddlewareTests.cs index 40e26cd..7993ad2 100644 --- a/tests/Shiny.Mediator.Tests/CacheRequestMiddlewareTests.cs +++ b/tests/Shiny.Mediator.Tests/CacheRequestMiddlewareTests.cs @@ -1,6 +1,71 @@ +using Microsoft.Extensions.Configuration; +using Shiny.Mediator.Middleware; + namespace Shiny.Mediator.Tests; public class CacheRequestMiddlewareTests { - + [Fact] + public async Task EndToEnd() + { + var conn = new MockConnectivity(); + var fs = new MockFileSystem(); + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + ["Cache:Shiny.Mediator.Tests.CacheRequest"] = "" + }) + .Build(); + + var middleware = new CacheRequestMiddleware(configuration, conn, fs); + + // TODO: test with ICacheItem + var request = new CacheRequest(); + + var result1 = await middleware.Process( + request, + () => Task.FromResult( + new CacheResponse(DateTimeOffset.UtcNow.Ticks) + ), + CancellationToken.None + ); + await Task.Delay(2000); + var result2 = await middleware.Process( + request, + () => Task.FromResult( + new CacheResponse(DateTimeOffset.UtcNow.Ticks) + ), + CancellationToken.None + ); + + // if cached + result1.Ticks.Should().Be(result2.Ticks); + } +} + + +public record CacheRequest : IRequest; +public record CacheResponse(long Ticks); + +public class MockConnectivity : IConnectivity +{ + public IEnumerable ConnectionProfiles { get; set; }// = ConnectionProfile.WiFi; + public NetworkAccess NetworkAccess { get; set; } + public event EventHandler? ConnectivityChanged; +} + +public class MockFileSystem : IFileSystem +{ + public Task OpenAppPackageFileAsync(string filename) + { + throw new NotImplementedException(); + } + + public Task AppPackageFileExistsAsync(string filename) + { + throw new NotImplementedException(); + } + + public string CacheDirectory { get; } = "."; + public string AppDataDirectory { get; } = "."; } \ No newline at end of file diff --git a/tests/Shiny.Mediator.Tests/Shiny.Mediator.Tests.csproj b/tests/Shiny.Mediator.Tests/Shiny.Mediator.Tests.csproj index 93022d6..8357047 100644 --- a/tests/Shiny.Mediator.Tests/Shiny.Mediator.Tests.csproj +++ b/tests/Shiny.Mediator.Tests/Shiny.Mediator.Tests.csproj @@ -16,6 +16,7 @@ + @@ -25,6 +26,7 @@ +