Beispiel #1
0
        public async Task CreatesOutput()
        {
            using var tmpFolder  = Utility.GetTempFolder();
            using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.Oblivion);
            var settings = new CodeSnippetPatcherSettings()
            {
                On       = true,
                Code     = @"// Let's do work! 
                    int wer = 23; 
                    wer++;",
                Nickname = "UnitTests",
            };
            var outputFile = Utility.TypicalOutputFile(tmpFolder);
            var snippet    = new CodeSnippetPatcherRun(settings);
            await snippet.Prep(GameRelease.Oblivion, CancellationToken.None);

            await snippet.Run(new RunSynthesisPatcher()
            {
                OutputPath        = ModPath.FromPath(outputFile),
                DataFolderPath    = dataFolder.Dir.Path,
                GameRelease       = GameRelease.Oblivion,
                LoadOrderFilePath = Utility.PathToLoadOrderFile,
                SourcePath        = null
            }, CancellationToken.None);

            Assert.True(File.Exists(outputFile));
        }
Beispiel #2
0
        public static void TestPlugin(string path, Action <ISkyrimModDisposableGetter> verify)
        {
            Assert.True(File.Exists(path));

            using var mod = SkyrimMod.CreateFromBinaryOverlay(ModPath.FromPath(path), SkyrimRelease.SkyrimSE);
            verify(mod);
        }
Beispiel #3
0
        public async Task RunTwice()
        {
            using var tmpFolder  = Utility.GetTempFolder();
            using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.Oblivion);
            var outputFile = Utility.TypicalOutputFile(tmpFolder);
            var settings   = new CodeSnippetPatcherSettings()
            {
                On       = true,
                Code     = @"state.PatchMod.Npcs.AddNew();",
                Nickname = "UnitTests",
            };

            for (int i = 0; i < 2; i++)
            {
                var snippet = new CodeSnippetPatcherRun(settings);
                await snippet.Prep(GameRelease.Oblivion, CancellationToken.None);

                await snippet.Run(new RunSynthesisPatcher()
                {
                    OutputPath        = ModPath.FromPath(outputFile),
                    DataFolderPath    = dataFolder.Dir.Path,
                    GameRelease       = GameRelease.Oblivion,
                    LoadOrderFilePath = Utility.PathToLoadOrderFile,
                    SourcePath        = i == 1 ? outputFile.Path : null
                }, CancellationToken.None);
            }
            using var mod = OblivionMod.CreateFromBinaryOverlay(outputFile);
            Assert.Equal(2, mod.Npcs.Count);
        }
        public void ExceptionDisposesExistingMods()
        {
            var dataFolder = "C:/DataFolder";
            var modPaths   = new ModKey[]
            {
                TestConstants.MasterModKey,
                TestConstants.MasterModKey2,
            }
            .Select(x => ModPath.FromPath(Path.Combine(dataFolder, x.FileName)))
            .ToArray();
            var fs = Substitute.For <IFileSystem>();

            fs.File.Exists(Arg.Any <string>()).Returns(true);
            var importer = Substitute.For <IModImporter <IModDisposeGetter> >();
            var mod      = Substitute.For <IModDisposeGetter>();

            importer.Import(modPaths.First()).Returns(mod);
            importer.Import(modPaths.Last()).Throws(new ArgumentException());
            Assert.Throws <AggregateException>(() =>
            {
                new LoadOrderImporter <IModDisposeGetter>(
                    fs,
                    new DataDirectoryInjection(dataFolder),
                    new LoadOrderListingsInjection(modPaths.Select(x => x.ModKey).ToArray()),
                    importer)
                .Import();
            });
            mod.Received().Dispose();
        }
Beispiel #5
0
        public override object?ConvertFrom(ITypeDescriptorContext?context, CultureInfo?culture, object value)
        {
            switch (value)
            {
            case string str:
                return(ModPath.FromPath(str));

            default:
                return(new NotImplementedException());
            }
        }
