Skip to content

Commit

Permalink
* Update tests to include immunities
Browse files Browse the repository at this point in the history
* Tests now use .NET 8
* Ensure comparisons are case insensitive for immunity testing
  • Loading branch information
baughj committed Dec 10, 2023
1 parent 8e0c83e commit cea6b3c
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/Extensions/CastableDamage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public partial class CastableDamage

// temporary silliness due to xsd issues
public bool IsEmpty => IsSimple && Simple.Value == 0 && Simple.Min == 0 && Simple.Max == 0;

}
33 changes: 22 additions & 11 deletions src/Extensions/CreatureBehaviorSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//
// For contributors and individual authors please refer to CONTRIBUTORS.MD.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
Expand Down Expand Up @@ -129,56 +130,66 @@ public static void ProcessAll(IWorldDataManager manager)

public bool ImmuneToElement(ElementType type, out CreatureImmunity immunity)
{
immunity = Immunities?.FirstOrDefault(x => x.Type == CreatureImmunityType.Element && x.Value == type.ToString());
immunity = Immunities?.FirstOrDefault(x =>
x.Type == CreatureImmunityType.Element &&
string.Equals(x.Value, type.ToString(), StringComparison.CurrentCultureIgnoreCase));
return immunity != null;
}

public bool ImmuneToElement(string type, out CreatureImmunity immunity)
{
immunity = Immunities?.FirstOrDefault(x => x.Type == CreatureImmunityType.Element && x.Value == type);
immunity = Immunities?.FirstOrDefault(x =>
x.Type == CreatureImmunityType.Element &&
string.Equals(x.Value, type, StringComparison.CurrentCultureIgnoreCase));
return immunity != null;
}

public bool ImmuneToCastableCategory(string category, out CreatureImmunity immunity)
{
immunity = Immunities?.FirstOrDefault(x =>
x.Type == CreatureImmunityType.CastableCategory && x.Value == category);
x.Type == CreatureImmunityType.CastableCategory &&
string.Equals(x.Value, category, StringComparison.CurrentCultureIgnoreCase));
return immunity != null;
}

public bool ImmuneToStatusCategory(string category, out CreatureImmunity immunity)
{
immunity = Immunities?.FirstOrDefault(x =>
x.Type == CreatureImmunityType.StatusCategory && x.Value == category);
x.Type == CreatureImmunityType.StatusCategory &&
string.Equals(x.Value, category, StringComparison.CurrentCultureIgnoreCase));
return immunity != null;
}


public bool ImmuneToStatus(string status, out CreatureImmunity immunity)
{
immunity = Immunities?.FirstOrDefault(x => x.Type == CreatureImmunityType.Status && x.Value == status);
immunity = Immunities?.FirstOrDefault(x =>
x.Type == CreatureImmunityType.Status &&
string.Equals(x.Value, status, StringComparison.CurrentCultureIgnoreCase));
return immunity != null;
}

public bool ImmuneToStatus(Status status, out CreatureImmunity immunity)
{
immunity = Immunities?.FirstOrDefault(x => x.Type == CreatureImmunityType.Status && x.Value == status.Name);
immunity = Immunities?.FirstOrDefault(x =>
x.Type == CreatureImmunityType.Status &&
string.Equals(x.Value, status.Name, StringComparison.CurrentCultureIgnoreCase));
return immunity != null;
}

public bool ImmuneToCastable(string castable, out CreatureImmunity immunity)
{
immunity = Immunities?.FirstOrDefault(x => x.Type == CreatureImmunityType.Castable && x.Value == castable);
immunity = Immunities?.FirstOrDefault(x =>
x.Type == CreatureImmunityType.Castable &&
string.Equals(x.Value, castable, StringComparison.CurrentCultureIgnoreCase));
return immunity != null;
}

