Mutagen-Modding / Mutagen.Bethesda.Analyzers

A project to diagnose and analyze the health of a mod or a load order
GNU General Public License v3.0
14 stars 4 forks source link

Moq data #74

Closed Noggog closed 2 years ago

Noggog commented 2 years ago

Added MoqData which is an Autofixture attribute that uses Mutagen.Bethesda.Testing, but with a Moq backing instead

Added a test for MissingAssetsAnalyzerTests, just to give a little proof of concept.

Few things I like about it

Easier MissingAssetsAnalyzer sut instantiation.

Didn't need to even interact with ILogger or MockFileSystem. Didn't care to access/use them, so they're hidden away.

Side note: In the situations where we did care about dependency X of a SUT we were testing, we can still opt in to get access to just that one:

public void SomeOtherTest(
    [Frozen] Mock<ISomeDependencyOurAnalyzerHas> dep
    MissingAssetsAnalyzer analyzer)
{
    dep.Setup(x => x.SomeMember).Returns(45);
    // ...            

If MissingAssetsAnalyzer had 6 dependencies, we still dont have to deal with most of them, while getting access to the one we want to mock it as we like. [Frozen] ensures the mock is a singleton so the one we're getting is also the one passed to the sut

Easy existing file test

Since the MoqData attribute is making our MockFileSystem and injecting it into our analyzer for us, we can just define FilePath existingDiffuse and it will make a file that exists within the file system for us.

This made for a very easy TestExistingTextureSetTextures where I didn't have to spam the page doing all the fileSystem.File.CreateFile(somePath) prep. Just used the paths in the TextureSet mock and then good to go

General Thoughts

I dont think it needs to be used by everyone contributing if they prefer without, but I'd like to have it on the toolbelt for when I'm writing tests myself.