Skip to content

Commit

Permalink
LoadObjectListFnAsync with the specified orderBy field names.
Browse files Browse the repository at this point in the history
  • Loading branch information
o.nadymov committed Dec 29, 2024
1 parent 9670b68 commit 041ffd0
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/CIS.Service.Client.Tests/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text;
using CIS.Service.Client.Models;
using CIS.Service.Client.Tests.Models;
using Microsoft.Extensions.Configuration;

namespace CIS.Service.Client.Tests
Expand All @@ -25,5 +26,12 @@ public static ImpersonatingUser GetImpersonatingUser()

return user;
}

public static FnOrderByInfo GetOrderByInfo()
{
var info = _config.GetSection(nameof(FnOrderByInfo)).Get<FnOrderByInfo>();

return info;
}
}
}
4 changes: 4 additions & 0 deletions src/CIS.Service.Client.Tests/Models/Employee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class Employee : IdentityObject, IBody
{
public string Name { get; set; }

public string DisplayName { get; set; }

public string Surname { get; set; }

public bool IsActive { get; set; }
Expand All @@ -16,5 +18,7 @@ public class Employee : IdentityObject, IBody
public DateTime DateReceipt { get; set; }

public DateTime? DateDismissal { get; set; }

public override string ToString() => DisplayName;
}
}
13 changes: 13 additions & 0 deletions src/CIS.Service.Client.Tests/Models/FnOrderByInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using CIS.Service.Client.Models;

namespace CIS.Service.Client.Tests.Models
{
public class FnOrderByInfo
{
public string FuncName { get; set; }

public string OrderByFields { get; set; }

public List<WebValue> Args { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -955,5 +955,22 @@ public async Task CreateByLegalPerson()
// Assert
Assert.Pass();
}

[Test]
public async Task LoadObjectListOrderByFnAsync()
{
// Arrange
var provider = ServiceProvider.GetService<IPersistentCisServiceProvider>();
var info = ConfigurationHelper.GetOrderByInfo();

// Act
var employees = await provider.LoadObjectListFnAsync<Employee>(info.FuncName, info.OrderByFields, info.Args?.Select(x => x.GetRealValue()).ToArray());

// Assert
Assert.Multiple(() =>
{
Assert.That(employees, Is.Not.Null);
});
}
}
}
11 changes: 11 additions & 0 deletions src/CIS.Service.Client.Tests/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,16 @@
"ImpersonatingUser": {
"Id": "00000000-1111-2222-3333-444444444444",
"LoginType": "Windows"
},

"FnOrderByInfo": {
"FuncName": "funcName",
"OrderByFields": "Field1, Field2 DESC",
"Args": [
{
"Value": "33333333-3333-3333-3333-333333333333",
"WebType": { "TypeName": "System.Guid, System.Private.CoreLib" }
}
]
}
}
32 changes: 32 additions & 0 deletions src/CIS.Service.Client/Models/WebLoadingFnOrderByCriteria.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Text.Json.Serialization;

namespace CIS.Service.Client.Models
{
/// <summary>
/// The container with full information for loading data from table valued functions with the specified orderBy field names with unnamed arguments.
/// </summary>
public class WebLoadingFnOrderByCriteria : WebLoadingSPCriteria
{
/// <summary>
/// Default constructor.
/// </summary>
public WebLoadingFnOrderByCriteria()
{
}

/// <summary>
/// Constructor with parameters.
/// </summary>
public WebLoadingFnOrderByCriteria(string storedProcedureName, string orderByFieldNames, object[] args)
: base(storedProcedureName, args)
{
OrderByFieldNames = orderByFieldNames;
}

/// <summary>
/// Gets or sets the orderBy field names.
/// </summary>
[JsonPropertyName("OrderByFieldNames")]
public string OrderByFieldNames { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public interface IPersistentCisServiceProvider
/// <returns>The persistent object list of specified class.</returns>
Task<List<T>> LoadObjectListFnAsync<T>(string funcName, params object[] args) where T : IdentityObject;

/// <summary>
/// Async loading the persistent object list of specified class from Table Valued Function with the specified orderBy field names.
/// </summary>
/// <param name="funcName">The name of Table Valued Function</param>
/// <param name="orderByFieldNames">The field names for orderBy statement (Field1, Field2 DESC, Field 3).</param>
/// <param name="args">The arguments of Table Valued Function.</param>
/// <returns>The persistent object list of specified class.</returns>
Task<List<T>> LoadObjectListFnAsync<T>(string funcName, string orderByFieldNames, params object[] args) where T : IdentityObject;

/// <summary>
/// Async loading the persistent object list of specified class from the specified function on C# code.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions src/CIS.Service.Client/Services/PersistentCisServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public async Task<List<T>> LoadObjectListFnAsync<T>(string funcName, params obje
return objList;
}

public async Task<List<T>> LoadObjectListFnAsync<T>(string funcName, string orderByFieldNames, params object[] args) where T : IdentityObject
{
var uri = new Uri(new Uri(Settings.WebAPIEndpointAddress), $"{_controllerName}/{typeof(T).Name}/LoadObjectListOrderByFn");

var webCriteria = new WebLoadingFnOrderByCriteria(funcName, orderByFieldNames, args);
var jsonModel = JsonHelper.ToJson(webCriteria);

var objList = await InvokeAsync<List<T>>(Settings, uri, HttpMethod.Post, jsonModel);

return objList;
}

public async Task<List<T>> LoadObjectListCodeFnAsync<T>(string funcName, params object[] args) where T : IdentityObject
{
var uri = new Uri(new Uri(Settings.WebAPIEndpointAddress), $"{_controllerName}/{typeof(T).Name}/LoadObjectListCodeFn");
Expand Down

0 comments on commit 041ffd0

Please # to comment.