From 761f2d952b073b78a06453768992b7b0fd4c6463 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 10 Apr 2022 21:34:18 -0400 Subject: enable nullable annotations in mod data models (#837) --- src/SMAPI.Tests/Core/ModResolverTests.cs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/SMAPI.Tests/Core') diff --git a/src/SMAPI.Tests/Core/ModResolverTests.cs b/src/SMAPI.Tests/Core/ModResolverTests.cs index e1b56559..b8649a7d 100644 --- a/src/SMAPI.Tests/Core/ModResolverTests.cs +++ b/src/SMAPI.Tests/Core/ModResolverTests.cs @@ -145,7 +145,7 @@ namespace SMAPI.Tests.Core { // arrange Mock mock = this.GetMetadata("Mod A", Array.Empty(), allowStatusChange: true); - this.SetupMetadataForValidation(mock, new ModDataRecordVersionedFields + this.SetupMetadataForValidation(mock, new ModDataRecordVersionedFields(this.GetModDataRecord()) { Status = ModStatus.AssumeBroken }); @@ -216,9 +216,9 @@ namespace SMAPI.Tests.Core File.WriteAllText(Path.Combine(modFolder, manifest.EntryDll!), ""); // arrange - Mock mock = new Mock(MockBehavior.Strict); + Mock mock = new(MockBehavior.Strict); mock.Setup(p => p.Status).Returns(ModMetadataStatus.Found); - mock.Setup(p => p.DataRecord).Returns(() => null); + mock.Setup(p => p.DataRecord).Returns(this.GetModDataRecordVersionedFields()); mock.Setup(p => p.Manifest).Returns(manifest); mock.Setup(p => p.DirectoryPath).Returns(modFolder); @@ -265,7 +265,7 @@ namespace SMAPI.Tests.Core public void ProcessDependencies_Skips_Failed() { // arrange - Mock mock = new Mock(MockBehavior.Strict); + Mock mock = new(MockBehavior.Strict); mock.Setup(p => p.Status).Returns(ModMetadataStatus.Failed); // act @@ -380,7 +380,7 @@ namespace SMAPI.Tests.Core Mock modA = this.GetMetadata("Mod A"); Mock modB = this.GetMetadata("Mod B", dependencies: new[] { "Mod A" }); Mock modC = this.GetMetadata("Mod C", dependencies: new[] { "Mod B" }, allowStatusChange: true); - Mock modD = new Mock(MockBehavior.Strict); + Mock modD = new(MockBehavior.Strict); modD.Setup(p => p.Manifest).Returns(null); modD.Setup(p => p.Status).Returns(ModMetadataStatus.Failed); @@ -516,8 +516,8 @@ namespace SMAPI.Tests.Core /// Whether the code being tested is allowed to change the mod status. private Mock GetMetadata(IManifest manifest, bool allowStatusChange = false) { - Mock mod = new Mock(MockBehavior.Strict); - mod.Setup(p => p.DataRecord).Returns(() => null); + Mock mod = new(MockBehavior.Strict); + mod.Setup(p => p.DataRecord).Returns(this.GetModDataRecordVersionedFields()); mod.Setup(p => p.Status).Returns(ModMetadataStatus.Found); mod.Setup(p => p.DisplayName).Returns(manifest.UniqueID); mod.Setup(p => p.Manifest).Returns(manifest); @@ -538,11 +538,22 @@ namespace SMAPI.Tests.Core private void SetupMetadataForValidation(Mock mod, ModDataRecordVersionedFields? modRecord = null) { mod.Setup(p => p.Status).Returns(ModMetadataStatus.Found); - mod.Setup(p => p.DataRecord).Returns(() => null); mod.Setup(p => p.Manifest).Returns(this.GetManifest()); mod.Setup(p => p.DirectoryPath).Returns(Path.GetTempPath()); - mod.Setup(p => p.DataRecord).Returns(modRecord); + mod.Setup(p => p.DataRecord).Returns(modRecord ?? this.GetModDataRecordVersionedFields()); mod.Setup(p => p.GetUpdateKeys(It.IsAny())).Returns(Enumerable.Empty()); } + + /// Generate a default mod data record. + private ModDataRecord GetModDataRecord() + { + return new("Default Display Name", new ModDataModel("Sample ID", null, ModWarning.None)); + } + + /// Generate a default mod data versioned fields instance. + private ModDataRecordVersionedFields GetModDataRecordVersionedFields() + { + return new ModDataRecordVersionedFields(this.GetModDataRecord()); + } } } -- cgit