public async Task GitCommandBase_ExecuteAsync_CallsExecuteInternalAsyncWithCorrectArgs() { var mockContext = new Mock <ICommandContext>(); var mockStreams = new Mock <IStandardStreams>(); var mockProvider = new Mock <IHostProvider>(); var mockHostRegistry = new Mock <IHostProviderRegistry>(); mockHostRegistry.Setup(x => x.GetProviderAsync(It.IsAny <InputArguments>())) .ReturnsAsync(mockProvider.Object) .Verifiable(); mockProvider.Setup(x => x.IsSupported(It.IsAny <InputArguments>())) .Returns(true); string standardIn = "protocol=test\nhost=example.com\npath=a/b/c\n\n"; TextReader standardInReader = new StringReader(standardIn); mockStreams.Setup(x => x.In).Returns(standardInReader); mockContext.Setup(x => x.Streams).Returns(mockStreams.Object); mockContext.Setup(x => x.Trace).Returns(Mock.Of <ITrace>()); mockContext.Setup(x => x.Settings).Returns(Mock.Of <ISettings>()); GitCommandBase testCommand = new TestCommand(mockContext.Object, mockHostRegistry.Object) { VerifyExecuteInternalAsync = (input, provider) => { Assert.Same(mockProvider.Object, provider); Assert.Equal("test", input.Protocol); Assert.Equal("example.com", input.Host); Assert.Equal("a/b/c", input.Path); } }; await testCommand.ExecuteAsync(); }
public async Task GitCommandBase_ExecuteAsync_ConfiguresSettingsRemoteUri() { var mockContext = new Mock <ICommandContext>(); var mockStreams = new Mock <IStandardStreams>(); var mockProvider = new Mock <IHostProvider>(); var mockSettings = new Mock <ISettings>(); var mockHostRegistry = new Mock <IHostProviderRegistry>(); mockHostRegistry.Setup(x => x.GetProviderAsync(It.IsAny <InputArguments>())) .ReturnsAsync(mockProvider.Object); string standardIn = "protocol=test\nhost=example.com\npath=a/b/c\n\n"; TextReader standardInReader = new StringReader(standardIn); var remoteUri = new Uri("test://example.com/a/b/c"); mockSettings.SetupProperty(x => x.RemoteUri); mockStreams.Setup(x => x.In).Returns(standardInReader); mockContext.Setup(x => x.Streams).Returns(mockStreams.Object); mockContext.Setup(x => x.Trace).Returns(Mock.Of <ITrace>()); mockContext.Setup(x => x.Settings).Returns(mockSettings.Object); GitCommandBase testCommand = new TestCommand(mockContext.Object, mockHostRegistry.Object); await testCommand.ExecuteAsync(); Assert.Equal(remoteUri, mockSettings.Object.RemoteUri); }
public async Task DesktopApp_WithKestrel_WorksWhenPublished(string project, string url, string runtime, string libuvName, bool forceRunnable) { var runnable = forceRunnable || string.IsNullOrEmpty(runtime) || (DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier().Contains(runtime)); var testInstance = GetTestInstance() .WithLockFiles(); // Prevent path too long failure on CI machines var projectPath = Path.Combine(testInstance.TestRoot, project); var publishCommand = new PublishCommand(projectPath, runtime: runtime, output: Path.Combine(projectPath, "out")); var result = await publishCommand.ExecuteAsync(); result.Should().Pass(); // Test the output var outputDir = publishCommand.GetOutputDirectory(portable: false); outputDir.Should().HaveFile(libuvName); outputDir.Should().HaveFile(publishCommand.GetOutputExecutable()); Task exec = null; if (runnable) { var outputExePath = Path.Combine(outputDir.FullName, publishCommand.GetOutputExecutable()); var command = new TestCommand(outputExePath); try { exec = command.ExecuteAsync(url); NetworkHelper.IsServerUp(url).Should().BeTrue($"Unable to connect to kestrel server - {project} @ {url}"); NetworkHelper.TestGetRequest(url, url); } finally { command.KillTree(); } if (exec != null) { await exec; } } }
public async Task RunAsync_Test() { // Arrange var command = new TestCommand(); var expectedExitCode = await command.ExecuteAsync(); var commandOptionParser = new CommandOptionParser(); var typeProvider = new TypeProvider(typeof(TestCommand)); var commandOptionConverter = new CommandOptionConverter(); var commandResolver = new CommandResolver(typeProvider, commandOptionConverter); var application = new CliApplication(commandOptionParser, commandResolver); // Act var exitCodeValue = await application.RunAsync(); // Assert Assert.That(exitCodeValue, Is.EqualTo(expectedExitCode.Value), "Exit code"); }
public void ItRunsKestrelStandaloneAfterPublish() { TestInstance instance = TestAssetsManager.CreateTestInstance(KestrelSampleBase) .WithLockFiles(); var url = NetworkHelper.GetLocalhostUrlWithFreePort(); var args = $"{url} {Guid.NewGuid().ToString()}"; var output = Publish(Path.Combine(instance.TestRoot, KestrelStandalone), false); var command = new TestCommand(output); try { command.ExecuteAsync($"{args}"); NetworkHelper.IsServerUp(url).Should().BeTrue($"Unable to connect to kestrel server - {KestrelStandalone} @ {url}"); NetworkHelper.TestGetRequest(url, args); } finally { command.KillTree(); } }
// ignoring since this never ends ... useful for testing https://github.com/Netflix//issues/236 // [Fact] //public void testSuccessClosesCircuitWhenBusy() // { // Plugins.getInstance().registerCommandExecutionHook(new MyCommandExecutionHook()); // try { // performLoad(200, 0, 40); // performLoad(250, 100, 40); // performLoad(600, 0, 40); // } finally { // .reset(); // } // } async Task performLoad(IJellyfishContext ctx, int totalNumCalls, int errPerc, int waitMillis) { Random rnd = new Random(); for (int i = 0; i < totalNumCalls; i++) { //System.out.println(i); try { var err = rnd.NextDouble() * 100 < errPerc; TestCommand cmd = new TestCommand(ctx, err); await cmd.ExecuteAsync(); } catch (Exception) { //System.err.println(e.getMessage()); } Thread.Sleep(waitMillis); } }
public void TestThatBaseCommandImplementationReturnsUsageError() { var command = new TestCommand(); command.ExecuteAsync(CancellationToken.None).Result.Should().Be(CommandResult.UsageError); }