-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
232 additions
and
434 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using content.domainservice; | ||
using content.repository; | ||
using Moq; | ||
using Qdrant.Client; | ||
using Qdrant.Client.Grpc; | ||
|
||
public class HistoryServiceTests | ||
{ | ||
[Fact] | ||
public async Task GetHistory_ReturnsVideos() | ||
{ | ||
// Arrange | ||
var mockHistoryRepo = new Mock<HistoryRepository>(null!); | ||
var mockClient = new Mock<QdrantClient>("localhost",default!,default!,default!,default!,default!); | ||
var mockDomainService = new Mock<IDomainService>(); | ||
var userId = 1L; | ||
var historyList = new List<long> { 1L, 2L }; | ||
var videoDtos = new List<VideoDto> { new VideoDto(), new VideoDto() }; | ||
|
||
mockHistoryRepo.Setup(x => x.GetHistorys(userId, It.IsAny<long>(), It.IsAny<int>())).ReturnsAsync(historyList); | ||
mockDomainService.Setup(x => x.FindAllByIds(historyList)).ReturnsAsync(videoDtos); | ||
|
||
var service = new HistoryService(mockHistoryRepo.Object, mockClient.Object, mockDomainService.Object); | ||
|
||
// Act | ||
var result = await service.GetHistory(userId); | ||
|
||
// Assert | ||
Assert.Equal(videoDtos, result.Items); | ||
} | ||
|
||
[Fact] | ||
public async Task AddHistory_ReturnsTrue() | ||
{ | ||
// Arrange | ||
var mockHistoryRepo = new Mock<HistoryRepository>(null!); | ||
var mockClient = new Mock<QdrantClient>("localhost",default!,default!,default!,default!,default!); | ||
var mockDomainService = new Mock<IDomainService>(); | ||
|
||
var userId = 1L; | ||
var videoId = 2L; | ||
|
||
mockHistoryRepo.Setup(x => x.AddHistory(userId, videoId)).Returns(Task.FromResult(1L)); | ||
|
||
var service = new HistoryService(mockHistoryRepo.Object, mockClient.Object, mockDomainService.Object); | ||
|
||
// Act | ||
var result = await service.AddHistory(userId, videoId); | ||
|
||
// Assert | ||
Assert.True(result); | ||
} | ||
|
||
/* [Fact] | ||
public async Task Recommendation_ReturnsPagination() | ||
{ | ||
// Arrange | ||
var mockHistoryRepo = new Mock<HistoryRepository>(null!); | ||
var mockClient = new Mock<QdrantClient>("localhost",default!,default!,default!,default!,default!); | ||
var mockDomainService = new Mock<IDomainService>(); | ||
var userId = 1L; | ||
var page = 0UL; | ||
var size = 10UL; | ||
var historyList = new List<long> { 1L, 2L }; | ||
var recommendationResults = new List<ScoredPoint> { new ScoredPoint { Id = new PointId { Num = 1 } }, new ScoredPoint { Id = new PointId { Num = 2 } } }; | ||
var videoIds = recommendationResults.Select(x => (long)x.Id.Num).ToList(); | ||
var videoDtos = new List<VideoDto> { new (), new () }; | ||
mockHistoryRepo.Setup(x => x.GetHistorys(userId, It.IsAny<long?>(), It.IsAny<int?>())).ReturnsAsync(historyList); | ||
mockClient.Setup(x => x.RecommendAsync( | ||
It.IsAny<string>(), | ||
It.IsAny<IReadOnlyList<ulong>>(), | ||
It.IsAny<IReadOnlyList<ulong>?>(), | ||
It.IsAny<ReadOnlyMemory<Vector>?>(), | ||
It.IsAny<ReadOnlyMemory<Vector>?>(), | ||
It.IsAny<RecommendStrategy?>(), | ||
It.IsAny<Filter?>(), | ||
It.IsAny<SearchParams?>(), | ||
It.IsAny<ulong>(), | ||
It.IsAny<ulong>(), | ||
It.IsAny<WithPayloadSelector?>(), | ||
It.IsAny<WithVectorsSelector?>(), | ||
It.IsAny<float?>(), | ||
It.IsAny<string?>(), | ||
It.IsAny<LookupLocation?>(), | ||
It.IsAny<ReadConsistency?>(), | ||
It.IsAny<ShardKeySelector?>(), | ||
It.IsAny<TimeSpan?>(), | ||
It.IsAny<CancellationToken>() | ||
)).ReturnsAsync(recommendationResults); | ||
mockDomainService.Setup(x => x.FindAllByIds(videoIds)).ReturnsAsync(videoDtos); | ||
var service = new HistoryService(mockHistoryRepo.Object, mockClient.Object, mockDomainService.Object); | ||
// Act | ||
var result = await service.Recommendation(userId, page, size); | ||
// Assert | ||
Assert.NotNull(result); | ||
Assert.Equal(videoDtos, result.Items); | ||
Assert.Equal((page + 1).ToString(), result.NextPage); | ||
} */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using content.repository; | ||
using Moq; | ||
using StackExchange.Redis; | ||
|
||
public class HistoryRepositoryTests | ||
{ | ||
[Fact] | ||
public async Task GetHistorys_ShouldReturnHistorys() | ||
{ | ||
// Arrange | ||
var mockDb = new Mock<IDatabase>(); | ||
var (userId, historyIds) = (123, new RedisValue[] { 1, 2, 3 }); | ||
mockDb.Setup(db => db.ListRangeAsync($"history:{userId}", It.IsAny<long>(), It.IsAny<long>(), CommandFlags.None)).ReturnsAsync(historyIds); | ||
var repository = new HistoryRepository(mockDb.Object); | ||
|
||
// Act | ||
var result = await repository.GetHistorys(userId); | ||
|
||
// Assert | ||
Assert.Equal(historyIds.Length, result.Count); | ||
for (int i = 0; i < historyIds.Length; i++) | ||
{ | ||
Assert.Equal((long)historyIds[i], result[i]); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task AddHistory_ShouldReturnCount() | ||
{ | ||
// Arrange | ||
var mockDb = new Mock<IDatabase>(); | ||
var (userId, historyId, expectedCount) = (123, 456, 1); | ||
mockDb.Setup(db => db.ListRightPushAsync($"history:{userId}", historyId, When.Always, CommandFlags.None)).ReturnsAsync(expectedCount); | ||
var repository = new HistoryRepository(mockDb.Object); | ||
// Act | ||
var result = await repository.AddHistory(userId, historyId); | ||
// Assert | ||
Assert.Equal(expectedCount, result); | ||
} | ||
} |
Oops, something went wrong.