示例#1
0
        public void GivenASuccessfulShutdownItDoesNotThrow()
        {
            const int    ProcessId = 1234;
            const string PipeName  = "some-pipe-name";

            string pidDirectory = Path.GetFullPath("var/pids/build");
            string pidFilePath  = Path.Combine(pidDirectory, $"{RazorPidFile.FilePrefix}{ProcessId}");

            var fileSystemMock = new FileSystemMockBuilder()
                                 .AddFile(pidFilePath, "")
                                 .UseCurrentSystemTemporaryDirectory()
                                 .Build();

            fileSystemMock.File.Exists(pidFilePath).Should().BeTrue();

            var serverPath = Path.Combine(fileSystemMock.Directory.CreateTemporaryDirectory().DirectoryPath, "path/to/rzc.dll");

            var server = new RazorServer(
                pidFile: new RazorPidFile(
                    path: new FilePath(pidFilePath),
                    processId: ProcessId,
                    serverPath: new FilePath(serverPath),
                    pipeName: PipeName),
                commandFactory: CreateCommandFactoryMock(serverPath, PipeName).Object,
                fileSystem: fileSystemMock);

            server.Shutdown();

            fileSystemMock.File.Exists(pidFilePath).Should().BeFalse();
        }
示例#2
0
        public void GivenAFailedShutdownCommandItThrows()
        {
            const int    ProcessId    = 1234;
            const string ServerPath   = "path/to/rzc.dll";
            const string PipeName     = "some-pipe-name";
            const string ErrorMessage = "error!";

            string pidDirectory = Path.GetFullPath("var/pids/build");
            string pidFilePath  = Path.Combine(pidDirectory, $"{RazorPidFile.FilePrefix}{ProcessId}");

            var fileSystemMock = new FileSystemMockBuilder()
                                 .AddFile(pidFilePath, "")
                                 .Build();

            fileSystemMock.File.Exists(pidFilePath).Should().BeTrue();

            var server = new RazorServer(
                pidFile: new RazorPidFile(
                    path: new FilePath(pidFilePath),
                    processId: ProcessId,
                    serverPath: new FilePath(ServerPath),
                    pipeName: PipeName),
                commandFactory: CreateCommandFactoryMock(ServerPath, PipeName, exitCode: 1, stdErr: ErrorMessage).Object,
                fileSystem: fileSystemMock);

            Action a = () => server.Shutdown();

            a.ShouldThrow <BuildServerException>().WithMessage(
                string.Format(
                    LocalizableStrings.ShutdownCommandFailed,
                    ErrorMessage));

            fileSystemMock.File.Exists(pidFilePath).Should().BeTrue();
        }