Skip to content

Commit 8945fc4

Browse files
committed
Doh/DoL: add tests and optimize for maintainability
1 parent 5186484 commit 8945fc4

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

NetStone.Test/Tests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class Tests
2020
private const string TestCharacterIdEureka = "14556736";
2121
private const string TestCharacterIdEureka2 = "6787158";
2222
private const string TestCharacterIdBare = "9426169";
23+
private const string TestCharacterIdDoH = "42256897";
2324

2425
private const string TestFreeCompany = "9232379236109629819";
2526
private const string TestFreeCompanyRecruiting = "9232660711086374997";
@@ -289,6 +290,17 @@ public async Task TestFreeCompanySearch()
289290
} while (page != null);
290291
}
291292

293+
[Test]
294+
public async Task CheckCharacterDoH()
295+
{
296+
var chara = await this.lodestone.GetCharacter(TestCharacterIdDoH);
297+
Assert.NotNull(chara);
298+
var attribs = chara.Attributes;
299+
Assert.AreEqual(39, attribs.Craftsmanship);
300+
Assert.AreEqual(7, attribs.Control);
301+
Assert.AreEqual(180, attribs.MpGpCp);
302+
}
303+
292304
[Test]
293305
public async Task CheckCharacterBare()
294306
{

NetStone/Model/Parseables/Character/CharacterAttributes.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using HtmlAgilityPack;
1+
using System;
2+
using HtmlAgilityPack;
23
using NetStone.Definitions.Model.Character;
34

45
namespace NetStone.Model.Parseables.Character;
@@ -84,13 +85,13 @@ public CharacterAttributes(HtmlNode rootNode, CharacterAttributesDefinition defi
8485
/// This characters' Attack Magic Potency value.
8586
/// </summary>
8687
/// <remarks>This value is only set for disciples of war/magic.</remarks>
87-
public int? AttackMagicPotency => MpGpCpParameterName == "MP" ? int.Parse(Parse(this.definition.AttackMagicPotency)) : null;
88+
public int? AttackMagicPotency => IsDoWOrDoM() ? this.AttackMagicPotencyInternal : null;
8889

8990
/// <summary>
9091
/// This characters' Healing Magic Potency value.
9192
/// </summary>
9293
/// <remarks>This value is only set for disciples of war/magic.</remarks>
93-
public int? HealingMagicPotency => MpGpCpParameterName == "MP" ? int.Parse(Parse(this.definition.HealingMagicPotency)) : null;
94+
public int? HealingMagicPotency => IsDoWOrDoM() ? this.HealingMagicPotencyInternal : null;
9495

9596
/// <summary>
9697
/// This characters' Spell Speed value.
@@ -112,25 +113,25 @@ public CharacterAttributes(HtmlNode rootNode, CharacterAttributesDefinition defi
112113
/// This characters' Craftmanship value.
113114
/// </summary>
114115
/// <remarks>This value is only set for disciples of the hand.</remarks>
115-
public int? Craftmanship => MpGpCpParameterName == "CP" ? AttackMagicPotencyValue : null;
116+
public int? Craftsmanship => IsDoH() ? this.AttackMagicPotencyInternal : null;
116117

117118
/// <summary>
118119
/// This characters' Control value.
119120
/// </summary>
120121
/// <remarks>This value is only set for disciples of the hand.</remarks>
121-
public int? Control => MpGpCpParameterName == "CP" ? HealingMagicPotencyValue : null;
122+
public int? Control => IsDoH() ? this.HealingMagicPotencyInternal : null;
122123

123124
/// <summary>
124125
/// This characters' Gathering value.
125126
/// </summary>
126127
/// <remarks>This value is only set for disciples of the land.</remarks>
127-
public int? Gathering => MpGpCpParameterName == "GP" ? AttackMagicPotencyValue : null;
128+
public int? Gathering => IsDoL() ? this.AttackMagicPotencyInternal : null;
128129

129130
/// <summary>
130131
/// This characters' Perception value.
131132
/// </summary>
132133
/// <remarks>This value is only set for disciples of the land.</remarks>
133-
public int? Perception => MpGpCpParameterName == "GP" ? HealingMagicPotencyValue : null;
134+
public int? Perception => IsDoL() ? this.HealingMagicPotencyInternal : null;
134135

135136
/// <summary>
136137
/// This characters' HP value.
@@ -146,8 +147,12 @@ public CharacterAttributes(HtmlNode rootNode, CharacterAttributesDefinition defi
146147
/// Value indicating which of MP, GP, or CP is indicated by <see cref="MpGpCp"/>.
147148
/// </summary>
148149
public string MpGpCpParameterName => Parse(this.definition.MpGpCpParameterName);
150+
151+
internal bool IsDoL() => this.MpGpCpParameterName.Equals("GP", StringComparison.InvariantCultureIgnoreCase);
152+
internal bool IsDoWOrDoM() => this.MpGpCpParameterName.Equals("MP", StringComparison.InvariantCultureIgnoreCase);
153+
internal bool IsDoH() => this.MpGpCpParameterName.Equals("CP", StringComparison.InvariantCultureIgnoreCase);
149154

150-
private int AttackMagicPotencyValue => int.Parse(Parse(this.definition.AttackMagicPotency));
151-
152-
private int HealingMagicPotencyValue => int.Parse(Parse(this.definition.HealingMagicPotency));
155+
internal int AttackMagicPotencyInternal => int.TryParse(Parse(this.definition.AttackMagicPotency), out var val) ? val : 0;
156+
157+
internal int HealingMagicPotencyInternal => int.TryParse(Parse(this.definition.HealingMagicPotency), out var val) ? val : 0;
153158
}

NetStone/NetStone.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)