Closed Atralupus closed 16 hours ago
Currently, there is no unit test for inventory and we should make one.
inventory
InventoryTest.cs
Mimir.Tests/QueryTests/InventoryTest.cs
public class InventoryTest { [Fact] public async Task GraphQL_Query_Inventory_Returns_CorrectValue() { } }
IServiceProvider
InventoryRepository
make IInventoryRepository interface and apply to InventoryRepository in Mimir.MongoDB
IInventoryRepository
fix registration method at Program in Mimir:
Program
-builder.Services.AddSingleton<InventoryRepository>(); +builder.Services.AddSingleton<IInventoryRepository, InventoryRepository>();
and Query in Mimir:
Query
public async Task GetInventoryAsync(Address address, [Service] InventoryRepository repo) =>
(await repo.GetByAddressAsync(address)).Object;
public async Task GetInventoryAsync(Address address, [Service] IInventoryRepository repo) =>
mocking:
[Fact] public async Task GraphQL_Query_Invnetory_Returns_CorrectValue() {
// process mokking
var mockRepo = new Mock();
mockRepo
.Setup(repo => repo.GetByAddressAsync(It.IsAny
.ReturnsAsync(new InventoryDocument(...)); }
create service provider with mockRepo:
[Fact] public async Task GraphQL_Query_Invnetory_Returns_CorrectValue() { // var address = ... // var state = ... // var mockRepo = ...
var serviceProvider = TestServices.Builder .With(mockRepo.Object) .Build(); }
query inventory and verify it's result:
public async Task GraphQL_Query_Inventory_Returns_CorrectValue() { // var address = ... // var state = ... // var mockRepo = ... // var serviceProvider = ... var query = $$""" query { inventory(address: "{{address}}") { items { count item { elementalType grade id itemSubType itemType ... on Armor { elementalType equipped exp grade id itemId itemSubType itemType level madeWithMimisbrunnrRecipe optionCountFromCombination requiredBlockIndex setId spineResourcePath } ... on Aura { elementalType equipped exp grade id itemId itemSubType itemType level madeWithMimisbrunnrRecipe optionCountFromCombination requiredBlockIndex setId spineResourcePath } ... on Belt { elementalType equipped exp grade id itemId itemSubType itemType level madeWithMimisbrunnrRecipe optionCountFromCombination requiredBlockIndex setId spineResourcePath } ... on Consumable { elementalType grade id itemId itemSubType itemType requiredBlockIndex } ... on Costume { elementalType equipped grade id itemId itemSubType itemType requiredBlockIndex spineResourcePath } ... on Equipment { elementalType equipped exp grade id itemId itemSubType itemType level madeWithMimisbrunnrRecipe optionCountFromCombination requiredBlockIndex setId spineResourcePath } ... on Grimoire { elementalType equipped exp grade id itemId itemSubType itemType level madeWithMimisbrunnrRecipe optionCountFromCombination requiredBlockIndex setId spineResourcePath } ... on ItemBase { elementalType grade id itemSubType itemType } ... on ItemUsable { elementalType grade id itemId itemSubType itemType requiredBlockIndex } ... on Material { elementalType grade id itemId itemSubType itemType } ... on Necklace { elementalType equipped exp grade id itemId itemSubType itemType level madeWithMimisbrunnrRecipe optionCountFromCombination requiredBlockIndex setId spineResourcePath } ... on Ring { elementalType equipped exp grade id itemId itemSubType itemType level madeWithMimisbrunnrRecipe optionCountFromCombination requiredBlockIndex setId spineResourcePath } ... on TradableMaterial { elementalType grade id itemId itemSubType itemType requiredBlockIndex } ... on Weapon { elementalType equipped exp grade id itemId itemSubType itemType level madeWithMimisbrunnrRecipe optionCountFromCombination requiredBlockIndex setId spineResourcePath } } } } } """;
var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetDocument(query));
await Verify(result); }
Please assign this issue to me
Currently, there is no unit test for
inventory
and we should make one.Make
InventoryTest.cs
with first unit testMimir.Tests/QueryTests/InventoryTest.cs
Mocking
IServiceProvider
with mockInventoryRepository
make
IInventoryRepository
interface and apply toInventoryRepository
in Mimir.MongoDBfix registration method at
Program
in Mimir:and
Query
in Mimir:public async Task GetInventoryAsync(Address address, [Service] InventoryRepository repo) =>
(await repo.GetByAddressAsync(address)).Object;
public async Task GetInventoryAsync(Address address, [Service] IInventoryRepository repo) =>
(await repo.GetByAddressAsync(address)).Object;
mocking:
// process mokking
var mockRepo = new Mock();
mockRepo
.Setup(repo => repo.GetByAddressAsync(It.IsAny
())).ReturnsAsync(new InventoryDocument(...)); }
create service provider with
mockRepo
:var serviceProvider = TestServices.Builder .With(mockRepo.Object) .Build(); }
Testing GraphQL query
inventory
via verifying snapshotquery inventory and verify it's result:
var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetDocument(query));
await Verify(result); }