Ejemplo n.º 1
0
        public void SetUp()
        {
            MockTracer tracer = new MockTracer();

            string enlistmentRoot  = Path.Combine("mock:", "GVFS", "UnitTests", "Repo");
            string statusCachePath = Path.Combine("mock:", "GVFS", "UnitTests", "Repo", ".gvfs", "gitStatusCache");

            this.gitProcess = new MockGitProcess();
            this.gitProcess.SetExpectedCommandResult($"--no-optional-locks status \"--serialize={statusCachePath}", () => new GitProcess.Result(string.Empty, string.Empty, 0), true);
            MockGVFSEnlistment enlistment = new MockGVFSEnlistment(enlistmentRoot, "fake://repoUrl", "fake://gitBinPath", null, this.gitProcess);

            enlistment.InitializeCachePathsFromKey("fake:\\gvfsSharedCache", "fakeCacheKey");

            this.gitParentPath    = enlistment.WorkingDirectoryRoot;
            this.gvfsMetadataPath = enlistment.DotGVFSRoot;

            this.enlistmentDirectory = new MockDirectory(
                enlistmentRoot,
                new MockDirectory[]
            {
                new MockDirectory(this.gitParentPath, folders: null, files: null),
            },
                null);

            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "config"), ".git config Contents", createDirectories: true);
            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "HEAD"), ".git HEAD Contents", createDirectories: true);
            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "logs", "HEAD"), "HEAD Contents", createDirectories: true);
            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "info", "always_exclude"), "always_exclude Contents", createDirectories: true);
            this.enlistmentDirectory.CreateDirectory(Path.Combine(this.gitParentPath, ".git", "objects", "pack"));

            this.fileSystem = new MockFileSystem(this.enlistmentDirectory);
            this.fileSystem.AllowMoveFile = true;
            this.fileSystem.DeleteNonExistentFileThrowsException = false;

            this.context = new GVFSContext(
                tracer,
                this.fileSystem,
                new MockGitRepo(tracer, enlistment, this.fileSystem),
                enlistment);
        }
Ejemplo n.º 2
0
        public virtual void Setup()
        {
            //ViewFactory.Current = new MockViewFactory();
            Logger.Current              = new MockLogger();
            FileSystem.Current          = new MockFileSystem();
            EnvironmentSettings.Current = new MockEnvironmentSettings();
            TimeService.Current         = new MockTimeService();
            Registry.Current            = new MockRegistry();
            IdentityGenerator.Current   = new MockIdentityGenerator();
            HttpRequestManager.Current  = new MockHttpRequestManager();
            Config.Current              = new MockConfig();
            ArchiveFactory.Current      = new MockArchiveFactory();

            //managers relevant to installing and installing games.
            GameExplorer.Current    = new MockGameExplorer();
            IconManager.Current     = new MockIconManager();
            ProcessManager.Current  = new MockProcessManager();
            ShortcutManager.Current = new MockShortcutManager();

            ((MockRegistry)Registry.Current).AddFakeKey(BaseRegistryKey.LocalMachine, new MockRegistryKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"));

            MockDirectory volumeRoot = MockFileSystem.AddVolumeRoot("C:");

            volumeRoot.AddDirectory("temp");
            MockDirectory documentsDir = volumeRoot.AddDirectory("Documents and Settings");

            documentsDir.AddDirectory("All Users").AddDirectory("Application Data");
            MockDirectory userDir = documentsDir.AddDirectory("user");

            userDir.AddDirectory("Local Settings").AddDirectory("Application Data");
            userDir.AddDirectory("desktop");
            userDir.AddDirectory("start menu");
            volumeRoot.AddDirectory("Documents and Settings").AddDirectory("All Users").AddDirectory("Application Data");

            MockDirectory mgdfDirectory = volumeRoot.AddDirectory("program files").AddDirectory("MGDF");

            mgdfDirectory.AddDirectory("game");

            Resources.InitUpdaterDirectories();
        }
        public void PreparePluginContainerForTransferWithMultipleDirectories()
        {
            var files = new List <string>
            {
                typeof(string).Assembly.LocalFilePath(),
                typeof(HostApplicationCommands).Assembly.LocalFilePath(),
                Assembly.GetExecutingAssembly().LocalFilePath()
            };
            var mockDirectory = new MockDirectory(files);
            var fileSystem    = new Mock <IFileSystem>();
            {
                fileSystem.Setup(f => f.Directory)
                .Returns(() => mockDirectory);
            }

            var uploads = new Mock <IStoreUploads>();
            {
                uploads.Setup(u => u.Register(It.IsAny <string>()))
                .Callback <string>(f => Assert.AreEqual(files[1], f))
                .Returns(new UploadToken())
                .Verifiable();
            }

            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(true);
                configuration.Setup(c => c.Value <List <string> >(It.IsAny <ConfigurationKey>()))
                .Returns(new List <string> {
                    "bla1", "bla2", "bla3"
                });
            }

            var commands = new HostApplicationCommands(fileSystem.Object, uploads.Object, configuration.Object);
            var task     = commands.PreparePluginContainerForTransfer(typeof(HostApplicationCommands).Assembly.GetName());

            task.Wait();

            uploads.Verify(u => u.Register(It.IsAny <string>()), Times.Once());
        }
