Skip to content

Commit

Permalink
fix(featured): ensure onlyFeatured is serialized correctly in all eve…
Browse files Browse the repository at this point in the history
…ntualities (#195)

fixes #192 .. again

Co-authored-by: GuVAnj8Gv3RJ <[email protected]>
  • Loading branch information
GuVAnj8Gv3RJ and GuVAnj8Gv3RJ authored Sep 3, 2023
1 parent 345c569 commit ad92485
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
9 changes: 9 additions & 0 deletions AccountDownloader/Services/AppCloudService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Threading.Tasks;
using BaseX;
using CloudX.Shared;
using Microsoft.Extensions.Logging;

Expand All @@ -22,9 +23,17 @@ public AppCloudService(CloudXInterface? cloudInterface, ILogger? logger)
_interface = cloudInterface ?? throw new NullReferenceException("Cannot run without a CloudX Interface");
this.logger = logger ?? throw new NullReferenceException("Cannot run without a Logger");

UniLog.OnLog += UniLog_OnLog;

_interface.UserUpdated += Profile.UpdateUser;
}

// Lets us see inside cloudx
private void UniLog_OnLog(string obj)
{
this.logger.LogDebug(obj);
}

public AuthenticationState AuthState { get; private set; }

public IUserProfile Profile { get; private set; } = new AppCloudUserProfile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public virtual async IAsyncEnumerable<IEnumerable<Record>> GetRecords(string own
if (from != null)
searchParams.MinDate = from.Value;

var search = new PaginatedRecordSearch<Record>(searchParams, Cloud);
var search = new PaginatedRecordSearch<Record>(searchParams, Cloud, this.Logger);

var count = 0;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using AccountDownloaderLibrary.Models;
using CloudX.Shared;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace AccountDownloaderLibrary.Implementations;

Expand All @@ -12,9 +14,12 @@ namespace AccountDownloaderLibrary.Implementations;
public bool HasMoreResults { get; private set; }
public int Offset { get; private set; } = 0;

public PaginatedRecordSearch(AccountDownloaderSearchParameters searchParameters, CloudXInterface cloud)
private ILogger Logger;

public PaginatedRecordSearch(AccountDownloaderSearchParameters searchParameters, CloudXInterface cloud, ILogger logger)
{
this.searchParameters = searchParameters;
this.Logger = logger;
this.cloud = cloud;
HasMoreResults = true;
}
Expand All @@ -27,8 +32,7 @@ public Task<CloudResult<SearchResults<R>>> FindRecords(AccountDownloaderSearchPa
public async Task<IEnumerable<R>> Next()
{
searchParameters.Offset = Offset;
searchParameters.Count = searchParameters.Count;
searchParameters.OnlyFeatured = null;

CloudResult<SearchResults<R>> cloudResult = await FindRecords(searchParameters).ConfigureAwait(continueOnCapturedContext: false);
if (cloudResult.IsOK)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public class AccountDownloaderSearchParameters : SearchParameters
{
[JsonProperty(PropertyName = "onlyFeatured", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("onlyFeatured")]
[System.Text.Json.Serialization.JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault | JsonIgnoreCondition.WhenWritingDefault)]
public new bool? OnlyFeatured { get; set; } = null;
}
19 changes: 18 additions & 1 deletion AcountDownloaderLibrary.Tests/SearchParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,24 @@ public void TestFeaturedNullNET()

deSerialize = JsonConvert.DeserializeObject<AccountDownloaderSearchParameters>(jsonA);

Assert.IsFalse(deSerialize?.OnlyFeatured, "OnlyFeatured was included and should be false");
InOutNewtonsoft(np)
.Should()
.BeEquivalentTo(InOutNewtonsoft(ap));
}

[TestMethod]
public void TestFeaturedSerializedToLiteralNull()
{
var ap = new AccountDownloaderSearchParameters();
var json = JsonConvert.SerializeObject(ap);

ap.OnlyFeatured = null;

json.Should().NotContain("\"onlyFeatured\":null");

json = System.Text.Json.JsonSerializer.Serialize(ap);

json.Should().NotContain("\"onlyFeatured\":null");

}
}

0 comments on commit ad92485

Please sign in to comment.