Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: TestServices of Mimir.Tests #531

Merged
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
13 changes: 5 additions & 8 deletions Mimir.Tests/QueryTests/ActionPointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ public async Task GetActionPoint_Returns_CorrectValue()
.Setup(repo => repo.GetByAddressAsync(It.IsAny<Address>()))
.ReturnsAsync(new ActionPointDocument(1, new Address(), 120));

var serviceProvider = TestServices.CreateServices(
actionPointRepositoryMock: actionPointMock
);

var query =
"query { actionPoint(address: \"0x0000000000000000000000000000000000000000\") }";
var serviceProvider = TestServices.Builder
.With(actionPointMock.Object)
.Build();
const string query = "query { actionPoint(address: \"0x0000000000000000000000000000000000000000\") }";
var result = await TestServices.ExecuteRequestAsync(
serviceProvider,
b => b.SetQuery(query)
);
b => b.SetQuery(query));

await Verify(result);
}
Expand Down
52 changes: 36 additions & 16 deletions Mimir.Tests/QueryTests/AgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,45 @@ public class AgentTest
[Fact]
public async Task GraphQl_Query_Agent_Returns_CorrectValue()
{
var serviceProvider = TestServices.CreateServices();

var query = """
query {
agent(address: "0x0000000000000000000000000000000000000000") {
address
monsterCollectionRound
version
avatarAddresses {
key
value
var agentAddress = new Address("0x0000000031000000000200000000030000000004");
var avatarAddress1 = new Address("0x0000005001000000000200000000030000000004");
var avatarAddress2 = new Address("0x0000008001000000000200000000030000000004");
var avatarAddress3 = new Address("0x0000001001000000000200000000030000000004");
var agentState = new AgentState
{
Address = agentAddress,
AvatarAddresses = new Dictionary<int, Address>
{
{ 0, avatarAddress1 },
{ 1, avatarAddress2 },
{ 2, avatarAddress3 }
},
MonsterCollectionRound = 3,
Version = 4,
};
var mockRepo = new Mock<IAgentRepository>();
mockRepo
.Setup(repo => repo.GetByAddressAsync(It.IsAny<Address>()))
.ReturnsAsync(new AgentDocument(1, agentAddress, agentState));

var serviceProvider = TestServices.Builder
.With(mockRepo.Object)
.Build();
var query = $$"""
query {
agent(address: "{{agentAddress}}") {
address
monsterCollectionRound
version
avatarAddresses {
key
value
}
}
}
}
""";

""";
var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetQuery(query));

await Verify(result);
}

}
}
147 changes: 74 additions & 73 deletions Mimir.Tests/QueryTests/AvatarQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,100 +19,101 @@ public async Task GraphQL_Query_Avatar_Returns_CorrectValue()
var monsterMap = new CollectionMap();
var itemMap = new CollectionMap();
var eventMap = new CollectionMap();
Mail mail = new Mail()
var mail = new Mail
{
BlockIndex = 0,
Id = Guid.Parse("a9320f02-7794-4c3b-8071-701d501f9529"),
RequiredBlockIndex = 0,
TypeId = "A"
BlockIndex = 0,
Id = Guid.Parse("a9320f02-7794-4c3b-8071-701d501f9529"),
RequiredBlockIndex = 0,
TypeId = "A"
};

List<Mail> mails = new();
mails.Add(mail);
MailBox mailBox = new MailBox() {Mails = mails};


List<Mail> mails =
[
mail
];
var mailBox = new MailBox { Mails = mails };

stageMap.Add(1, 1);
monsterMap.Add(1, 1);
itemMap.Add(1, 1);
eventMap.Add(1, 1);

