Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SapiensAnatis committed Aug 7, 2023
1 parent 6de9b13 commit 5bc70ab
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
using DragaliaAPI.Models.Generated;
using DragaliaAPI.Shared.Definitions.Enums;
using DragaliaAPI.Shared.MasterAsset;
using Microsoft.EntityFrameworkCore.Update;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;

namespace DragaliaAPI.Test.Features.Dungeon.Record;

Expand Down Expand Up @@ -89,10 +91,234 @@ await this.dungeonRecordRewardService.ProcessQuestMissionCompletion(
)
)
.Should()
.Be(status);
.Be((status, firstClearRewards));

questEntity.IsMissionClear1.Should().BeTrue();
questEntity.IsMissionClear2.Should().BeTrue();
questEntity.IsMissionClear3.Should().BeTrue();
}

[Fact]
public async Task ProcessEnemyDrops_RewardsCorrectDrops()
{
PlayRecord playRecord =
new()
{
treasure_record = new List<AtgenTreasureRecord>()
{
new()
{
area_idx = 0,
enemy = new List<int>() { 1, 0, 1 }
},
new()
{
area_idx = 1,
enemy = new List<int>() { 0, 1, 0 }
}
}
};

DungeonSession session =
new()
{
QuestData = null!,
Party = null!,
EnemyList = new Dictionary<int, IEnumerable<AtgenEnemy>>()
{
{
0,
new List<AtgenEnemy>()
{
new()
{
enemy_drop_list = new List<EnemyDropList>()
{
new()
{
mana = 10,
coin = 10,
drop_list = new List<AtgenDropList>()
{
new() { type = EntityTypes.Dew, quantity = 10 },
new() { type = EntityTypes.HustleHammer, quantity = 10 }
}
},
}
},
new()
{
enemy_drop_list = new List<EnemyDropList>()
{
new()
{
mana = 10,
coin = 10,
drop_list = new List<AtgenDropList>()
{
new() { type = EntityTypes.AstralItem, quantity = 10 }
}
},
}
},
new()
{
enemy_drop_list = new List<EnemyDropList>()
{
new()
{
mana = 10,
coin = 10,
drop_list = new List<AtgenDropList>()
{
new() { type = EntityTypes.Wyrmite, quantity = 10 }
}
},
new()
{
mana = 10,
coin = 10,
drop_list = new List<AtgenDropList>()
{
new() { type = EntityTypes.FafnirMedal, quantity = 10 }
}
},
}
}
}
},
{
1,
new List<AtgenEnemy>()
{
new(),
new()
{
enemy_drop_list = new List<EnemyDropList>()
{
new() { coin = 10, mana = 10, }
}
}
}
}
}
};

this.mockRewardService
.Setup(x => x.GrantReward(It.Is<Entity>(e => e.Type == EntityTypes.Dew)))
.ReturnsAsync(RewardGrantResult.Added);
this.mockRewardService
.Setup(x => x.GrantReward(It.Is<Entity>(e => e.Type == EntityTypes.HustleHammer)))
.ReturnsAsync(RewardGrantResult.Added);
this.mockRewardService
.Setup(x => x.GrantReward(It.Is<Entity>(e => e.Type == EntityTypes.Wyrmite)))
.ReturnsAsync(RewardGrantResult.Added);
this.mockRewardService
.Setup(x => x.GrantReward(It.Is<Entity>(e => e.Type == EntityTypes.FafnirMedal)))
.ReturnsAsync(RewardGrantResult.Added);

this.mockRewardService
.Setup(
x =>
x.GrantReward(
It.Is<Entity>(e => e.Type == EntityTypes.Mana && e.Quantity == 40)
)
)
.ReturnsAsync(RewardGrantResult.Added);
this.mockRewardService
.Setup(
x =>
x.GrantReward(
It.Is<Entity>(e => e.Type == EntityTypes.Rupies && e.Quantity == 40)
)
)
.ReturnsAsync(RewardGrantResult.Added);

(await this.dungeonRecordRewardService.ProcessEnemyDrops(playRecord, session))
.Should()
.BeEquivalentTo(
(
new List<AtgenDropAll>()
{
new() { type = EntityTypes.Dew, quantity = 10 },
new() { type = EntityTypes.HustleHammer, quantity = 10 },
new() { type = EntityTypes.FafnirMedal, quantity = 10 },
new() { type = EntityTypes.Wyrmite, quantity = 10 }
},
40,
40
)
);

this.mockRewardService.VerifyAll();
}

