Skip to content

Commit

Permalink
Merge pull request #76 from Dotsarecool/major_dependency_injection_ov…
Browse files Browse the repository at this point in the history
…erhaul

Major dependency injection overhaul
  • Loading branch information
binary1230 authored Jan 17, 2022
2 parents 915c6de + de25ddc commit b0d4bc6
Show file tree
Hide file tree
Showing 237 changed files with 11,135 additions and 9,505 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:

- name: Checkout
uses: actions/checkout@v2
with:
submodules: 'recursive'

- name: Setup dotnet
uses: actions/setup-dotnet@v1
Expand Down Expand Up @@ -55,7 +57,7 @@ jobs:
- name: Publish
run: dotnet publish --no-build -c Release /p:PublishProfile=FolderProfile .\DiztinGUIsh\

- uses: papeloto/action-zip@v1
- uses: vimtor/action-zip@v1
with:
files: DiztinGUIsh\bin\Release\net6.0-windows7.0\publish\
dest: ${{ steps.ver.outputs.ver }}.zip
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "Diz.LogWriter"]
path = Diz.LogWriter
url = https://github.com/DizTools/Diz.LogWriter
[submodule "Diz.Ui.Winforms"]
path = Diz.Ui.Winforms
url = https://github.com/DizTools/Diz.Ui.Winforms
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>17.0.0</Version>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<PackageReference Include="FluentAssertions">
<Version>6.2.0</Version>
</PackageReference>
<PackageReference Include="FluentAssertions.Analyzers">
<Version>0.13.0</Version>
</PackageReference>
<PackageReference Include="FluentAssertions.ArgumentMatchers.Moq">
<Version>2.0.0</Version>
</PackageReference>

<PackageReference Include="JetBrains.Annotations">
<Version>2021.3.0</Version>
</PackageReference>
<PackageReference Include="LightInject">
<Version>6.4.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>17.0.0</Version>
</PackageReference>
<PackageReference Include="Moq">
<Version>4.16.1</Version>
</PackageReference>
<PackageReference Include="xunit.abstractions">
<Version>2.0.3</Version>
</PackageReference>
<PackageReference Include="xunit.extensibility.core">
<Version>2.4.1</Version>
</PackageReference>
<PackageReference Include="xunit.runner.console">
<Version>2.4.1</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.analyzers">
<Version>0.10.0</Version>
</PackageReference>
<PackageReference Include="xunit.assert">
<Version>2.4.1</Version>
</PackageReference>

</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Diz.Test\Diz.Test.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Diz.Controllers.controllers;
using Diz.Controllers.interfaces;
using Diz.Core.model;
using Diz.Core.model.project;
using Diz.Core.serialization;
using Diz.Core.util;
using Diz.Cpu._65816.import;
using Diz.Test.Utils;
using FluentAssertions;
using LightInject;
using Moq;
using Xunit;

namespace Diz.Controllers.Test;