var avatar = new AvatarState
{
Address = default,
Version = 1,
AgentAddress = new Address("0x0000000000000000000000000000000000000001"),
MailBox = mailBox,
BlockIndex = 0,
DailyRewardReceivedIndex = 0,
ActionPoint = 0,
StageMap = stageMap,
MonsterMap = monsterMap,
ItemMap = itemMap,
EventMap = eventMap,
Hair = 0,
Lens = 0,
Ear = 0,
Tail = 0,
CombinationSlotAddresses = new List<Address>(){new Address()},
RankingMapAddress = default,
Name = "TestAvatar",
CharacterId = 1,
Level = 0,
Exp = 0,
UpdatedAt = 0,

Address = default,
Version = 1,
AgentAddress = new Address("0x0000000000000000000000000000000000000001"),
MailBox = mailBox,
BlockIndex = 0,
DailyRewardReceivedIndex = 0,
ActionPoint = 0,
StageMap = stageMap,
MonsterMap = monsterMap,
ItemMap = itemMap,
EventMap = eventMap,
Hair = 0,
Lens = 0,
Ear = 0,
Tail = 0,
CombinationSlotAddresses = [new Address()],
RankingMapAddress = default,
Name = "TestAvatar",
CharacterId = 1,
Level = 0,
Exp = 0,
UpdatedAt = 0,


// Add other mock data as needed
// Add other mock data as needed
};

var mockRepo = new Mock<IAvatarRepository>();
mockRepo
.Setup(repo => repo.GetByAddressAsync(It.IsAny<Address>()))
.ReturnsAsync(new AvatarDocument(0, new Address(), avatar));

var serviceProvider = TestServices.CreateServices(avatarRepositoryMock: mockRepo);

var query = """
query {
avatar(address: "0x0000000000000000000000000000000000000000") {
address
agentAddress
blockIndex
characterId
name
level
eventMap {
key
value
}
itemMap {
key
value
}
mailBox {
mails {
blockIndex
id
requiredBlockIndex
typeId

var serviceProvider = TestServices.Builder
.With(mockRepo.Object)
.Build();
var query = $$"""
Copy link
Contributor

@moreal moreal Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for me and other reviewers:

To enclose any interpolation expression within that string, you need to use the same number of braces as the number of $ characters, as the following example shows:

query {
avatar(address: "{{mockAddress}}") {
address
agentAddress
blockIndex
characterId
name
level
eventMap {
key
value
}
itemMap {
key
value
}
mailBox {
mails {
blockIndex
id
requiredBlockIndex
typeId
}
}
monsterMap {
key
value
}
stageMap {
key
value
}
}
monsterMap {
key
value
}
stageMap {
key
value
}
}
}
""";
""";

var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetQuery(query));

await Verify(result);

}
}
}
101 changes: 49 additions & 52 deletions Mimir.Tests/QueryTests/CombinationSlotsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,62 +25,59 @@ public async Task GraphQL_Query_CombinationSlots_Returns_CorrectValue()
.Setup(repo => repo.GetByAddressAsync(It.IsAny<Address>()))
.ReturnsAsync(new AllCombinationSlotStateDocument(1, allCombinationSlotAddress, allCombinationSlotState));

var serviceProvider = TestServices.CreateServices(
allCombinationSlotStateRepositoryMock : mockRepo
);
var serviceProvider = TestServices.Builder
.With(mockRepo.Object)
.Build();

var query = $$"""
query {
combinationSlots(avatarAddress: "{{allCombinationSlotAddress}}") {
key
value {
address
index
isUnlocked
petId
startBlockIndex
unlockBlockIndex
result {
tradableFungibleItemCount
typeId
costume {
elementalType
equipped
grade
id
itemId
itemSubType
itemType
requiredBlockIndex
spineResourcePath
}
itemUsable {
elementalType
grade
id
itemId
itemSubType
itemType
requiredBlockIndex
}
tradableFungibleItem {
elementalType
grade
id
itemId
itemSubType
itemType
requiredBlockIndex
var query = $$"""
query {
combinationSlots(avatarAddress: "{{allCombinationSlotAddress}}") {
key
value {
address
index
isUnlocked
petId
startBlockIndex
unlockBlockIndex
result {
tradableFungibleItemCount
typeId
costume {
elementalType
equipped
grade
id
itemId
itemSubType
itemType
requiredBlockIndex
spineResourcePath
}
itemUsable {
elementalType
grade
id
itemId
itemSubType
itemType
requiredBlockIndex
}
tradableFungibleItem {
elementalType
grade
id
itemId
itemSubType
itemType
requiredBlockIndex
}
}
}
}
}
}
""";
var result = TestServices.ExecuteRequestAsync(
serviceProvider,
b => b.SetQuery(query)
);
}
""";
var result = TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetQuery(query));

await Verify(result);
}
Expand Down
Loading
Loading