Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface IUserService

Task<T?> GetSystemDataAsync<T>(Guid userId, string systemId);

Task<Dictionary<Guid, T>> GetSystemListDataAsync<T>(IEnumerable<Guid> userIds, string systemId);
Task<Dictionary<Guid, T?>> GetSystemListDataAsync<T>(IEnumerable<Guid> userIds, string systemId);

Task<bool> DisableAsync(DisableUserModel user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ public async Task UpsertSystemDataAsync<T>(string systemId, T data)
return dataList.FirstOrDefault().Value ?? default;
}

public async Task<Dictionary<Guid, T>> GetSystemListDataAsync<T>(IEnumerable<Guid> userIds, string systemId)
public async Task<Dictionary<Guid, T?>> GetSystemListDataAsync<T>(IEnumerable<Guid> userIds, string systemId)
{
var requestUri = $"api/user/systemData/byIds";
var data = await _caller.PostAsync<Dictionary<Guid, T>>(requestUri, new GetSystemDataModel { UserIds = userIds.ToList(), SystemId = systemId }) ?? new();
return data;
var data = await _caller.PostAsync<Dictionary<Guid, string>>(requestUri, new GetSystemDataModel { UserIds = userIds.ToList(), SystemId = systemId }) ?? new();
return data.ToDictionary(d => d.Key, d => typeof(T) == typeof(string) ? (T)(object)d.Value : JsonSerializer.Deserialize<T?>(d.Value));
}

public async Task<bool> DisableAsync(DisableUserModel user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ public async Task TestIntGetUserSystemDataAsync(string systemId)
var data = 1;
var requestUri = $"api/user/systemData/byIds";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.PostAsync<Dictionary<Guid, int>>(requestUri, It.IsAny<GetSystemDataModel>(), default))
.ReturnsAsync(new Dictionary<Guid, int>() { { userId, data } }).Verifiable();
caller.Setup(provider => provider.PostAsync<Dictionary<Guid, string>>(requestUri, It.IsAny<GetSystemDataModel>(), default))
.ReturnsAsync(new Dictionary<Guid, string>() { { userId, data.ToString() } }).Verifiable();
var userContext = new Mock<IUserContext>();
userContext.Setup(user => user.GetUserId<Guid>()).Returns(userId).Verifiable();
var userService = GetUserService(caller, userContext);
Expand All @@ -506,35 +506,15 @@ public async Task TestObjectGetUserSystemDataAsync(string systemId)
};
var requestUri = $"api/user/systemData/byIds";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.PostAsync<Dictionary<Guid, SystemData>>(requestUri, It.IsAny<GetSystemDataModel>(), default))
.ReturnsAsync(new Dictionary<Guid, SystemData>() { { userId, data } }).Verifiable();
caller.Setup(provider => provider.PostAsync<Dictionary<Guid, string>>(requestUri, It.IsAny<GetSystemDataModel>(), default))
.ReturnsAsync(new Dictionary<Guid, string>() { { userId, JsonSerializer.Serialize(data) } }).Verifiable();
var userContext = new Mock<IUserContext>();
userContext.Setup(user => user.GetUserId<Guid>()).Returns(userId).Verifiable();
var userService = GetUserService(caller, userContext);
var result = await userService.GetSystemDataAsync<SystemData>(systemId);
Assert.IsTrue(result is not null);
}

[TestMethod]
[DataRow("masa-auth")]
public async Task TestGetUserSystemDataAsync(string systemId)
{
var userIds = new List<Guid> { Guid.NewGuid() };
var data = new SystemData
{
Name = "name",
Value = "value"
};
var requestUri = $"api/user/systemData/byIds";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.GetAsync<object, string>(requestUri, new { userIds = string.Join(',', userIds), systemId }, default))
.ReturnsAsync(JsonSerializer.Serialize(data)).Verifiable();
var userContext = new Mock<IUserContext>();
var userService = GetUserService(caller, userContext);
var result = await userService.GetSystemListDataAsync<SystemData>(userIds, systemId);
Assert.IsTrue(result is not null);
}

[TestMethod]
[DataRow("masa-auth")]
public async Task TestIntUpsertSystemDataAsync(string systemId)
Expand Down