public class ImportRomDialogControllerTest : ContainerFixture
{
[Inject] private readonly IImportRomDialogController importRomDialogController = null!;
[Inject] private readonly ISampleRomTestData sampleDataFixture = null!;

public event EventHandler? SimulateViewActions;
private const string RomFilename = "SAMPLEROM";
private ImportRomSettings? generatedSettings;
private Mock<IImportRomDialogView>? mockView = null!;

protected override void Configure(IServiceRegistry serviceRegistry)
{
base.Configure(serviceRegistry);

serviceRegistry.Register<ISampleRomTestData, SampleRomTestDataFixture>(new PerContainerLifetime());

serviceRegistry.Register<IReadFromFileBytes>(factory =>
{
var mockLinkedRomBytesProvider = TestUtil.CreateReadFromFileMock(
factory.GetInstance<ISampleRomTestData>().SampleRomBytes
);
return mockLinkedRomBytesProvider.Object;
});

serviceRegistry.Register(factory => new Mock<ICommonGui>().Object);

serviceRegistry.Register(factory =>
{
mockView = new Mock<IImportRomDialogView>();
mockView.Setup(x => x.ShowAndWaitForUserToConfirmSettings())
.Callback(
() =>
{
SimulateViewActions?.Invoke(null, EventArgs.Empty);
importRomDialogController.Submit();
}).Returns(true);
mockView.SetupGet(x => x.EnabledVectorTableEntries).Returns(new List<string>());
return mockView.Object;
});
}

private void Run(Action? uiActions = null)
{
if (uiActions != null)
SimulateViewActions += (sender, args) => uiActions();

generatedSettings = importRomDialogController.PromptUserForImportOptions(RomFilename);
}

[Fact]
public void Defaults()
{
Run();
generatedSettings!.RomBytes.Should().BeEquivalentTo(sampleDataFixture.SampleRomBytes);
generatedSettings.RomFilename.Should().Be(RomFilename);
}

[Fact]
public void WithNoLabels()
{
Run(() => importRomDialogController.Builder.OptionClearGenerateVectorTableLabels());
generatedSettings!.InitialLabels.Should().BeEmpty("We cleared them in the UI code");
}

[Fact]
public void WithTwoLabels()
{
mockView!.SetupGet(x => x.EnabledVectorTableEntries)
.Returns(new List<string>
{
SnesVectorNames.Native_ABORT,
SnesVectorNames.Emulation_RESET,
});

Run(() =>
{
// importRomDialogController.Builder.OptionSetGenerateVectorTableLabelFor(SnesVectorNames.Native_ABORT, true);
// importRomDialogController.Builder.OptionSetGenerateVectorTableLabelFor(SnesVectorNames.Emulation_RESET, true);
});

var vectorNames = generatedSettings!.InitialLabels.Select(x => x.Value.Name).ToList();
vectorNames.Should().HaveCount(2);
}

public static TheoryData<bool> EnableDisableLabelGeneration =>
new()
{
true,
false
};

[Theory, MemberData(nameof(EnableDisableLabelGeneration))]
public void LabelGenerationDisable(bool labelGenerationEnabled)
{
mockView!.SetupGet(x => x.EnabledVectorTableEntries)
.Returns(new List<string>
{
SnesVectorNames.Native_ABORT,
SnesVectorNames.Emulation_RESET,
});

Run(() =>
{
importRomDialogController.Builder.OptionGenerateSelectedVectorTableLabels = labelGenerationEnabled;
});

generatedSettings!.InitialLabels.Should().HaveCount(labelGenerationEnabled ? 2 : 0);
}

[Fact]
public void ControllerProperties()
{
Run();
importRomDialogController.CartridgeTitle.Should().Be(sampleDataFixture.Project.InternalRomGameName);

var input = importRomDialogController.Builder.Input;

input.Filename.Should().Be(RomFilename);
input.RomBytes.Should().HaveCountGreaterThan(100);
input.RomSettingsOffset!.Value.Should().Be(RomUtil.LoromSettingOffset);

var snesRomAnalysisResults = input.AnalysisResults!;
snesRomAnalysisResults.RomMapMode.Should().Be(RomMapMode.LoRom);
snesRomAnalysisResults.DetectedRomMapModeCorrectly.Should().Be(true);
snesRomAnalysisResults.RomSpeed.Should().Be(sampleDataFixture.Project.Data.RomSpeed);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#nullable enable

using System;
using Diz.Controllers.controllers;
using Diz.Controllers.interfaces;
using Diz.Core.export;
using Diz.Core.util;
using Diz.LogWriter.util;
using Diz.Test.Utils;
using FluentAssertions;
using Moq;
using Xunit;

namespace Diz.Controllers.Test;

public class LogCreatorSettingsEditorControllerTests : ContainerFixture
{
private static IFilesystemService CreateFilesystemMockObject()
{
var fsMock = new Mock<IFilesystemService>();

fsMock.Setup(x => x.DirectoryExists(It.IsAny<string>())).Returns(true);
fsMock.Setup(x => x.CreateDirectory(It.IsAny<string>()));

return fsMock.Object;
}

private static ILogCreatorSettingsEditorView CreateLogCreatorSettingsEditorView()
{
var viewMock = new Mock<ILogCreatorSettingsEditorView>();
viewMock.Setup(x => x.PromptEditAndConfirmSettings()).Returns(true);
return viewMock.Object;
}

[Inject] private readonly Func<LogWriterSettings, ISampleAssemblyTextGenerator> createSampleTextFn = null!;

[Fact]
public void Basics()
{
var fsMock = CreateFilesystemMockObject();
var viewMock = CreateLogCreatorSettingsEditorView();
var controller = new LogCreatorSettingsEditorController(viewMock, fsMock, createSampleTextFn);

controller.ValidateExportSettings().Should().BeTrue("default settings should be valid");
controller.PromptSetupAndValidateExportSettings().Should().BeTrue("dialog unchanged settings should be valid");

controller.GetSampleOutput().Should().Contain("UNREACH");
}

[Fact]
public void TestSampleTextGeneration()
{
createSampleTextFn.Should().NotBeNull();
var x = createSampleTextFn(new LogWriterSettings());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<GitThisAssemblyMetadata>true</GitThisAssemblyMetadata>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
<PackageVersion>3.0.0</PackageVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Diz.Core\Diz.Core.csproj" />
<ProjectReference Include="..\Diz.LogWriter\Diz.LogWriter.csproj" />
<ProjectReference Include="..\..\Diz.Core\Diz.Core.csproj" />
<ProjectReference Include="..\..\Diz.Import\Diz.Import.csproj" />
<ProjectReference Include="..\..\Diz.LogWriter\Diz.LogWriter.csproj" />
</ItemGroup>

<ItemGroup>
Expand All @@ -19,6 +20,9 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="LightInject">
<Version>6.4.0</Version>
</PackageReference>
</ItemGroup>

</Project>
Loading

0 comments on commit b0d4bc6

Please sign in to comment.