[Fact]
public async Task ProcessEventRewards_CallsExpectedMethods()
{
List<PartySettingList> party = new();
DungeonSession session =
new() { QuestData = MasterAsset.QuestData[100010101], Party = party, };
PlayRecord playRecord = new();

List<AtgenScoreMissionSuccessList> scoreMissionSuccessLists =
new()
{
new()
{
score_mission_complete_type = QuestCompleteType.DragonElementLocked,
score_target_value = 2,
}
};

List<AtgenEventPassiveUpList> passiveUpLists =
new()
{
new() { passive_id = 3, progress = 10 }
};

List<AtgenDropAll> eventDrops =
new()
{
new() { type = EntityTypes.Clb01EventItem, quantity = 100 }
};

int materialMultiplier = 2;
int pointMultiplier = 3;
int points = 10;
int boostedPoints = 20;

this.mockAbilityCrestMultiplierService
.Setup(x => x.GetEventMultiplier(session.Party, session.QuestData.Gid))
.ReturnsAsync((materialMultiplier, pointMultiplier));

this.mockQuestCompletionService
.Setup(x => x.CompleteQuestScoreMissions(session, playRecord, pointMultiplier))
.ReturnsAsync((scoreMissionSuccessLists, points, boostedPoints));

this.mockEventDropService
.Setup(x => x.ProcessEventPassiveDrops(session.QuestData))
.ReturnsAsync(passiveUpLists);
this.mockEventDropService
.Setup(
x => x.ProcessEventMaterialDrops(session.QuestData, playRecord, materialMultiplier)
)
.ReturnsAsync(eventDrops);

(await this.dungeonRecordRewardService.ProcessEventRewards(playRecord, session))
.Should()
.BeEquivalentTo(
new DungeonRecordRewardService.EventRewardData(
scoreMissionSuccessLists,
points + boostedPoints,
boostedPoints,
passiveUpLists,
eventDrops
)
);

this.mockAbilityCrestMultiplierService.VerifyAll();
this.mockQuestCompletionService.VerifyAll();
this.mockEventDropService.VerifyAll();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Castle.Core.Logging;
using DragaliaAPI.Database.Entities;
using DragaliaAPI.Database.Repositories;
using DragaliaAPI.Features.Dungeon;
using DragaliaAPI.Features.Dungeon.Record;
using DragaliaAPI.Features.Missions;
using DragaliaAPI.Features.Player;
Expand Down Expand Up @@ -111,6 +112,41 @@ public async Task GenerateIngameResultData_CallsExpectedMethods()
new() { passive_id = 1, progress = 2 }
};

List<AtgenMissionsClearSet> missionsClearSets = new List<AtgenMissionsClearSet>()
{
new()
{
type = EntityTypes.CollectEventItem,
id = 1,
quantity = 2
}
};

List<AtgenFirstClearSet> missionCompleteSets =
new()
{
new()
{
type = EntityTypes.ExchangeTicket,
id = 2,
quantity = 3
}
};

List<AtgenFirstClearSet> firstClearSets =
new()
{
new()
{
type = EntityTypes.RaidEventItem,
id = 4,
quantity = 5
}
};

QuestMissionStatus missionStatus =
new(new bool[] { }, missionsClearSets, missionCompleteSets);

int takeCoin = 10;
int takeMana = 20;
int takeAccumulatePoint = 30;
Expand All @@ -129,6 +165,9 @@ public async Task GenerateIngameResultData_CallsExpectedMethods()
.Setup(x => x.AddExperience(400))
.ReturnsAsync(new PlayerLevelResult(true, 100, 50));

this.mockDungeonRewardService
.Setup(x => x.ProcessQuestMissionCompletion(playRecord, session, mockQuest))
.ReturnsAsync((missionStatus, firstClearSets));
this.mockDungeonRewardService
.Setup(x => x.ProcessEnemyDrops(playRecord, session))
.ReturnsAsync((dropList, takeMana, takeCoin));
Expand Down Expand Up @@ -175,6 +214,9 @@ await this.dungeonRecordService.GenerateIngameResultData(
take_coin = takeCoin,
take_astral_item_quantity = 0,
player_level_up_fstone = 50,
first_clear_set = firstClearSets,
mission_complete = missionCompleteSets,
missions_clear_set = missionsClearSets,
},
grow_record = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public class DungeonRecordRewardService(
ILogger<DungeonRecordRewardService> logger
) : IDungeonRecordRewardService
{
public async Task<QuestMissionStatus> ProcessQuestMissionCompletion(
public async Task<(
QuestMissionStatus MissionStatus,
IEnumerable<AtgenFirstClearSet> FirstClearRewards
)> ProcessQuestMissionCompletion(
PlayRecord playRecord,
DungeonSession session,
DbQuest questData
Expand Down Expand Up @@ -44,7 +47,7 @@ DbQuest questData
questData.IsMissionClear2 = status.Missions[1];
questData.IsMissionClear3 = status.Missions[2];

return status;
return (status, firstClearRewards);
}

public async Task<(
Expand Down
11 changes: 11 additions & 0 deletions DragaliaAPI/Features/Dungeon/Record/DungeonRecordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ await this.ProcessPlayerLevel(
session
);

(QuestMissionStatus missionStatus, IEnumerable<AtgenFirstClearSet>? firstClearSets) =
await dungeonRecordRewardService.ProcessQuestMissionCompletion(
playRecord,
session,
questData
);

ingameResultData.reward_record.first_clear_set = firstClearSets;
ingameResultData.reward_record.missions_clear_set = missionStatus.MissionsClearSet;
ingameResultData.reward_record.mission_complete = missionStatus.MissionCompleteSet;

(IEnumerable<AtgenDropAll> dropList, int manaDrop, int coinDrop) =
await dungeonRecordRewardService.ProcessEnemyDrops(playRecord, session);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ namespace DragaliaAPI.Features.Dungeon.Record;

public interface IDungeonRecordRewardService
{
Task<QuestMissionStatus> ProcessQuestMissionCompletion(
Task<(
QuestMissionStatus MissionStatus,
IEnumerable<AtgenFirstClearSet> FirstClearRewards
)> ProcessQuestMissionCompletion(
PlayRecord playRecord,
DungeonSession session,
DbQuest questData
Expand Down

0 comments on commit 5bc70ab

Please sign in to comment.