public bool ImmuneToCastable(Castable castable, out CreatureImmunity immunity)
{
immunity = Immunities?.FirstOrDefault(x =>
x.Type == CreatureImmunityType.Castable && x.Value == castable.Name);
x.Type == CreatureImmunityType.Castable &&
string.Equals(x.Value, castable.Name, StringComparison.CurrentCultureIgnoreCase));
return immunity != null;
}



}
4 changes: 2 additions & 2 deletions src/Hybrasyl.Xml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<AssemblyName>Hybrasyl.Xml</AssemblyName>
<RootNamespace>Hybrasyl.Xml</RootNamespace>
<PackageVersion>0.9.3.26</PackageVersion>
<Version>0.9.3.26</Version>
<PackageVersion>0.9.3.27</PackageVersion>
<Version>0.9.3.27</Version>
<BuildDocFx Condition="'$(Configuration)'=='Debug'">false</BuildDocFx>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Authors>ERISCO LLC</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/XSD/Castable.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
<xs:element name="Animations" type="hyb:SpellAnimations" minOccurs="0" maxOccurs="1" />
<xs:element name="Sound" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="Id" type="xs:unsignedByte" use="optional" default="255" />
<xs:attribute name="Id" type="xs:unsignedByte" use="optional" default="1" />
</xs:complexType>
</xs:element>
<xs:element name="Heal" minOccurs="0" maxOccurs="1" type="hyb:CastableHeal" />
Expand Down
1 change: 1 addition & 0 deletions tests/Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ public void Resistances()
Assert.Empty(modifier.Augments);
Assert.Empty(modifier.Resistances);
}

}
60 changes: 60 additions & 0 deletions tests/Immunities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Hybrasyl.XmlTests;
using Hybrasyl.Xml.Objects;
using Xunit.Abstractions;

namespace Hybrasyl.XmlTests;

[Collection("Xml")]
public class ImmunitiesTests(ITestOutputHelper output, XmlManagerFixture fixture) : IClassFixture<XmlManagerFixture>
{
private readonly ITestOutputHelper Output = output;
private readonly XmlManagerFixture Fixture = fixture;

[Fact]
public void CastableImmunity()
{
var castableImmune = Fixture.SyncManager.Get<CreatureBehaviorSet>("CastableImmune");
Assert.NotNull(castableImmune);
var immuneTo = Fixture.SyncManager.GetByIndex<Castable>("ard srad");
Assert.NotNull(immuneTo);
Assert.True(castableImmune.ImmuneToCastable(immuneTo, out var immunity));
Assert.True(castableImmune.ImmuneToCastable("ard srad", out immunity));
Assert.True(castableImmune.ImmuneToCastable("aRd sRaD", out immunity));
var notImmune = Fixture.SyncManager.Get<CreatureBehaviorSet>("BasicAssCritter");
Assert.NotNull(notImmune);
Assert.False(notImmune.ImmuneToCastable(immuneTo, out immunity));
Assert.False(notImmune.ImmuneToCastable("ard srad", out immunity));
}

[Fact]
public void CastableCategoryImmunity()
{
var castableImmune = Fixture.SyncManager.Get<CreatureBehaviorSet>("CastCatImmune");
Assert.NotNull(castableImmune);
Assert.True(castableImmune.ImmuneToCastableCategory("Debuff", out var immunity));
Assert.True(castableImmune.ImmuneToCastableCategory("DeBuFf", out immunity));
}

[Fact]
public void StatusImmunity()
{
var statusImmune = Fixture.SyncManager.Get<CreatureBehaviorSet>("StatusImmune");
var status = Fixture.SyncManager.Get<Status>("TestPlusAc");

Assert.NotNull(statusImmune);
Assert.NotNull(status);
Assert.True(statusImmune.ImmuneToStatus("TeStPlUsAc", out _));
Assert.True(statusImmune.ImmuneToStatus("testplusac", out _));
Assert.True(statusImmune.ImmuneToStatus(status, out _));
}

[Fact]
public void StatusCategoryImmunity()
{
var statusImmune = Fixture.SyncManager.Get<CreatureBehaviorSet>("StatCatImmune");
Assert.NotNull(statusImmune);
Assert.True(statusImmune.ImmuneToStatusCategory("Str", out _));
}
}


2 changes: 1 addition & 1 deletion tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion tests/XmlEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public XmlEntityTests(ITestOutputHelper output, XmlManagerFixture fixture)
public void CreatureAssailSoundIsByte()
{
// Occasionally xsd2code will make this an sbyte, for unknown reasons,
// so we test for that hre
// so we test for that here
var f = new Creature();
Assert.IsType<byte>(f.AssailSound);
}
Expand Down
1 change: 1 addition & 0 deletions tests/XmlManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,5 @@ public void LoadDataAsync()
{

}

}

0 comments on commit cea6b3c

Please sign in to comment.