-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from Dotsarecool/major_dependency_injection_ov…
…erhaul Major dependency injection overhaul
- Loading branch information
Showing
237 changed files
with
11,135 additions
and
9,505 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
69 changes: 69 additions & 0 deletions
69
Diz.Controllers/Diz.Controllers.Test/Diz.Controllers.Test/Diz.Controllers.Test.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
148 changes: 148 additions & 0 deletions
148
Diz.Controllers/Diz.Controllers.Test/Diz.Controllers.Test/src/ImportRomDialogontroller.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
.../Diz.Controllers.Test/Diz.Controllers.Test/src/LogCreatorSettingsEditorControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.