-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting on cache unit tests + some cleanup
- Loading branch information
Showing
5 changed files
with
71 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
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 |
---|---|---|
@@ -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<string, string> | ||
{ | ||
["Cache:Shiny.Mediator.Tests.CacheRequest"] = "" | ||
}) | ||
.Build(); | ||
|
||
var middleware = new CacheRequestMiddleware<CacheRequest, CacheResponse>(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<CacheResponse>; | ||
public record CacheResponse(long Ticks); | ||
|
||
public class MockConnectivity : IConnectivity | ||
{ | ||
public IEnumerable<ConnectionProfile> ConnectionProfiles { get; set; }// = ConnectionProfile.WiFi; | ||
public NetworkAccess NetworkAccess { get; set; } | ||
public event EventHandler<ConnectivityChangedEventArgs>? ConnectivityChanged; | ||
} | ||
|
||
public class MockFileSystem : IFileSystem | ||
{ | ||
public Task<Stream> OpenAppPackageFileAsync(string filename) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<bool> AppPackageFileExistsAsync(string filename) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public string CacheDirectory { get; } = "."; | ||
public string AppDataDirectory { get; } = "."; | ||
} |
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