Beispiel #6
0
        public void NonSynthesisTarget()
        {
            var env        = Utility.SetupEnvironment(GameRelease.SkyrimLE);
            var output     = ModPath.FromPath(Path.Combine(env.DataFolder, Utility.OtherFileName));
            var pluginPath = Path.Combine(env.DataFolder, "Plugins.txt");

            env.FileSystem.File.WriteAllLines(pluginPath,
                                              new string[]
            {
                $"*{Utility.TestFileName}",
                $"*{Utility.OverrideFileName}",
                $"*{output.ModKey.FileName}",
                $"*{Utility.OtherFileName}",
                $"*{Utility.SynthesisModKey}",
            });
            var settings = new RunSynthesisMutagenPatcher()
            {
                DataFolderPath    = env.DataFolder,
                GameRelease       = GameRelease.SkyrimLE,
                LoadOrderFilePath = env.PluginPath,
                OutputPath        = output,
                SourcePath        = null
            };
            var stateFactory = env.GetStateFactory();

            using var state = stateFactory.ToState(
                      GameCategory.Skyrim,
                      settings,
                      new PatcherPreferences(),
                      output.ModKey);
            state.RawLoadOrder.Should().HaveCount(3);
            state.RawLoadOrder.Select(l => l.ModKey).Should().Equal(new ModKey[]
            {
                Utility.TestFileName,
                Utility.OverrideModKey,
                output.ModKey,
            });
        }
        public void EntryDoesNotExist()
        {
            var dataFolder = "C:/DataFolder";
            var modPaths   = new ModKey[]
            {
                TestConstants.MasterModKey,
                TestConstants.MasterModKey2,
                TestConstants.MasterModKey3,
            }
            .Select(x => ModPath.FromPath(Path.Combine(dataFolder, x.FileName)))
            .ToArray();
            var fs = new MockFileSystem(
                modPaths
                .Skip(1)
                .ToDictionary(x => (string)x.Path, x => new MockFileData(string.Empty)));
            var importer = Substitute.For <IModImporter <TestMod> >();

            foreach (var modPath in modPaths)
            {
                importer.Import(modPath).Returns(new TestMod(modPath.ModKey));
            }
            var lo = new LoadOrderImporter <TestMod>(
                fs,
                new DataDirectoryInjection(dataFolder),
                new LoadOrderListingsInjection(modPaths.Select(x => x.ModKey).ToArray()),
                importer)
                     .Import();

            lo.Count.Should().Be(3);
            lo.First().Value.Mod.Should().BeNull();
            lo.First().Value.ModKey.Should().Be(TestConstants.MasterModKey);
            lo.Select(x => x.Value.Mod)
            .Skip(1)
            .Should().Equal(
                modPaths
                .Skip(1)
                .Select(x => importer.Import(x)));
        }
Beispiel #8
0
        public void NonSynthesisTarget()
        {
            using var tmpFolder  = Utility.GetTempFolder();
            using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.SkyrimLE);
            var output     = ModPath.FromPath(Path.Combine(dataFolder.Dir.Path, Utility.OtherFileName));
            var pluginPath = Path.Combine(tmpFolder.Dir.Path, "Plugins.txt");

            File.WriteAllLines(pluginPath,
                               new string[]
            {
                $"*{Utility.TestFileName}",
                $"*{Utility.OverrideFileName}",
                $"*{output.ModKey.FileName}",
                $"*{Utility.OtherFileName}",
                $"*{Utility.SynthesisModKey}",
            });
            var settings = new RunSynthesisMutagenPatcher()
            {
                DataFolderPath    = dataFolder.Dir.Path,
                GameRelease       = GameRelease.SkyrimLE,
                LoadOrderFilePath = Utility.PathToLoadOrderFile,
                OutputPath        = output,
                SourcePath        = null
            };

            using var state = Mutagen.Bethesda.Synthesis.Internal.Utility.ToState(
                      GameCategory.Skyrim,
                      settings,
                      new PatcherPreferences(),
                      output.ModKey);
            state.RawLoadOrder.Should().HaveCount(3);
            state.RawLoadOrder.Select(l => l.ModKey).Should().Equal(new ModKey[]
            {
                Utility.TestFileName,
                Utility.OverrideModKey,
                output.ModKey,
            });
        }