Esempio n. 1
0
        public void WatchFolder_Typical(
            DirectoryPath existingDir,
            FilePath existingFile,
            [Frozen] MockFileSystemWatcher mockFileWatcher,
            [Frozen] MockFileSystem fs)
        {
            FilePath fileB = Path.Combine(existingDir.Path, "FileB");

            fs.File.WriteAllText(existingFile, string.Empty);
            var live = ObservableExt.WatchFolderContents(existingDir.Path, fileSystem: fs)
                       .RemoveKey();
            var list = live.AsObservableList();

            list.Count.Should().Be(1);
            list.Items.ToExtendedList()[0].Should().Be(existingFile);
            fs.File.WriteAllText(fileB, string.Empty);
            mockFileWatcher.MarkCreated(fileB);
            list = live.AsObservableList();
            list.Count.Should().Be(2);
            list.Items.ToExtendedList()[0].Should().Be(existingFile);
            list.Items.ToExtendedList()[1].Should().Be(fileB);
            fs.File.Delete(existingFile);
            mockFileWatcher.MarkDeleted(existingFile);
            list = live.AsObservableList();
            list.Count.Should().Be(1);
            list.Items.ToExtendedList()[0].Should().Be(fileB);
        }
Esempio n. 2
0
        public void FileIsCreated(
            [Frozen] FilePath path,
            [Frozen] MockFileSystemWatcher fileChanges,
            [Frozen] MockFileSystem fs)
        {
            var listingA = new ModListing("ModA.esp", true);
            var reader   = Substitute.For <ICreationClubRawListingsReader>();

            reader.Read(Arg.Any <Stream>()).Returns(listingA.AsEnumerable());
            var list = new CreationClubLiveListingsFileReader(
                fs,
                reader,
                new CreationClubListingsPathInjection(path))
                       .Get(out var state)
                       .AsObservableList();

            list.Items.Should().HaveCount(0);
            var scheduler = new TestScheduler();
            var stateTest = scheduler.Start(() => state);

            stateTest.Messages.Should().HaveCount(1);
            stateTest.Messages[0].Value.Kind.Should().Be(NotificationKind.OnNext);
            stateTest.Messages[0].Value.Value.Succeeded.Should().BeFalse();
            fs.File.WriteAllText(path, string.Empty);
            fileChanges.MarkCreated(path);
            list.Items.Should().HaveCount(1);
            list.Items.First().Should().Be(listingA);
            stateTest = scheduler.Start(() => state);
            stateTest.Messages[^ 1].Value.Kind.Should().Be(NotificationKind.OnNext);
Esempio n. 3
0
        public void WatchFile_Typical(
            [Frozen] FilePath path,
            [Frozen] MockFileSystemWatcher mockFileWatcher,
            [Frozen] MockFileSystem fs)
        {
            int count = 0;

            using var sub = ObservableExt.WatchFile(path, fileWatcherFactory: fs.FileSystemWatcher)
                            .Subscribe(x => count++);
            count.Should().Be(0);
            fs.File.WriteAllText(path, string.Empty);
            mockFileWatcher.MarkCreated(path);
            count.Should().Be(1);
        }
Esempio n. 4
0
        public void WatchFolder_ATypicalSeparator(
            DirectoryPath someDirectory,
            [Frozen] FilePath file,
            [Frozen] MockFileSystemWatcher mockFileWatcher,
            [Frozen] MockFileSystem fs)
        {
            fs.Directory.CreateDirectory(someDirectory);
            var live = ObservableExt.WatchFolderContents(someDirectory.Path.Replace('\\', '/'), fileSystem: fs)
                       .RemoveKey();
            var list = live.AsObservableList();

            list.Count.Should().Be(0);
            fs.File.WriteAllText(file, string.Empty);
            mockFileWatcher.MarkCreated(file);
            list.Count.Should().Be(1);
            list.Items.ToExtendedList()[0].Should().Be(file);
        }
Esempio n. 5
0
        public void WatchFolder_OnlySubfolder(
            [Frozen] DirectoryPath existingDir,
            [Frozen] MockFileSystemWatcher mockFileWatcher,
            [Frozen] MockFileSystem fs)
        {
            FilePath fileA = Path.Combine(existingDir.Path, "SomeFolder", "FileA");
            FilePath fileB = Path.Combine(existingDir.Path, "FileB");

            fs.Directory.CreateDirectory(Path.GetDirectoryName(fileA) !);
            fs.File.WriteAllText(fileA, string.Empty);
            var live = ObservableExt.WatchFolderContents(Path.Combine(existingDir.Path, "SomeFolder"), fileSystem: fs)
                       .RemoveKey();
            var list = live.AsObservableList();

            list.Count.Should().Be(1);
            list.Items.ToExtendedList()[0].Should().Be(fileA);
            fs.File.WriteAllText(fileB, string.Empty);
            mockFileWatcher.MarkCreated(fileB);
            list = live.AsObservableList();
            list.Count.Should().Be(1);
            list.Items.ToExtendedList()[0].Should().Be(fileA);
        }
Esempio n. 6
0
        public void ModAdded(
            ModKey existingModKey,
            IDataDirectoryProvider dataDir,
            MockFileSystemWatcher mockChange,
            MockFileSystem fs,
            CreationClubLiveLoadOrderFolderWatcher sut)
        {
            fs.File.WriteAllText(Path.Combine(dataDir.Path, existingModKey.FileName), string.Empty);
            var list = sut
                       .Get()
                       .AsObservableCache();

            list.Count.Should().Be(1);
            list.Items.First().Should().Be(existingModKey);

            var modKeyB     = ModKey.FromNameAndExtension("NewMod.esm");
            var modKeyBPath = Path.Combine(dataDir.Path, modKeyB.FileName);

            fs.File.WriteAllText(modKeyBPath, string.Empty);
            mockChange.MarkCreated(modKeyBPath);
            list.Count.Should().Be(2);
            list.Items.First().Should().Be(existingModKey);
            list.Items.Last().Should().Be(modKeyB);
        }
        public void LiveLoadOrder(
            [Frozen] IScheduler scheduler,
            [Frozen] MockFileSystemWatcher watcher,
            [Frozen] MockFileSystem fs,
            [Frozen] ILiveLoadOrderTimings timings,
            [Frozen] IPluginListingsPathProvider pluginPath,
            [Frozen] IDataDirectoryProvider dataDir,
            [Frozen] ICreationClubListingsPathProvider cccPath)
        {
            var implicitKey      = Implicits.Get(GameRelease.SkyrimSE).Listings.First();
            var lightMasterPath  = Path.Combine(dataDir.Path, TestConstants.LightMasterModKey.FileName);
            var lightMaster2Path = Path.Combine(dataDir.Path, TestConstants.LightMasterModKey2.FileName);
            var master2Path      = Path.Combine(dataDir.Path, TestConstants.MasterModKey2.FileName);

            fs.File.WriteAllText(lightMasterPath, string.Empty);
            fs.File.WriteAllText(Path.Combine(dataDir.Path, TestConstants.Skyrim.FileName), string.Empty);
            fs.File.WriteAllLines(pluginPath.Path,
                                  new string[]
            {
                $"*{TestConstants.MasterModKey}",
                $"*{TestConstants.MasterModKey2}",
                $"*{TestConstants.PluginModKey}",
            });
            fs.File.WriteAllLines(cccPath.Path,
                                  new string[]
            {
                TestConstants.LightMasterModKey.ToString(),
                TestConstants.LightMasterModKey2.ToString(),
            });
            var live = LoadOrder.GetLiveLoadOrder(
                GameRelease.SkyrimSE,
                pluginPath.Path,
                dataDir.Path,
                out var state,
                scheduler: scheduler,
                cccLoadOrderFilePath: cccPath.Path,
                timings: timings,
                fileSystem: fs);

            state.Subscribe(x =>
            {
                if (x.Failed)
                {
                    throw x.Exception ?? new Exception();
                }
            });
            var list = live.AsObservableList();

            list.Items.Select(x => x.ModKey).Should().Equal(new ModKey[]
            {
                implicitKey,
                TestConstants.LightMasterModKey,
                TestConstants.MasterModKey,
                TestConstants.MasterModKey2,
                TestConstants.PluginModKey,
            });

            fs.File.WriteAllLines(pluginPath.Path,
                                  new string[]
            {
                $"*{TestConstants.MasterModKey}",
                $"*{TestConstants.PluginModKey}",
            });
            watcher.MarkChanged(pluginPath.Path);
            fs.File.WriteAllText(lightMaster2Path, string.Empty);
            watcher.MarkCreated(lightMaster2Path);
            fs.File.Delete(lightMasterPath);
            watcher.MarkDeleted(lightMasterPath);
            list.Items.Select(x => x.ModKey).Should().Equal(new ModKey[]
            {
                implicitKey,
                TestConstants.LightMasterModKey2,
                TestConstants.MasterModKey,
                TestConstants.PluginModKey,
            });

            fs.File.WriteAllLines(pluginPath.Path,
                                  new string[]
            {
                $"*{TestConstants.MasterModKey}",
                $"*{TestConstants.MasterModKey2}",
            });
            watcher.MarkChanged(pluginPath.Path);
            list.Items.Select(x => x.ModKey).Should().Equal(new ModKey[]
            {
                implicitKey,
                TestConstants.LightMasterModKey2,
                TestConstants.MasterModKey,
                TestConstants.MasterModKey2,
            });

            fs.File.WriteAllLines(pluginPath.Path,
                                  new string[]
            {
                $"*{TestConstants.MasterModKey}",
                $"*{TestConstants.MasterModKey2}",
                $"*{TestConstants.PluginModKey}",
            });
            watcher.MarkChanged(pluginPath.Path);
            fs.File.Delete(lightMaster2Path);
            watcher.MarkDeleted(lightMaster2Path);
            list.Items.Select(x => x.ModKey).Should().Equal(new ModKey[]
            {
                implicitKey,
                TestConstants.MasterModKey,
                TestConstants.MasterModKey2,
                TestConstants.PluginModKey,
            });

            // Does not respect just data folder modification
            // Since ModListing doesn't specify whether data folder is present
            // Data folder is just used for Timestamp alignment for Oblivion
            fs.File.Delete(master2Path);
            watcher.MarkDeleted(master2Path);
            list.Items.Select(x => x.ModKey).Should().Equal(new ModKey[]
            {
                implicitKey,
                TestConstants.MasterModKey,
                TestConstants.MasterModKey2,
                TestConstants.PluginModKey,
            });
        }