LateStartStudio / Hero6

Hero6
http://www.hero6.org/
Other
19 stars 6 forks source link

Create 'Hero6' directory if it doesn't already exist #275

Closed brianjlacy closed 5 years ago

brianjlacy commented 5 years ago

Prevents crash when settings directory does not already exist.

codecov[bot] commented 5 years ago

Codecov Report

Merging #275 into master will increase coverage by 0.07%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #275      +/-   ##
==========================================
+ Coverage   50.26%   50.34%   +0.07%     
==========================================
  Files         125      125              
  Lines        3159     3164       +5     
==========================================
+ Hits         1588     1593       +5     
  Misses       1571     1571
Impacted Files Coverage Δ
.../Engine/Utilities/Settings/UserSettings.Desktop.cs 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1d5f4b8...588947b. Read the comment docs.

persn commented 5 years ago

Awesome! So cool to see someone else than me contributing code. I have a busy weekend as I'm attending a kendo tryout both days and I'm pretty beat up after. But I'll give it a review sometime in the early upcoming week

persn commented 5 years ago

Here's what you need to do to write a unit test

  1. Make a IDirectoryWrapper service, look at IFileWrapper.cs to get an idea of what you're supposed to do

  2. Make a provider of the previous service, look at FileWrapper.cs for reference

  3. Add the new service so that the dependency inejctor finds it, take a look at at the constructor in Game.cs. This looks messy right now but I'm going to clean it up and make it better in the future.

  4. In UserSettings, take in the service by the constructor, do it the same I did when I added the IFileWrapper service

  5. Replace the line invoking the Directory.CreateFolder with the wrapper function you created.

Now you're ready to write the actual test!

  1. In UserSettingsTest.cs you'll need to add the new argument to the new UserSettings, you'll notice I wrote a stub for FileWrapper, but we don't need to that here, we can just use the NSubstitute framework to create a fake. http://nsubstitute.github.io/

You need

private IDirectoryWrapper directory;

and

directory = Substitute.For<IDirectoryWrapper>();

  1. Create the test, give it a good name SaveMakesDirectory for instance. What you'll want to do is to check if the wrapped function you made was invoked after invoking Save(), you can do this with NSubstitute http://nsubstitute.github.io/help/received-calls/
persn commented 5 years ago

You should also add your name to the https://github.com/LateStartStudio/Hero6/blob/master/docs/COPYRIGHT.md