public class DailyRewardQueryTest
{
[Fact]
public async Task GraphQL_Query_DailyRewardReceivedBlockIndex_Returns_CorrectValue()
{
}
}
Mocking IServiceProvider with Mock DailyRewardRepository
Create IDailyRewardRepository Interface:
Add the IDailyRewardRepository interface and apply it to DailyRewardRepository.
Make DailyRewardRepository.GetReceivedBlockIndexAsync Virtual:
Modify the GetReceivedBlockIndexAsync method to be virtual for mocking.
Mock Setup:
[Fact]
public async Task GraphQL_Query_DailyRewardReceivedBlockIndex_Returns_CorrectValue()
{
var mockAddress = new Address("0x0000000000000000000000000000000000000000");
var mockRepo = new Mock<IDailyRewardRepository>();
mockRepo
.Setup(repo => repo.GetReceivedBlockIndexAsync(mockAddress))
.ReturnsAsync(12345);
var serviceProvider = TestServices.CreateServices(dailyRewardRepositoryMock: mockRepo);
var query = """
query {
dailyRewardReceivedBlockIndex(address: "0x0000000000000000000000000000000000000000")
}
""";
var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetQuery(query));
await Verify(result);
}
Notes
Mocking:
The repository is mocked to return a predefined block index (e.g., 12345) for the test address.
Verification:
The Verify method is used to validate the returned result matches the expected snapshot.
Scenario Covered:
Test ensures that querying dailyRewardReceivedBlockIndex for a given address returns the correct block index.
We need to add a integration test for the
dailyRewardReceivedBlockIndex
query to ensure it returns the correct data.Create
DailyRewardQueryTest.cs
with Initial integration TestMimir.Tests/QueryTests/DailyRewardQueryTest.cs
Mocking
IServiceProvider
with MockDailyRewardRepository
Create
IDailyRewardRepository
Interface:IDailyRewardRepository
interface and apply it toDailyRewardRepository
.Make
DailyRewardRepository.GetReceivedBlockIndexAsync
Virtual:GetReceivedBlockIndexAsync
method to bevirtual
for mocking.Mock Setup:
Notes
Mocking:
12345
) for the test address.Verification:
Verify
method is used to validate the returned result matches the expected snapshot.Scenario Covered:
dailyRewardReceivedBlockIndex
for a given address returns the correct block index.