Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SapiensAnatis committed Aug 9, 2023
1 parent 50d6d14 commit 03c7ccc
Showing 1 changed file with 116 additions and 6 deletions.
122 changes: 116 additions & 6 deletions DragaliaAPI.Test/Controllers/DungeonControllerTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using DragaliaAPI.Features.Dungeon;
using DragaliaAPI.Features.Dungeon.Record;
using DragaliaAPI.Models;
using DragaliaAPI.Models.Generated;
using DragaliaAPI.Services.Photon;
using DragaliaAPI.Shared.Definitions.Enums;
using DragaliaAPI.Shared.MasterAsset;

namespace DragaliaAPI.Test.Controllers;
Expand All @@ -9,42 +12,149 @@ public class DungeonControllerTest
{
private readonly Mock<IDungeonService> mockDungeonService;
private readonly Mock<IOddsInfoService> mockOddsInfoService;
private readonly Mock<IMatchingService> mockMatchingService;
private readonly Mock<IDungeonRecordHelperService> mockDungeonRecordHelperService;

private readonly DungeonController dungeonController;

public DungeonControllerTest()
{
this.mockDungeonService = new(MockBehavior.Strict);
this.mockOddsInfoService = new(MockBehavior.Strict);
this.mockMatchingService = new(MockBehavior.Strict);
this.mockDungeonRecordHelperService = new(MockBehavior.Strict);

this.dungeonController = new(
this.mockDungeonService.Object,
this.mockOddsInfoService.Object
this.mockOddsInfoService.Object,
this.mockMatchingService.Object,
this.mockDungeonRecordHelperService.Object
);
}

[Fact]
public async Task Fail_IsMultiFalse_ReturnsExpectedResponse()
{
int questId = 227060105;

List<UserSupportList> userSupportList =
new() { new() { support_chara = new() { chara_id = Charas.HalloweenLowen } } };

dungeonController.SetupMockContext();
List<AtgenHelperDetailList> supportDetailList =
new()
{
new()
{
is_friend = false,
viewer_id = 1,
get_mana_point = 50,
}
};

this.mockDungeonService
.Setup(x => x.FinishDungeon("my key"))
.ReturnsAsync(
new DungeonSession()
{
QuestData = MasterAsset.QuestData.Get(questId),
Party = new List<PartySettingList>(),
IsMulti = false,
SupportViewerId = 4,
}
);

this.mockDungeonRecordHelperService
.Setup(x => x.ProcessHelperDataSolo(4))
.ReturnsAsync((userSupportList, supportDetailList));

DungeonFailData? response = (
await this.dungeonController.Fail(new DungeonFailRequest() { dungeon_key = "my key" })
).GetData<DungeonFailData>();

response.Should().NotBeNull();
response!
.Should()
.BeEquivalentTo(
new DungeonFailData()
{
result = 1,
fail_helper_list = userSupportList,
fail_helper_detail_list = supportDetailList,
fail_quest_detail = new()
{
wall_id = 0,
wall_level = 0,
is_host = true,
quest_id = questId
}
}
);

this.mockDungeonService.VerifyAll();
this.mockDungeonRecordHelperService.VerifyAll();
}

[Fact]
public async Task Fail_RespondsWithCorrectQuestId()
public async Task Fail_IsMultiTrue_RespondsExpectedResponse()
{
int questId = 227060105;

List<UserSupportList> userSupportList =
new() { new() { support_chara = new() { chara_id = Charas.HalloweenLowen } } };

List<AtgenHelperDetailList> supportDetailList =
new()
{
new()
{
is_friend = false,
viewer_id = 1,
get_mana_point = 50,
}
};

this.mockDungeonService
.Setup(x => x.FinishDungeon("my key"))
.ReturnsAsync(
new DungeonSession()
{
QuestData = MasterAsset.QuestData.Get(227060105),
Party = new List<PartySettingList>()
QuestData = MasterAsset.QuestData.Get(questId),
Party = new List<PartySettingList>(),
IsMulti = true,
}
);

this.mockDungeonRecordHelperService
.Setup(x => x.ProcessHelperDataMulti())
.ReturnsAsync((userSupportList, supportDetailList));

this.mockMatchingService.Setup(x => x.GetIsHost()).ReturnsAsync(false);

DungeonFailData? response = (
await this.dungeonController.Fail(new DungeonFailRequest() { dungeon_key = "my key" })
).GetData<DungeonFailData>();

response.Should().NotBeNull();
response!.fail_quest_detail.quest_id.Should().Be(227060105);
response!
.Should()
.BeEquivalentTo(
new DungeonFailData()
{
result = 1,
fail_helper_list = userSupportList,
fail_helper_detail_list = supportDetailList,
fail_quest_detail = new()
{
wall_id = 0,
wall_level = 0,
is_host = false,
quest_id = questId
}
}
);

this.mockDungeonService.VerifyAll();
this.mockMatchingService.VerifyAll();
this.mockDungeonRecordHelperService.VerifyAll();
}
}

0 comments on commit 03c7ccc

Please sign in to comment.