Ejemplo n.º 4
0
        public CommonRepoSetup()
        {
            MockTracer tracer = new MockTracer();

            string         enlistmentRoot = Path.Combine("mock:", "GVFS", "UnitTests", "Repo");
            GVFSEnlistment enlistment     = new GVFSEnlistment(enlistmentRoot, "fake://repoUrl", "fake://gitBinPath", null);

            enlistment.InitializeCachePathsFromKey("fake:\\gvfsSharedCache", "fakeCacheKey");

            this.GitParentPath    = enlistment.WorkingDirectoryRoot;
            this.GVFSMetadataPath = enlistment.DotGVFSRoot;

            MockDirectory enlistmentDirectory = new MockDirectory(
                enlistmentRoot,
                new MockDirectory[]
            {
                new MockDirectory(this.GitParentPath, folders: null, files: null),
            },
                null);

            enlistmentDirectory.CreateFile(Path.Combine(this.GitParentPath, ".git", "config"), ".git config Contents", createDirectories: true);
            enlistmentDirectory.CreateFile(Path.Combine(this.GitParentPath, ".git", "HEAD"), ".git HEAD Contents", createDirectories: true);
            enlistmentDirectory.CreateFile(Path.Combine(this.GitParentPath, ".git", "logs", "HEAD"), "HEAD Contents", createDirectories: true);
            enlistmentDirectory.CreateFile(Path.Combine(this.GitParentPath, ".git", "info", "always_exclude"), "always_exclude Contents", createDirectories: true);
            enlistmentDirectory.CreateDirectory(Path.Combine(this.GitParentPath, ".git", "objects", "pack"));

            MockFileSystem fileSystem = new MockFileSystem(enlistmentDirectory);

            this.Repository = new MockGitRepo(
                tracer,
                enlistment,
                fileSystem);
            CreateStandardGitTree(this.Repository);

            this.Context = new GVFSContext(tracer, fileSystem, this.Repository, enlistment);

            this.HttpObjects = new MockHttpGitObjects(tracer, enlistment);
            this.GitObjects  = new MockGVFSGitObjects(this.Context, this.HttpObjects);
        }
