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

chore: clean up overloads, update obsolete and add new SendFindRequestAsync method #328

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions src/FMData.Rest/FileMakerRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public async Task<IResponse> LogoutAsync()

#region Special Implementations
/// <inheritdoc />
[Obsolete("Use SendAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/326")]
[Obsolete("Use SendFindRequestAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/328")]
public override async Task<IEnumerable<T>> FindAsync<T>(
string layout,
Dictionary<string, string> req)
Expand Down Expand Up @@ -309,7 +309,7 @@ public override async Task<IEnumerable<T>> FindAsync<T>(
/// </summary>
/// <param name="req">The find request field/value dictionary to pass into FileMaker server.</param>
/// <returns>A <see cref="Dictionary{String,String}"/> wrapped in a FindResponse containing both record data and portal data.</returns>
[Obsolete("Use SendAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/326")]
[Obsolete("Use SendFindRequestAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/328")]
public override async Task<IFindResponse<Dictionary<string, string>>> SendAsync(IFindRequest<Dictionary<string, string>> req)
{
if (string.IsNullOrEmpty(req.Layout)) throw new ArgumentException("Layout is required on the request.");
Expand Down Expand Up @@ -543,7 +543,7 @@ public override async Task<IResponse> SendAsync(IDeleteRequest req)
}

/// <inheritdoc />
public override async Task<(IEnumerable<TResponse>, DataInfoModel)> SendAsync<TResponse, TRequest>(
public override async Task<(IEnumerable<TResponse>, DataInfoModel)> SendFindRequestAsync<TResponse, TRequest>(
IFindRequest<TRequest> req,
Func<TResponse, int, object> fmId = null,
Func<TResponse, int, object> modId = null)
Expand Down
6 changes: 3 additions & 3 deletions src/FMData.Xml/FileMakerXmlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ public override Task<T> GetByFileMakerIdAsync<T>(string layout, int fileMakerId,
/// <summary>
/// Find a record using a dictionary of input parameters.
/// </summary>
[Obsolete("Use SendAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/326")]
[Obsolete("Use SendFindRequestAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/328")]
public override Task<IFindResponse<Dictionary<string, string>>> SendAsync(IFindRequest<Dictionary<string, string>> req)
{
throw new NotImplementedException();
}

/// <inheritdoc />
[Obsolete("Use SendAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/326")]
[Obsolete("Use SendFindRequestAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/328")]
public override Task<IEnumerable<T>> FindAsync<T>(
string layout,
Dictionary<string, string> req)
Expand Down Expand Up @@ -181,7 +181,7 @@ public override async Task<IEditResponse> SendAsync<T>(IEditRequest<T> req)
}

/// <inheritdoc />
public override async Task<(IEnumerable<TResponse>, DataInfoModel)> SendAsync<TResponse, TRequest>(
public override async Task<(IEnumerable<TResponse>, DataInfoModel)> SendFindRequestAsync<TResponse, TRequest>(
IFindRequest<TRequest> req,
Func<TResponse, int, object> fmId = null,
Func<TResponse, int, object> modId = null)
Expand Down
10 changes: 5 additions & 5 deletions src/FMData/FileMakerApiClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public Task<IResponse> DeleteAsync(
/// <summary>
/// Send a Find Record request to the FileMaker API.
/// </summary>
[Obsolete("Use SendAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/326")]
[Obsolete("Use SendFindRequestAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/328")]
public abstract Task<IFindResponse<Dictionary<string, string>>> SendAsync(IFindRequest<Dictionary<string, string>> req);

/// <summary>
Expand All @@ -652,7 +652,7 @@ public virtual async Task<IEnumerable<T>> SendAsync<T>(
Func<T, int, object> fmId,
Func<T, int, object> modId) where T : class, new()
{
var (data, _) = await SendAsync<T, T>(req, fmId, modId).ConfigureAwait(false);
var (data, _) = await SendFindRequestAsync(req, fmId, modId).ConfigureAwait(false);
return data;
}

Expand All @@ -663,19 +663,19 @@ public virtual async Task<IEnumerable<T>> SendAsync<T>(
Func<T, int, object> fmId = null,
Func<T, int, object> modId = null) where T : class, new()
{
return await SendAsync<T, T>(req, fmId, modId).ConfigureAwait(false);
return await SendFindRequestAsync(req, fmId, modId).ConfigureAwait(false);
}

/// <inheritdoc />
public abstract Task<(IEnumerable<TResponse>, DataInfoModel)> SendAsync<TResponse, TRequest>(
public abstract Task<(IEnumerable<TResponse>, DataInfoModel)> SendFindRequestAsync<TResponse, TRequest>(
IFindRequest<TRequest> req,
Func<TResponse, int, object> fmId,
Func<TResponse, int, object> modId) where TResponse : class, new();

#endregion

/// <inheritdoc />
[Obsolete("Use SendAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/326")]
[Obsolete("Use SendFindRequestAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/328")]
public abstract Task<IEnumerable<T>> FindAsync<T>(string layout, Dictionary<string, string> req);

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/FMData/IFileMakerApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public interface IFileMakerApiClient
/// <param name="layout"></param>
/// <param name="req"></param>
/// <returns></returns>
[Obsolete("Use SendAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/326")]
[Obsolete("Use SendFindRequestAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/328")]
Task<IEnumerable<T>> FindAsync<T>(string layout, Dictionary<string, string> req);
#endregion

Expand Down Expand Up @@ -444,7 +444,7 @@ Task<IEditResponse> UpdateContainerAsync(
/// Find a record or records matching the request.
/// </summary>
/// <param name="req">Find request.</param>
[Obsolete("Use SendAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/326")]
[Obsolete("Use SendFindRequestAsync<TResponse, TRequest>() instead. See also: https://github.com/fuzzzerd/fmdata/pull/328")]
Task<IFindResponse<Dictionary<string, string>>> SendAsync(IFindRequest<Dictionary<string, string>> req);

/// <summary>
Expand Down Expand Up @@ -501,7 +501,7 @@ Task<IEnumerable<T>> SendAsync<T>(
/// <returns>An <see cref="IEnumerable{T}"/> matching the request parameters.</returns>
/// <remarks>The data info portion of the response is always returned when correctly parsed.</remarks>
/// <remarks>This method allows using separate Request and Response generics, which is useful when querying with dynamic input, but static output.</remarks>
Task<(IEnumerable<TResponse>, DataInfoModel)> SendAsync<TResponse, TRequest>(
Task<(IEnumerable<TResponse>, DataInfoModel)> SendFindRequestAsync<TResponse, TRequest>(
IFindRequest<TRequest> req,
Func<TResponse, int, object> fmId,
Func<TResponse, int, object> modId) where TResponse : class, new();
Expand Down
34 changes: 30 additions & 4 deletions tests/FMData.Rest.Tests/Find.SendAsync.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ public async Task SendAsync_EmptyFind_ShouldReturnMany()
Assert.Equal(2, response.Count());
}

[Fact]
public async Task SendAsync_Using_Var_With_Mappers_ShouldReturnMany()
{
var fdc = FindTestsHelpers.GetMockedFDC();
Func<User, int, object> fMRecordIdMapper = (o, id) => o.FileMakerRecordId = id;
Func<User, int, object> fMModIdMapper = (o, id) => o.FileMakerRecordId = id;

var response = await fdc.SendAsync(new FindRequest<User> { Layout = "layout" }, fMRecordIdMapper, fMModIdMapper);

Assert.Equal(2, response.Count());
}

[Fact]
public async Task SendAsync_Explicit_Type_With_Mappers_ShouldReturnMany()
{
var fdc = FindTestsHelpers.GetMockedFDC();
Func<User, int, object> fMRecordIdMapper = (o, id) => o.FileMakerRecordId = id;
Func<User, int, object> fMModIdMapper = (o, id) => o.FileMakerRecordId = id;

IEnumerable<User> response;

response = await fdc.SendAsync(new FindRequest<User> { Layout = "layout" }, fMRecordIdMapper, fMModIdMapper);

Assert.Equal(2, response.Count());
}

[Fact]
[Obsolete]
public async Task SendAsync_FindWithoutQuery_ShouldConvertToGetRange_AndReturnMany()
Expand Down Expand Up @@ -308,7 +334,7 @@ public async Task SendAsync_Using_Dictionary_Find_Should_Have_DataInfo()
req.AddQuery(toFind, false);

// act
var (data, info) = await fdc.SendAsync<User, Dictionary<string, string>>(req, null, null);
var (data, info) = await fdc.SendFindRequestAsync<User, Dictionary<string, string>>(req, null, null);

// assert
Assert.NotEmpty(data);
Expand Down Expand Up @@ -339,7 +365,7 @@ public async Task SendAsync_Using_Dictionary_Find_Should_Have_DataInfo_OverloadO
req.AddQuery(toFind, false);

// act
var (data, info) = await fdc.SendAsync<User, Dictionary<string, string>>(req, IdMap, null);
var (data, info) = await fdc.SendFindRequestAsync<User, Dictionary<string, string>>(req, IdMap, null);

// assert
Assert.NotEmpty(data);
Expand Down Expand Up @@ -370,7 +396,7 @@ public async Task SendAsync_Using_Dictionary_Find_Should_Have_DataInfo_OverloadT
req.AddQuery(toFind, false);

// act
var (data, info) = await fdc.SendAsync<User, Dictionary<string, string>>(req, null, ModMap);
var (data, info) = await fdc.SendFindRequestAsync<User, Dictionary<string, string>>(req, null, ModMap);

// assert
Assert.NotEmpty(data);
Expand Down Expand Up @@ -401,7 +427,7 @@ public async Task SendAsync_Using_Dictionary_Find_Should_Have_DataInfo_OverloadT
req.AddQuery(toFind, false);

// act
var (data, info) = await fdc.SendAsync<User, Dictionary<string, string>>(req, IdMap, ModMap);
var (data, info) = await fdc.SendFindRequestAsync<User, Dictionary<string, string>>(req, IdMap, ModMap);

// assert
Assert.NotEmpty(data);
Expand Down