Here is a small explanation of the modifications made on the project
THe bug was the If/If else condition in the SpellChecker.cs file, CanUserCastSpell function
The TransGr8-DD-Test\Helper\User is a field/property connection between the TransGr8-DD-Test\User and TransGr8-DD-Test\Spell, to make it easy for future dynamic condition checking.
/// <summary>
/// Spell components mapped with user fileds
/// </summary>
public Dictionary<string, string> SpellComponentsWithUserFileds
{
get
{
return new Dictionary<string, string>()
{
{"V", "HasVerbalComponent" },
{"S", "HasSomaticComponent" },
{"M", "HasMaterialComponent" }
};
}
}
Using the Serilog package to display logs and save logs to files. The LoggerHelper is static class to use the same Logger for the whole session, and save the logs to the same file.
To get users or spells data, i created a service to load data.
Load data from Json file
Load data from generated objects
I create an interface for every dependent functionality of this project, like verifying the Range of the spell or the Duration.
The name is litte bite forward, but this class implements all the interfaces with virtual functions to be overrider at the future. The main function CanUserCastSpell(User user, Spell spell) is not implemented in this class, it's left for the children classes to implement with the other functions
/// <summary>
/// Obligatory function to check if the user can cast a spell
/// This function will regroup all the function above to give a proper results
/// </summary>
/// <param name="user"></param>
/// <param name="spellName"></param>
/// <returns></returns>
public virtual bool CanUserCastSpell(User user, string spellName)
{
return true;
}
Users data is stored in the json file ./data/users.json
As an avid D&D player, I have written an application which allows me to check if a user has the correct stats to cast spells in my quest.
I have a found some bug in the code but not too sure about how to fix it.
I have read some things online about a principal called SOLID and Rule Engines which I think may help me identify and fix the issue.
- I would like the code fixed so that we follow the new principal, without changing the signature of the Method
public bool CanUserCastSpell(User user, string spellName)
- I would like the Bug identified and fixed
- I would like the Unit Tests provided to be extended so they capture new tests as they are required
The bug is defined as such:
When the Spell is "Cure Wounds" and the User DOES NOT HAVE "Somatic Component" then they are still able to cast the spell.
The code which needs to be modified is centered in 2 files
- SpellChecker.cs
- SpellCheckerTests.cs
- Load all users into the application - Via a JSON File
- Select a User to Check the Spell for
- Use a Logger (Serilog) to write the messages rather than a Console.WriteLine statement.