Skip to content
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

housekeeping: Update nullability annotations #668

Merged
merged 18 commits into from
Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
DO NOT REMOVE THIS FILE
There is an issue where the nuget config local cache can play up.
Already had similar issues with the local cache and it containing netcore 3.1 packages.
https://github.com/actions/virtual-environments/issues/1090
-->
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
4 changes: 2 additions & 2 deletions src/Akavache.Core/Akavache.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="Splat" Version="10.*" />
<PackageReference Include="Splat" Version="11.*" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Akavache.Core/BlobCache/BlobCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static string ApplicationName
/// </summary>
public static IBlobCache LocalMachine
{
get => _unitTestLocalMachine ?? _localMachine ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService<IBlobCache>("LocalMachine");
get => _unitTestLocalMachine ?? _localMachine ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService<IBlobCache>("LocalMachine") ?? throw new InvalidOperationException("Unable to resolve LocalMachine cache. Make sure Akavache is initialized properly.");
set
{
if (ModeDetector.InUnitTestRunner())
Expand All @@ -103,7 +103,7 @@ public static IBlobCache LocalMachine
/// </summary>
public static IBlobCache UserAccount
{
get => _unitTestUserAccount ?? _userAccount ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService<IBlobCache>("UserAccount");
get => _unitTestUserAccount ?? _userAccount ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService<IBlobCache>("UserAccount") ?? throw new InvalidOperationException("Unable to resolve UserAccount cache. Make sure Akavache is initialized properly.");
set
{
if (ModeDetector.InUnitTestRunner())
Expand All @@ -124,7 +124,7 @@ public static IBlobCache UserAccount
/// </summary>
public static ISecureBlobCache Secure
{
get => _unitTestSecure ?? _secure ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService<ISecureBlobCache>();
get => _unitTestSecure ?? _secure ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService<ISecureBlobCache>() ?? throw new InvalidOperationException("Unable to resolve Secure cache. Make sure Akavache is initialized properly.");
set
{
if (ModeDetector.InUnitTestRunner())
Expand Down
2 changes: 1 addition & 1 deletion src/Akavache.Core/BlobCache/IObjectBlobCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IObjectBlobCache : IBlobCache
/// <typeparam name="T">The type of object associated with the blob.</typeparam>
/// <param name="key">The key to look up in the cache.</param>
/// <returns>A Future result representing the object in the cache.</returns>
IObservable<T> GetObject<T>(string key);
IObservable<T?> GetObject<T>(string key);

/// <summary>
/// Return all objects of a specific Type in the cache.
Expand Down
14 changes: 6 additions & 8 deletions src/Akavache.Core/HttpMixinExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Akavache
/// </summary>
public static class HttpMixinExtensions
{
private static IAkavacheHttpMixin HttpMixin => Locator.Current.GetService<IAkavacheHttpMixin>() ?? throw new InvalidOperationException("Unable to resolve IAkavacheHttpMixin, probably Akavache is not initialized.");

/// <summary>
/// Download data from an HTTP URL and insert the result into the
/// cache. If the data is already in the cache, this returns
Expand All @@ -28,8 +30,7 @@ public static class HttpMixinExtensions
/// <returns>The data downloaded from the URL.</returns>
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, string url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
var mixin = Locator.Current.GetService<IAkavacheHttpMixin>();
return mixin.DownloadUrl(blobCache, new Uri(url), headers, fetchAlways, absoluteExpiration);
return HttpMixin.DownloadUrl(blobCache, new Uri(url), headers, fetchAlways, absoluteExpiration);
}

/// <summary>
Expand All @@ -46,8 +47,7 @@ public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, string
/// <returns>The data downloaded from the URL.</returns>
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, Uri url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
var mixin = Locator.Current.GetService<IAkavacheHttpMixin>();
return mixin.DownloadUrl(blobCache, url, headers, fetchAlways, absoluteExpiration);
return HttpMixin.DownloadUrl(blobCache, url, headers, fetchAlways, absoluteExpiration);
}

/// <summary>
Expand All @@ -65,8 +65,7 @@ public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, Uri url
/// <returns>The data downloaded from the URL.</returns>
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, string key, string url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
var mixin = Locator.Current.GetService<IAkavacheHttpMixin>();
return mixin.DownloadUrl(blobCache, key, new Uri(url), headers, fetchAlways, absoluteExpiration);
return HttpMixin.DownloadUrl(blobCache, key, new Uri(url), headers, fetchAlways, absoluteExpiration);
}

/// <summary>
Expand All @@ -84,8 +83,7 @@ public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, string
/// <returns>The data downloaded from the URL.</returns>
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, string key, Uri url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
var mixin = Locator.Current.GetService<IAkavacheHttpMixin>();
return mixin.DownloadUrl(blobCache, key, url, headers, fetchAlways, absoluteExpiration);
return HttpMixin.DownloadUrl(blobCache, key, url, headers, fetchAlways, absoluteExpiration);
}
}
}
2 changes: 1 addition & 1 deletion src/Akavache.Drawing/Akavache.Drawing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Splat.Drawing" Version="10.*" />
<PackageReference Include="Splat.Drawing" Version="11.*" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion src/Akavache.Drawing/BitmapImageMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ private static IObservable<IBitmap> BytesToImage(byte[] compressedImage, float?
{
using (var ms = new MemoryStream(compressedImage))
{
return BitmapLoader.Current.Load(ms, desiredWidth, desiredHeight).ToObservable();
return BitmapLoader.Current.Load(ms, desiredWidth, desiredHeight).ToObservable()
.SelectMany(bitmap => bitmap is not null ?
Observable.Return(bitmap) :
Observable.Throw<IBitmap>(new IOException("Failed to load the bitmap!")));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Akavache.Mobile/Registrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public void Register(IMutableDependencyResolver resolver, IReadonlyDependencyRes

// NB: These correspond to the hacks in Akavache.Http's registrations
resolver.Register(
() => readonlyDependencyResolver.GetService<ISuspensionHost>().ShouldPersistState,
() => readonlyDependencyResolver.GetService<ISuspensionHost>()?.ShouldPersistState ?? throw new InvalidOperationException("Unable to resolve ISuspensionHost, probably ReactiveUI is not initialized."),
typeof(IObservable<IDisposable>),
"ShouldPersistState");

resolver.Register(
() => readonlyDependencyResolver.GetService<ISuspensionHost>().IsUnpausing,
() => readonlyDependencyResolver.GetService<ISuspensionHost>()?.IsUnpausing ?? throw new InvalidOperationException("Unable to resolve ISuspensionHost, probably ReactiveUI is not initialized."),
typeof(IObservable<Unit>),
"IsUnpausing");

Expand Down
2 changes: 1 addition & 1 deletion src/Akavache.Sqlite3/Akavache.Sqlite3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ItemGroup>
<PackageReference Include="SQLitePCLRaw.core" Version="2.0.4" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="Splat" Version="10.*" />
<PackageReference Include="Splat" Version="11.*" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
<PackageReference Include="System.Resources.ResourceManager" Version="4.3.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ public class SQLiteEncryptedBlobCache : SqlRawPersistentBlobCache, ISecureBlobCa
public SQLiteEncryptedBlobCache(string databaseFile, IEncryptionProvider? encryptionProvider = null, IScheduler? scheduler = null)
: base(databaseFile, scheduler)
{
_encryption = encryptionProvider ?? Locator.Current.GetService<IEncryptionProvider>();

if (_encryption is null)
{
throw new Exception("No IEncryptionProvider available. This should never happen, your DependencyResolver is broken");
}
_encryption = encryptionProvider ?? Locator.Current.GetService<IEncryptionProvider>() ?? throw new Exception("No IEncryptionProvider available. This should never happen, your DependencyResolver is broken");
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ public IObservable<byte[]> Get(string key)
? Observable.Return(cacheElements.First().Value)
: ExceptionHelper.ObservableThrowKeyNotFoundException<byte[]>(key);
})
#pragma warning disable CS8604 // Possible null reference argument.
.SelectMany(x => AfterReadFromDiskFilter(x, Scheduler))
#pragma warning restore CS8604 // Possible null reference argument.
.PublishLast().PermaRef();
}

Expand Down Expand Up @@ -320,9 +318,7 @@ public IObservable<Unit> InsertObject<T>(string key, T value, DateTimeOffset? ab
? Observable.Return(cacheElements.First().Value)
: ExceptionHelper.ObservableThrowKeyNotFoundException<byte[]>(key);
})
#pragma warning disable CS8604 // Possible null reference argument.
.SelectMany(x => AfterReadFromDiskFilter(x, Scheduler))
#pragma warning restore CS8604 // Possible null reference argument.
.SelectMany(DeserializeObject<T>)
.PublishLast().PermaRef();
}
Expand All @@ -349,9 +345,7 @@ public IObservable<IEnumerable<T>> GetAllObjects<T>()

return _initializer.SelectMany(_ => _opQueue.SelectTypes(new[] { typeFullName })
.SelectMany(x => x.ToObservable()
#pragma warning disable CS8604 // Possible null reference argument.
.SelectMany(y => AfterReadFromDiskFilter(y.Value, Scheduler))
#pragma warning restore CS8604 // Possible null reference argument.
.SelectMany(DeserializeObject<T>)
.Where(y => y is not null)
.Select(y => y!)
Expand Down Expand Up @@ -835,9 +829,7 @@ private byte[] SerializeObject<T>(T value)
}

var rawVal = serializer.Deserialize<T>(reader);
#pragma warning disable CS8604 // Possible null reference argument.
return Observable.Return(rawVal);
#pragma warning restore CS8604 // Possible null reference argument.
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace Akavache
public interface IObjectBlobCache : Akavache.IBlobCache, System.IDisposable
{
System.IObservable<System.Collections.Generic.IEnumerable<T>> GetAllObjects<T>();
System.IObservable<T> GetObject<T>(string key);
System.IObservable<T?> GetObject<T>(string key);
System.IObservable<System.DateTimeOffset?> GetObjectCreatedAt<T>(string key);
System.IObservable<System.Reactive.Unit> InsertObject<T>(string key, T value, System.DateTimeOffset? absoluteExpiration = default);
System.IObservable<System.Reactive.Unit> InvalidateAllObjects<T>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace Akavache
public interface IObjectBlobCache : Akavache.IBlobCache, System.IDisposable
{
System.IObservable<System.Collections.Generic.IEnumerable<T>> GetAllObjects<T>();
System.IObservable<T> GetObject<T>(string key);
System.IObservable<T?> GetObject<T>(string key);
System.IObservable<System.DateTimeOffset?> GetObjectCreatedAt<T>(string key);
System.IObservable<System.Reactive.Unit> InsertObject<T>(string key, T value, System.DateTimeOffset? absoluteExpiration = default);
System.IObservable<System.Reactive.Unit> InvalidateAllObjects<T>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace Akavache
public interface IObjectBlobCache : Akavache.IBlobCache, System.IDisposable
{
System.IObservable<System.Collections.Generic.IEnumerable<T>> GetAllObjects<T>();
System.IObservable<T> GetObject<T>(string key);
System.IObservable<T?> GetObject<T>(string key);
System.IObservable<System.DateTimeOffset?> GetObjectCreatedAt<T>(string key);
System.IObservable<System.Reactive.Unit> InsertObject<T>(string key, T value, System.DateTimeOffset? absoluteExpiration = default);
System.IObservable<System.Reactive.Unit> InvalidateAllObjects<T>();
Expand Down
8 changes: 4 additions & 4 deletions src/Akavache.Tests/Akavache.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Microsoft.Reactive.Testing" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageReference Include="Xunit.StaFact" Version="1.0.37" />
<PackageReference Include="ReactiveUI.Testing" Version="13.*" />
<PackageReference Include="Splat" Version="10.*" />
<PackageReference Include="Splat.Drawing" Version="10.*" />
<PackageReference Include="Splat" Version="11.*" />
<PackageReference Include="Splat.Drawing" Version="11.*" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.4" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="DiffEngine" Version="6.5.7" />
<PackageReference Include="DiffEngine" Version="6.6.1" />
<PackageReference Include="PublicApiGenerator" Version="10.2.0" />
<PackageReference Include="coverlet.msbuild" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
60 changes: 54 additions & 6 deletions src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,63 @@ public abstract class BlobCacheExtensionsTestBase
public async Task DownloadUrlTest()
{
string path;
using (Utility.WithEmptyDirectory(out path))
using (var fixture = CreateBlobCache(path))
{
var bytes = await fixture.DownloadUrl(@"http://httpbin.org/html").FirstAsync();
Assert.True(bytes.Length > 0);
}
}

/// <summary>
/// Tests to make sure the download Uri extension method overload performs correctly.
/// </summary>
/// <returns>A task to monitor the progress.</returns>
[Fact]
public async Task DownloadUriTest()
{
string path;
using (Utility.WithEmptyDirectory(out path))
using (var fixture = CreateBlobCache(path))
{
var fixture = CreateBlobCache(path);
using (fixture)
{
var bytes = await fixture.DownloadUrl(@"http://httpbin.org/html").FirstAsync();
Assert.True(bytes.Length > 0);
}
var bytes = await fixture.DownloadUrl(new Uri("http://httpbin.org/html")).FirstAsync();
Assert.True(bytes.Length > 0);
}
}

/// <summary>
/// Tests to make sure the download with key extension method overload performs correctly.
/// </summary>
/// <returns>A task to monitor the progress.</returns>
[Fact]
public async Task DownloadUrlWithKeyTest()
{
string path;
using (Utility.WithEmptyDirectory(out path))
using (var fixture = CreateBlobCache(path))
{
var key = Guid.NewGuid().ToString();
await fixture.DownloadUrl(key, "http://httpbin.org/html").FirstAsync();
var bytes = await fixture.Get(key);
Assert.True(bytes.Length > 0);
}
}

/// <summary>
/// Tests to make sure the download Uri with key extension method overload performs correctly.
/// </summary>
/// <returns>A task to monitor the progress.</returns>
[Fact]
public async Task DownloadUriWithKeyTest()
{
string path;
using (Utility.WithEmptyDirectory(out path))
using (var fixture = CreateBlobCache(path))
{
var key = Guid.NewGuid().ToString();
await fixture.DownloadUrl(key, new Uri("http://httpbin.org/html")).FirstAsync();
var bytes = await fixture.Get(key);
Assert.True(bytes.Length > 0);
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/Akavache.Tests/UtilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,17 @@ public void KeyedOperationQueueCorrectlyShutsDown()
op3.OnCompleted();
Assert.Equal(0, op3Result);
}

/// <summary>
/// Test to make sure the static caches are initialized.
/// </summary>
[Fact]
public void ShouldInitializeDefaultCaches()
{
Assert.NotNull(BlobCache.LocalMachine);
Assert.NotNull(BlobCache.UserAccount);
Assert.NotNull(BlobCache.InMemory);
Assert.NotNull(BlobCache.Secure);
}
}
}
2 changes: 1 addition & 1 deletion src/Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.3.37" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.194" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' != 'true' and '$(SourceLinkEnabled)' != 'false'">
Expand Down