コード例 #1
0
        public async Task GivenANonZeroExitCodeShutdownFails()
        {
            const string FakeRazorAssemblyPath = "/path/to/razor.dll";
            const string ErrorMessage          = "failed!";

            var resolverMock = new Mock <IRazorAssemblyResolver>(MockBehavior.Strict);

            resolverMock.Setup(r => r.EnumerateRazorToolAssemblies()).Returns(new FilePath[] { new FilePath(FakeRazorAssemblyPath) });

            var commandMock = new Mock <ICommand>(MockBehavior.Strict);

            commandMock.Setup(c => c.CaptureStdOut()).Returns(commandMock.Object);
            commandMock.Setup(c => c.CaptureStdErr()).Returns(commandMock.Object);
            commandMock.Setup(c => c.Execute()).Returns(new CommandResult(null, 1, "", ErrorMessage));

            var commandFactoryMock = new Mock <ICommandFactory>(MockBehavior.Strict);

            commandFactoryMock
            .Setup(
                f => f.Create(
                    "exec",
                    new string[] { FakeRazorAssemblyPath, "shutdown" },
                    It.IsAny <NuGetFramework>(),
                    Constants.DefaultConfiguration))
            .Returns(commandMock.Object);

            var manager = new RazorServerManager(resolverMock.Object, commandFactoryMock.Object);

            var result = await manager.ShutdownServerAsync();

            result.Kind.Should().Be(ResultKind.Failure);
            result.Message.Should().Be(ErrorMessage);
            result.Exception.Should().BeNull();
        }
コード例 #2
0
        public async Task GivenNoRazorAssemblyShutdownIsSkipped()
        {
            var resolverMock = new Mock <IRazorAssemblyResolver>(MockBehavior.Strict);

            resolverMock.Setup(r => r.EnumerateRazorToolAssemblies()).Returns(new FilePath[] {});

            var commandFactoryMock = new Mock <ICommandFactory>(MockBehavior.Strict);

            var manager = new RazorServerManager(resolverMock.Object, commandFactoryMock.Object);

            var result = await manager.ShutdownServerAsync();

            result.Kind.Should().Be(ResultKind.Skipped);
            result.Message.Should().Be(LocalizableStrings.NoRazorProjectFound);
            result.Exception.Should().BeNull();
        }
コード例 #3
0
        public async Task GivenAnInvalidProjectFileShutdownFails()
        {
            var exception = new InvalidProjectFileException("invalid project!");

            var resolverMock = new Mock <IRazorAssemblyResolver>(MockBehavior.Strict);

            resolverMock.Setup(r => r.EnumerateRazorToolAssemblies()).Throws(exception);

            var commandFactoryMock = new Mock <ICommandFactory>(MockBehavior.Strict);

            var manager = new RazorServerManager(resolverMock.Object, commandFactoryMock.Object);

            var result = await manager.ShutdownServerAsync();

            result.Kind.Should().Be(ResultKind.Failure);
            result.Message.Should().Be(exception.Message);
            result.Exception.Should().Be(exception);
        }