From 5bc70abfb65c5bfdae98c71acfee12e5a72e7aee Mon Sep 17 00:00:00 2001 From: Jay Malhotra <5047192+SapiensAnatis@users.noreply.github.com> Date: Fri, 4 Aug 2023 22:29:18 +0100 Subject: [PATCH] Add tests --- .../Record/DungeonRecordRewardServiceTest.cs | 228 +++++++++++++++++- .../Record/DungeonRecordServiceTest.cs | 42 ++++ .../Record/DungeonRecordRewardService.cs | 7 +- .../Dungeon/Record/DungeonRecordService.cs | 11 + .../Record/IDungeonRecordRewardService.cs | 5 +- 5 files changed, 289 insertions(+), 4 deletions(-) diff --git a/DragaliaAPI.Test/Features/Dungeon/Record/DungeonRecordRewardServiceTest.cs b/DragaliaAPI.Test/Features/Dungeon/Record/DungeonRecordRewardServiceTest.cs index 7b2f2a6f3..ec736888f 100644 --- a/DragaliaAPI.Test/Features/Dungeon/Record/DungeonRecordRewardServiceTest.cs +++ b/DragaliaAPI.Test/Features/Dungeon/Record/DungeonRecordRewardServiceTest.cs @@ -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; @@ -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() + { + new() + { + area_idx = 0, + enemy = new List() { 1, 0, 1 } + }, + new() + { + area_idx = 1, + enemy = new List() { 0, 1, 0 } + } + } + }; + + DungeonSession session = + new() + { + QuestData = null!, + Party = null!, + EnemyList = new Dictionary>() + { + { + 0, + new List() + { + new() + { + enemy_drop_list = new List() + { + new() + { + mana = 10, + coin = 10, + drop_list = new List() + { + new() { type = EntityTypes.Dew, quantity = 10 }, + new() { type = EntityTypes.HustleHammer, quantity = 10 } + } + }, + } + }, + new() + { + enemy_drop_list = new List() + { + new() + { + mana = 10, + coin = 10, + drop_list = new List() + { + new() { type = EntityTypes.AstralItem, quantity = 10 } + } + }, + } + }, + new() + { + enemy_drop_list = new List() + { + new() + { + mana = 10, + coin = 10, + drop_list = new List() + { + new() { type = EntityTypes.Wyrmite, quantity = 10 } + } + }, + new() + { + mana = 10, + coin = 10, + drop_list = new List() + { + new() { type = EntityTypes.FafnirMedal, quantity = 10 } + } + }, + } + } + } + }, + { + 1, + new List() + { + new(), + new() + { + enemy_drop_list = new List() + { + new() { coin = 10, mana = 10, } + } + } + } + } + } + }; + + this.mockRewardService + .Setup(x => x.GrantReward(It.Is(e => e.Type == EntityTypes.Dew))) + .ReturnsAsync(RewardGrantResult.Added); + this.mockRewardService + .Setup(x => x.GrantReward(It.Is(e => e.Type == EntityTypes.HustleHammer))) + .ReturnsAsync(RewardGrantResult.Added); + this.mockRewardService + .Setup(x => x.GrantReward(It.Is(e => e.Type == EntityTypes.Wyrmite))) + .ReturnsAsync(RewardGrantResult.Added); + this.mockRewardService + .Setup(x => x.GrantReward(It.Is(e => e.Type == EntityTypes.FafnirMedal))) + .ReturnsAsync(RewardGrantResult.Added); + + this.mockRewardService + .Setup( + x => + x.GrantReward( + It.Is(e => e.Type == EntityTypes.Mana && e.Quantity == 40) + ) + ) + .ReturnsAsync(RewardGrantResult.Added); + this.mockRewardService + .Setup( + x => + x.GrantReward( + It.Is(e => e.Type == EntityTypes.Rupies && e.Quantity == 40) + ) + ) + .ReturnsAsync(RewardGrantResult.Added); + + (await this.dungeonRecordRewardService.ProcessEnemyDrops(playRecord, session)) + .Should() + .BeEquivalentTo( + ( + new List() + { + 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 party = new(); + DungeonSession session = + new() { QuestData = MasterAsset.QuestData[100010101], Party = party, }; + PlayRecord playRecord = new(); + + List scoreMissionSuccessLists = + new() + { + new() + { + score_mission_complete_type = QuestCompleteType.DragonElementLocked, + score_target_value = 2, + } + }; + + List passiveUpLists = + new() + { + new() { passive_id = 3, progress = 10 } + }; + + List 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(); + } } diff --git a/DragaliaAPI.Test/Features/Dungeon/Record/DungeonRecordServiceTest.cs b/DragaliaAPI.Test/Features/Dungeon/Record/DungeonRecordServiceTest.cs index 1293f3c66..7516ceeb5 100644 --- a/DragaliaAPI.Test/Features/Dungeon/Record/DungeonRecordServiceTest.cs +++ b/DragaliaAPI.Test/Features/Dungeon/Record/DungeonRecordServiceTest.cs @@ -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; @@ -111,6 +112,41 @@ public async Task GenerateIngameResultData_CallsExpectedMethods() new() { passive_id = 1, progress = 2 } }; + List missionsClearSets = new List() + { + new() + { + type = EntityTypes.CollectEventItem, + id = 1, + quantity = 2 + } + }; + + List missionCompleteSets = + new() + { + new() + { + type = EntityTypes.ExchangeTicket, + id = 2, + quantity = 3 + } + }; + + List 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; @@ -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)); @@ -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() { diff --git a/DragaliaAPI/Features/Dungeon/Record/DungeonRecordRewardService.cs b/DragaliaAPI/Features/Dungeon/Record/DungeonRecordRewardService.cs index cee91ba6c..593630eaf 100644 --- a/DragaliaAPI/Features/Dungeon/Record/DungeonRecordRewardService.cs +++ b/DragaliaAPI/Features/Dungeon/Record/DungeonRecordRewardService.cs @@ -15,7 +15,10 @@ public class DungeonRecordRewardService( ILogger logger ) : IDungeonRecordRewardService { - public async Task ProcessQuestMissionCompletion( + public async Task<( + QuestMissionStatus MissionStatus, + IEnumerable FirstClearRewards + )> ProcessQuestMissionCompletion( PlayRecord playRecord, DungeonSession session, DbQuest questData @@ -44,7 +47,7 @@ DbQuest questData questData.IsMissionClear2 = status.Missions[1]; questData.IsMissionClear3 = status.Missions[2]; - return status; + return (status, firstClearRewards); } public async Task<( diff --git a/DragaliaAPI/Features/Dungeon/Record/DungeonRecordService.cs b/DragaliaAPI/Features/Dungeon/Record/DungeonRecordService.cs index 3086948de..8be049055 100644 --- a/DragaliaAPI/Features/Dungeon/Record/DungeonRecordService.cs +++ b/DragaliaAPI/Features/Dungeon/Record/DungeonRecordService.cs @@ -66,6 +66,17 @@ await this.ProcessPlayerLevel( session ); + (QuestMissionStatus missionStatus, IEnumerable? 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 dropList, int manaDrop, int coinDrop) = await dungeonRecordRewardService.ProcessEnemyDrops(playRecord, session); diff --git a/DragaliaAPI/Features/Dungeon/Record/IDungeonRecordRewardService.cs b/DragaliaAPI/Features/Dungeon/Record/IDungeonRecordRewardService.cs index 402cdf1a9..fa9e878ef 100644 --- a/DragaliaAPI/Features/Dungeon/Record/IDungeonRecordRewardService.cs +++ b/DragaliaAPI/Features/Dungeon/Record/IDungeonRecordRewardService.cs @@ -6,7 +6,10 @@ namespace DragaliaAPI.Features.Dungeon.Record; public interface IDungeonRecordRewardService { - Task ProcessQuestMissionCompletion( + Task<( + QuestMissionStatus MissionStatus, + IEnumerable FirstClearRewards + )> ProcessQuestMissionCompletion( PlayRecord playRecord, DungeonSession session, DbQuest questData