Ejemplo n.º 5
0
        public void LoadInvalidGameInvalidXML()
        {
            const string InvalidXml = @"{
  ""gameUid"":""Console"",
  ""gameName"":""Lua Console"",
  ""description"":""A Lua command console for interacting with the MGDF system"",
  ""version"":""1.0 Beta 2"",
  ""interfaceVersion"":""1"",
  ""developerUid"":""no-8"",
  ""developerName"":""no8 interactive"",
  ""homepage"":""http://www.junkship.org"",
  ""gameSourceService"":""http://games.junkship.org/gamesource.asmx"",
  ""statisticsService"":""http://statistics.junkship.org/statisticsService.asmx"",
  ""statisticsPrivacyPolicy"":""We wont use ur informationz""";

            MockDirectory gameDirectory = ((MockDirectory)MockFileSystem.GetDirectory(EnvironmentSettings.Current.AppDirectory + "\\game"));

            gameDirectory.AddFile("game.json", InvalidXml);
            Game game = new Game(Path.Combine(EnvironmentSettings.Current.AppDirectory, "game\\game.json"));

            Assert.AreEqual(false, game.IsValid);
            Assert.AreEqual(1, game.ErrorCollection.Count);
        }
Ejemplo n.º 6
0
        public void TestCanSendStatisticsDeniedNoPrivacyPolicy()
        {
            const string gameContent = @"{
  ""gameUid"":""Console"",
  ""gameName"":""Lua Console"",
  ""description"":""A Lua command console for interacting with the MGDF system"",
  ""version"":""0.1"",
  ""interfaceVersion"":""1"",
  ""developerUid"":""no-8"",
  ""developerName"":""no8 interactive"",
  ""homepage"":""http://www.junkship.org"",
  ""gamesourceService"":""http://games.junkship.org/gamesource.asmx"",
  ""statisticsService"":""http://statistics.junkship.org/statisticsservice.asmx"",
  ""supportEmail"":""*****@*****.**""
}";

            MockDirectory gameDirectory = ((MockDirectory)MockFileSystem.GetDirectory(EnvironmentSettings.Current.AppDirectory + "\\game"));

            gameDirectory.AddFile("game.json", gameContent);
            Game game = new Game(Path.Combine(EnvironmentSettings.Current.AppDirectory, "game\\game.json"));

            Assert.IsFalse(StatisticsSession.CanSendStatistics(game));
        }
Ejemplo n.º 7
0
        public void LoadGameInstaller()
        {
            MockDirectory desktopDir = (MockDirectory)MockFileSystem.GetDirectory("C:\\Documents and Settings\\user\\desktop");

            desktopDir.AddFile("game.zip", "data");


            MockArchiveFile archive = new MockArchiveFile(null, "C:\\Documents and Settings\\user\\desktop\\game.mza");

            new MockArchiveFile(archive, "game.json", ReadTextFile("console.json"));
            new MockArchiveFile(archive, "preferences.json", ReadTextFile("preferences.json"));
            new MockArchiveFile(archive, "content");
            new MockArchiveFile(archive, "bin");
            ((MockArchiveFactory)ArchiveFactory.Current).VirtualArchives.Add("C:\\Documents and Settings\\user\\desktop\\game.mza", archive);

            GameInstall install = new GameInstall("C:\\Documents and Settings\\user\\desktop\\game.mza");

            Assert.IsNotNull(install);
            Assert.IsTrue(install.IsValid);

            Assert.AreEqual("http://games.junkship.org/gamesource.asmx", install.Game.UpdateService);
            Assert.AreEqual("http://www.junkship.org", install.Game.Homepage);
            Assert.AreEqual(1, install.Game.InterfaceVersion);
            Assert.IsFalse(install.IsUpdate);
            Assert.AreEqual("Lua Console", install.Game.Name);
            Assert.AreEqual("We wont use ur informationz", install.Game.StatisticsPrivacyPolicy);
            Assert.AreEqual("http://statistics.junkship.org/statisticsservice.asmx", install.Game.StatisticsService);
            Assert.AreEqual("*****@*****.**", install.Game.SupportEmail);
            Assert.AreEqual("Console", install.Game.Uid);
            Assert.AreEqual(new Version(0, 1), install.Game.Version);

            Assert.IsNull(install.Update);
            Assert.IsFalse(install.IsUpdate);

            Assert.AreEqual("C:\\Documents and Settings\\user\\desktop\\game.mza", install.InstallerFile);
        }
Ejemplo n.º 8
0
        public void SearchWithDeletedFilesOnly()
        {
            var pluginFiles = new List <PluginFileInfo>
            {
                new PluginFileInfo(@"c:\temp\foobar.dll", DateTimeOffset.Now),
                new PluginFileInfo(@"c:\temp\foobar2.dll", DateTimeOffset.Now.AddHours(-2)),
            };

            var repository = new Mock <IPluginRepository>();
            {
                repository.Setup(r => r.KnownPluginFiles())
                .Returns(pluginFiles);
            }

            var mockFile      = new MockFile(new Dictionary <string, string>());
            var mockDirectory = new MockDirectory(new List <string>());
            var fileSystem    = new Mock <IFileSystem>();
            {
                fileSystem.Setup(f => f.File)
                .Returns(mockFile);
                fileSystem.Setup(f => f.Directory)
                .Returns(mockDirectory);
            }

            var scanner = new MockScanner();
            Func <IPluginRepository, IAssemblyScanner> scannerBuilder = r => scanner;

            var detector = new PluginDetector(
                repository.Object,
                scannerBuilder,
                fileSystem.Object,
                new SystemDiagnostics((p, s) => { }, null));

            detector.SearchDirectory(@"c:\temp");
            Assert.IsNull(scanner.FilesToScan);
        }
Ejemplo n.º 9
0
 public void AddDirectory(string name, MockDirectory dir)
 {
     EnsureEntryDontExist(name);
     _directories.Add(name, dir);
 }
Ejemplo n.º 10
0
 public bool TryGetDirectory(string name, out MockDirectory dir)
 {
     return(_directories.TryGetValue(name, out dir));
 }
Ejemplo n.º 11
0
 public void VerifyNotDeleted()
 {
     MockDirectory.Verify(m => m.Delete(true), Times.Never());
 }
Ejemplo n.º 12
0
        private void TestSetup(DateTime lastRun)
        {
            string lastRunTime = EpochConverter.ToUnixEpochSeconds(lastRun).ToString();

            this.gitProcess = new MockGitProcess();

            // Create enlistment using git process
            GVFSEnlistment enlistment = new MockGVFSEnlistment(this.gitProcess);

            // Create a last run time file
            MockFile timeFile = new MockFile(Path.Combine(enlistment.GitObjectsRoot, "info", PackfileMaintenanceStep.PackfileLastRunFileName), lastRunTime);

            // Create info directory to hold last run time file
            MockDirectory info = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "info"),
                null,
                new List <MockFile>()
            {
                timeFile
            });

            // Create pack info
            MockDirectory pack = new MockDirectory(
                enlistment.GitPackRoot,
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-1.pack"), "one"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-1.idx"), "1"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-2.pack"), "two"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-2.idx"), "2"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-3.pack"), "three"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, "pack-3.idx"), "3"),
                new MockFile(Path.Combine(enlistment.GitPackRoot, KeepName), string.Empty),
                new MockFile(Path.Combine(enlistment.GitPackRoot, StaleIdxName), "4"),
            });

            // Create git objects directory
            MockDirectory gitObjectsRoot = new MockDirectory(enlistment.GitObjectsRoot, new List <MockDirectory>()
            {
                info, pack
            }, null);

            // Add object directory to file System
            List <MockDirectory> directories = new List <MockDirectory>()
            {
                gitObjectsRoot
            };
            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, directories, null));

            // Create and return Context
            this.tracer  = new MockTracer();
            this.context = new GVFSContext(this.tracer, fileSystem, repository: null, enlistment: enlistment);

            this.gitProcess.SetExpectedCommandResult(
                this.ExpireCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));
            this.gitProcess.SetExpectedCommandResult(
                this.RepackCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));
        }
Ejemplo n.º 13
0
        private void TestSetup(DateTime lastRun)
        {
            string lastRunTime = EpochConverter.ToUnixEpochSeconds(lastRun).ToString();

            // Create GitProcess
            this.gitProcess = new MockGitProcess();
            this.gitProcess.SetExpectedCommandResult(
                PrunePackedCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));

            // Create enlistment using git process
            GVFSEnlistment enlistment = new MockGVFSEnlistment(this.gitProcess);

            // Create a last run time file
            MockFile timeFile = new MockFile(Path.Combine(enlistment.GitObjectsRoot, "info", LooseObjectsStep.LooseObjectsLastRunFileName), lastRunTime);

            // Create info directory to hold last run time file
            MockDirectory infoRoot = new MockDirectory(Path.Combine(enlistment.GitObjectsRoot, "info"), null, new List <MockFile>()
            {
                timeFile
            });

            // Create Hex Folder 1 with 1 File
            MockDirectory hex1 = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "AA"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "AA", "test"), string.Empty)
            });

            // Create Hex Folder 2 with 2 Files
            MockDirectory hex2 = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "F1"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "F1", "test1"), string.Empty),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "F1", "test2"), string.Empty)
            });

            // Create NonHex Folder with 4 Files
            MockDirectory nonhex = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "ZZ"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "test1"), string.Empty),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "test2"), string.Empty),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "test3"), string.Empty),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "test4"), string.Empty)
            });

            // Create git objects directory
            MockDirectory gitObjectsRoot = new MockDirectory(enlistment.GitObjectsRoot, new List <MockDirectory>()
            {
                infoRoot, hex1, hex2, nonhex
            }, null);

            // Add object directory to file System
            List <MockDirectory> directories = new List <MockDirectory>()
            {
                gitObjectsRoot
            };
            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, directories, null));

            // Create and return Context
            this.tracer  = new MockTracer();
            this.context = new GVFSContext(this.tracer, fileSystem, repository: null, enlistment: enlistment);
        }
Ejemplo n.º 14
0
 public void VerifyCreated()
 {
     MockDirectory.Verify(m => m.Create(), Times.Once());
 }
Ejemplo n.º 15
0
        private void TestSetup(DateTime lastRun)
        {
            string lastRunTime = EpochConverter.ToUnixEpochSeconds(lastRun).ToString();

            // Create GitProcess
            this.gitProcess = new MockGitProcess();
            this.gitProcess.SetExpectedCommandResult(
                PrunePackedCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));

            // Create enlistment using git process
            ScalarEnlistment enlistment = new MockScalarEnlistment(this.gitProcess);

            string packPrefix = Path.Combine(enlistment.GitPackRoot, "from-loose");

            this.packCommand = $"pack-objects {packPrefix} --non-empty --window=0 --depth=0 -q";

            this.gitProcess.SetExpectedCommandResult(
                this.packCommand,
                () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));

            // Create a last run time file
            MockFile timeFile = new MockFile(Path.Combine(enlistment.GitObjectsRoot, "info", LooseObjectsStep.LooseObjectsLastRunFileName), lastRunTime);

            // Create info directory to hold last run time file
            MockDirectory infoRoot = new MockDirectory(Path.Combine(enlistment.GitObjectsRoot, "info"), null, new List <MockFile>()
            {
                timeFile
            });

            // Create Hex Folder 1 with 1 File
            MockDirectory hex1 = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "AA"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "AA", "1156f4f2b850673090c285289ea8475d629fe1"), "one")
            });

            // Create Hex Folder 2 with 2 Files
            MockDirectory hex2 = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "F1"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "F1", "1156f4f2b850673090c285289ea8475d629fe2"), "two"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "F1", "1156f4f2b850673090c285289ea8475d629fe3"), "three")
            });

            // Create NonHex Folder with 4 Files
            MockDirectory nonhex = new MockDirectory(
                Path.Combine(enlistment.GitObjectsRoot, "ZZ"),
                null,
                new List <MockFile>()
            {
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe4"), "4"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe5"), "5"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe6"), "6"),
                new MockFile(Path.Combine(enlistment.GitObjectsRoot, "ZZ", "1156f4f2b850673090c285289ea8475d629fe7"), "7")
            });

            MockDirectory pack = new MockDirectory(
                enlistment.GitPackRoot,
                null,
                new List <MockFile>());

            // Create git objects directory
            MockDirectory gitObjectsRoot = new MockDirectory(enlistment.GitObjectsRoot, new List <MockDirectory>()
            {
                infoRoot, hex1, hex2, nonhex, pack
            }, null);

            // Add object directory to file System
            List <MockDirectory> directories = new List <MockDirectory>()
            {
                gitObjectsRoot
            };
            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, directories, null));

            // Create and return Context
            this.tracer  = new MockTracer();
            this.context = new ScalarContext(this.tracer, fileSystem, enlistment: enlistment);
        }
Ejemplo n.º 16
0
 public MockMountPoint()
 {
     MockRoot = new MockDirectory("/", "/", this, null);
 }
Ejemplo n.º 17
0
 public BlockedCreateDirectoryFileSystem(MockDirectory rootDirectory)
     : base(rootDirectory)
 {
     this.unblockCreateDirectory = new ManualResetEvent(initialState: false);
 }
Ejemplo n.º 18
0
 public FileSystemMockup(IMockFileDataAccessor data)
 {
     _file      = new MockFile(data);
     _path      = new MockPath(data);
     _directory = new MockDirectory(data, _file, data.Directory.GetCurrentDirectory());
 }
Ejemplo n.º 19
0
 public void VerifyDeleted()
 {
     MockDirectory.Verify(m => m.Delete(true), Times.Once());
 }