-
Notifications
You must be signed in to change notification settings - Fork 34
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
12 changed files
with
134 additions
and
37 deletions.
There are no files selected for viewing
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,13 @@ | ||
using MongoDB.Bson; | ||
using MongoDB.Driver; | ||
using MongoDB.Driver.GridFS; | ||
|
||
namespace Mimir.MongoDB.Services; | ||
|
||
public interface IMongoDbService | ||
{ | ||
IMongoCollection<T> GetCollection<T>(string collectionName); | ||
IMongoDatabase GetDatabase(); | ||
GridFSBucket GetGridFs(); | ||
Task<byte[]> RetrieveFromGridFs(ObjectId fileId); | ||
} |
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
5 changes: 5 additions & 0 deletions
5
Mimir.Tests/QueryTests/ActionPointTests.GetActionPoint_Returns_CorrectValue.received.txt
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,5 @@ | ||
{ | ||
"data": { | ||
"actionPoint": 120 | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Mimir.Tests/QueryTests/ActionPointTests.GetActionPoint_Returns_CorrectValue.verified.txt
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,5 @@ | ||
{ | ||
"data": { | ||
"actionPoint": 120 | ||
} | ||
} |
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,20 @@ | ||
using Libplanet.Crypto; | ||
|
||
namespace Mimir.Tests.QueryTests; | ||
|
||
public class ActionPointTests | ||
{ | ||
[Fact] | ||
public async Task GetActionPoint_Returns_CorrectValue() | ||
{ | ||
// var query = | ||
// @" | ||
// query($address: Address!) { | ||
// actionPoint(address: $address) | ||
// }"; | ||
var query = "query { actionPoint(address: \"0x0000000000000000000000000000000000000000\")}"; | ||
var result = await TestServices.ExecuteRequestAsync(b => b.SetQuery(query)); | ||
|
||
await Verify(result); | ||
} | ||
} |
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,68 @@ | ||
using System.Numerics; | ||
using System.Security.Cryptography; | ||
using HotChocolate; | ||
using HotChocolate.Execution; | ||
using Lib9c.GraphQL.Types; | ||
using Libplanet.Common; | ||
using Libplanet.Crypto; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Mimir.MongoDB.Bson; | ||
using Mimir.MongoDB.Repositories; | ||
using Mimir.MongoDB.Services; | ||
using MongoDB.Driver; | ||
using Moq; | ||
|
||
namespace Mimir.Tests; | ||
|
||
public static class TestServices | ||
{ | ||
public static readonly IServiceProvider Services; | ||
public static readonly RequestExecutorProxy Executor; | ||
|
||
static TestServices() | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
|
||
serviceCollection | ||
.AddGraphQLServer() | ||
.AddLib9cGraphQLTypes() | ||
.AddMimirGraphQLTypes() | ||
.BindRuntimeType(typeof(Address), typeof(AddressType)) | ||
.BindRuntimeType(typeof(BigInteger), typeof(BigIntegerType)) | ||
.BindRuntimeType(typeof(HashDigest<SHA256>), typeof(HashDigestSHA256Type)) | ||
.Services.AddSingleton(sp => new RequestExecutorProxy( | ||
sp.GetRequiredService<IRequestExecutorResolver>(), | ||
Schema.DefaultName | ||
)); | ||
|
||
var mockMongoDbService = new Mock<IMongoDbService>(); | ||
serviceCollection.AddSingleton(mockMongoDbService.Object); | ||
serviceCollection.AddSingleton<ActionPointRepository>(); | ||
|
||
var mockRepo = new Mock<IActionPointRepository>(); | ||
mockRepo | ||
.Setup(repo => repo.GetByAddressAsync(It.IsAny<Address>())) | ||
.ReturnsAsync(new ActionPointDocument(1, new Address(), 120)); | ||
serviceCollection.AddSingleton(mockRepo.Object); | ||
|
||
Services = serviceCollection.BuildServiceProvider(); | ||
Executor = Services.GetRequiredService<RequestExecutorProxy>(); | ||
} | ||
|
||
public static async Task<string> ExecuteRequestAsync( | ||
Action<IQueryRequestBuilder> configureRequest, | ||
CancellationToken cancellationToken = default | ||
) | ||
{ | ||
await using var scope = Services.CreateAsyncScope(); | ||
|
||
var requestBuilder = new QueryRequestBuilder(); | ||
requestBuilder.SetServices(scope.ServiceProvider); | ||
configureRequest(requestBuilder); | ||
var request = requestBuilder.Create(); | ||
|
||
await using var result = await Executor.ExecuteAsync(request, cancellationToken); | ||
result.ExpectQueryResult(); | ||
return result.ToJson(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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