public async Task ExecuteDirNotExistTest() { var targetPath = $"{TestContext.CurrentContext.TestDirectory}\\ololo"; var listener = new TcpListener(IPAddress.Any, 8888); listener.Start(); try { using (var client = new TcpClient("localhost", 8888)) { var acceptedClient = listener.AcceptTcpClient(); var command = new ListCommand(targetPath, acceptedClient); await command.Execute(); var reader = new StreamReader(client.GetStream()); var actual = await reader.ReadLineAsync(); Assert.AreEqual("-1", actual); } } finally { listener.Stop(); } }
public void TestToolsInstalled() { _mResolver.Setup(r => r.GetInstalled()).Returns(new string[] { "" }); ListCommand listCommand = new ListCommand(new[] { _mResolver.Object }, _mLogger.Object); Assert.True(listCommand.Execute()); }
public async Task WhenListPhysicalDrivesWithRigidDiskBlockThenListReadIsTriggered() { var path = Path.Combine("TestData", "rigid-disk-block.img"); var physicalDrives = new[] { new FakePhysicalDrive(path, "Type", "Model", await File.ReadAllBytesAsync(path)) }; var fakeCommandHelper = new FakeCommandHelper(new[] { path }); var cancellationTokenSource = new CancellationTokenSource(); var listCommand = new ListCommand(new NullLogger <ListCommand>(), fakeCommandHelper, physicalDrives); IEnumerable <MediaInfo> mediaInfos = null; listCommand.ListRead += (sender, args) => { mediaInfos = args?.MediaInfos; }; var result = await listCommand.Execute(cancellationTokenSource.Token); Assert.True(result.IsSuccess); var mediaInfosList = mediaInfos.ToList(); Assert.Single(mediaInfosList); var mediaInfo = mediaInfosList.First(); Assert.Equal(path, mediaInfo.Path); Assert.Equal(Media.MediaType.Raw, mediaInfo.Type); Assert.True(mediaInfo.IsPhysicalDrive); Assert.Equal("Model", mediaInfo.Model); Assert.Equal(131072, mediaInfo.DiskSize); Assert.NotNull(mediaInfo.RigidDiskBlock); }
public void Execute_ShouldReturn_Success_And_PrintDependencies_WhenLoadFromDirectorySucceeds() { var factory = Container.Resolve <IGitDependFileFactory>(); var console = Container.Resolve <IConsole>(); StringBuilder output = new StringBuilder(); console.Arrange(c => c.WriteLine(Arg.AnyString, Arg.IsAny <object[]>())) .DoInstead((string format, object[] args) => { output.AppendLine(string.Format(format, args)); }); string dir = Lib2Directory; ReturnCode loadCode = ReturnCode.Success; factory.Arrange(f => f.LoadFromDirectory(Arg.AnyString, out dir, out loadCode)) .Returns(Lib2Config); var options = new ListSubOptons(); var instance = new ListCommand(options); var code = instance.Execute(); const string EXPECTED = "- Lib2\r\n" + " - Lib1\r\n"; var actual = output.ToString(); Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code"); Assert.AreEqual(EXPECTED, actual, "Invalid Output"); }
public async Task WhenListPhysicalDrivesThenListReadIsTriggered() { var physicalDrives = new[] { new FakePhysicalDrive("Path", "Type", "Model", 8192) }; var fakeCommandHelper = new FakeCommandHelper(); var cancellationTokenSource = new CancellationTokenSource(); var listCommand = new ListCommand(new NullLogger <ListCommand>(), fakeCommandHelper, physicalDrives); IEnumerable <MediaInfo> mediaInfos = null; listCommand.ListRead += (sender, args) => { mediaInfos = args?.MediaInfos; }; var result = await listCommand.Execute(cancellationTokenSource.Token); Assert.True(result.IsSuccess); var mediaInfosList = mediaInfos.ToList(); Assert.Single(mediaInfosList); var mediaInfo = mediaInfosList.First(); Assert.Equal("Path", mediaInfo.Path); Assert.Equal(Media.MediaType.Raw, mediaInfo.Type); Assert.True(mediaInfo.IsPhysicalDrive); Assert.Equal("Model", mediaInfo.Model); Assert.Equal(8192, mediaInfo.DiskSize); Assert.Null(mediaInfo.RigidDiskBlock); }
public void when_list_command_is_executed_then_all_versions_are_fetched_from_database() { var listCommand = new ListCommand(MockSecureConsole.Object, _mockConnectionFactory.Object, _mockVersionRepositoryFactory.Object); listCommand.Execute(_requiredListCommandArguments); _mockVersionRepository.Verify(m => m.GetAllVersions(It.IsAny <string>()), Times.Once); }
public void when_list_command_is_executed_then_a_database_connection_is_established() { var listCommand = new ListCommand(MockSecureConsole.Object, _mockConnectionFactory.Object, _mockVersionRepositoryFactory.Object); listCommand.Execute(_requiredListCommandArguments); _mockConnectionFactory.Verify(m => m.Create(It.IsAny <DatabaseConnectionInfo>()), Times.Once); }
public void TestNoToolInstalled() { _mResolver.Setup(r => r.GetInstalled()).Returns(new string[] { }); ListCommand listCommand = new ListCommand(new[] { _mResolver.Object }, _mLogger.Object); Assert.True(listCommand.Execute()); _mLogger.Verify(l => l.LogInformation("No .NET Core tool installed")); }
public void AccountList_Execute_ReturnsSuccessMessage() { var command = new ListCommand(_console, LoggerMock.GetLogger <ListCommand>().Object, _accountService.Object); var resultMessage = command.Execute(); Assert.StartsWith("Found 1 user(s):", resultMessage); }
public void when_list_command_is_executed_then_a_database_connection_is_established() { var listCommand = new ListCommand(MockSecureConsole.Object, _mockConnectionFactory.Object, _mockVersionRepositoryFactory.Object); listCommand.Execute(_requiredListCommandArguments); _mockConnectionFactory.Verify(m => m.Create(It.IsAny<DatabaseConnectionInfo>()), Times.Once); }
public void when_list_command_is_executed_then_all_versions_are_fetched_from_database() { var listCommand = new ListCommand(MockSecureConsole.Object, _mockConnectionFactory.Object, _mockVersionRepositoryFactory.Object); listCommand.Execute(_requiredListCommandArguments); _mockVersionRepository.Verify(m => m.GetAllVersions(It.IsAny<string>()), Times.Once); }
public void SettingList_Execute_ReturnsSuccessMessage() { var console = new TestConsole(_output); var command = new ListCommand(console, LoggerMock.GetLogger <ListCommand>().Object, _applicationSettingService.Object); var resultMessage = command.Execute(); Assert.StartsWith("Application setting(s):", resultMessage); }
public void ServiceList_Execute_ReturnsSuccessMessage() { var console = new TestConsole(_output, "userPassword"); var command = new ListCommand(console, LoggerMock.GetLogger <ListCommand>().Object, _externalServiceService.Object); var resultMessage = command.Execute(); Assert.StartsWith("Found 1 external service(s):", resultMessage); }
public void ProviderList_Execute_ReturnsNoProvidersMessage() { _providerService.Setup(s => s.GetProviders(It.IsAny <string>())).ReturnsAsync(new List <TaskProviderDto>()); var command = new ListCommand(_providerService.Object, _console, LoggerMock.GetLogger <ListCommand>().Object); var message = command.Execute(); Assert.Equal("No registered task providers found.", message); }
public void QueueList_Execute_ReturnsSuccessMessage() { var command = new ListCommand(_console, LoggerMock.GetLogger <ListCommand>().Object, _projectService.Object, _jobQueueService.Object) { Project = "Project 1", }; var resultMessage = command.Execute(); Assert.StartsWith("Found 1 queue(s):", resultMessage); }
public void QueueList_Execute_ReturnsNotFoundMessage() { var command = new ListCommand(_console, LoggerMock.GetLogger <ListCommand>().Object, _projectService.Object, _jobQueueService.Object) { Project = "Project 2", }; var resultMessage = command.Execute(); Assert.Equal("Project Project 2 was not found.", resultMessage); }
public void ThrowArgumentExcpetion_WhenEmptyCollectionIsPassed() { //Arrange var sessionMock = new Mock <IUserSession>(); var serviceMock = new Mock <ICarService>(); var sut = new ListCommand(sessionMock.Object, serviceMock.Object); var args = new string[0]; //Act && Assert Assert.ThrowsException <ArgumentException>(() => sut.Execute(args)); }
public void ListCommand_CheckLogic_EmptyList() { var chatMembers = new List <ChatMember>(); var dbProviderMock = GetDbProvider(chatMembers); var listCommand = new ListCommand(dbProviderMock); var context = new CommandContext(null, null, null); var expectedResult = listCommand.Execute(context); Assert.AreEqual(expectedResult, "Список пуст"); }
public void PropertyList_Execute_ReturnsNotFoundMessage() { var command = new ListCommand(_console, LoggerMock.GetLogger <ListCommand>().Object, _projectService.Object, _projectModelService.Object) { Project = "Project 1", Model = "Tag" }; var resultMessage = command.Execute(); Assert.Equal("Failed to fetch properties. Make sure the project and model names are correct.", resultMessage); }
public void PropertyList_Execute_ReturnsSuccessMessage() { var command = new ListCommand(_console, LoggerMock.GetLogger <ListCommand>().Object, _projectService.Object, _projectModelService.Object) { Project = "Project 1", Model = "Product", }; var resultMessage = command.Execute(); Assert.StartsWith("Found 1 property:", resultMessage); }
public void TaskList_Execute_ReturnsNotFoundMessage() { var command = new ListCommand(_console, LoggerMock.GetLogger <ListCommand>().Object, _projectService.Object, _jobDefinitionService.Object, _providerService.Object) { Project = "Project 1", Job = "Default 2" }; var resultMessage = command.Execute(); Assert.Equal("Failed to fetch tasks. Make sure the project and job names are correct.", resultMessage); }
public void MemberList_Execute_ReturnsSuccessMessage() { var command = new ListCommand(_console, LoggerMock.GetLogger <ListCommand>().Object, _projectMemberService.Object, _projectService.Object) { Project = "Project 1" }; var resultMessage = command.Execute(); Assert.StartsWith("Found 1 project member(s):", resultMessage); _projectMemberService.Verify(p => p.GetProjectMembers(1, 0), Times.Once); }
//check if updates are available private static List <PackageElement> checkUpdate(List <PackageElement> confPackages) { bool single = false; ListCommand listCmd = new ListCommand(); List <PackageElement> newVersions = new List <PackageElement>(); foreach (PackageElement confelem in confPackages) { //write to cache TODO string packageVersion = confelem.Version.ToNormalizedString(); string[] pv = packageVersion.Split('.'); var repoResults = listCmd.Execute(confelem.Packageid); Console.WriteLine("Getting all versions of package " + confelem.Packageid); foreach (var rpackage in repoResults) { if (rpackage.IsReleaseVersion()) { string currRepoVersion = rpackage.Version.ToNormalizedString(); string[] repov = currRepoVersion.Split('.'); if (float.Parse(pv[0]) < float.Parse(repov[0])) //major version { //Console.WriteLine("updatemajor " + rpackage.Id + currRepoVersion); newVersions.Add(new PackageElement(rpackage.Id, NuGet.SemanticVersion.Parse(currRepoVersion), NuGet.SemanticVersion.Parse(packageVersion))); single = true; } else if (float.Parse(pv[0]) == float.Parse(repov[0])) { if (float.Parse(pv[1]) < float.Parse(repov[1])) { // Console.WriteLine("updateminor " + rpackage.Id + currRepoVersion); newVersions.Add(new PackageElement(rpackage.Id, NuGet.SemanticVersion.Parse(currRepoVersion), NuGet.SemanticVersion.Parse(packageVersion))); single = true; } else if (float.Parse(pv[1]) == float.Parse(repov[1])) { if (float.Parse(pv[2]) < float.Parse(repov[2])) { Console.WriteLine("updatepatch " + rpackage.Id + currRepoVersion); newVersions.Add(new PackageElement(rpackage.Id, NuGet.SemanticVersion.Parse(currRepoVersion), NuGet.SemanticVersion.Parse(packageVersion))); single = true; } } } } } } if (single) { return(newVersions); } return(null); }
public void ThrowArgumentExcpetion_WhenInvalidParametersArePassed() { //Arrange var sessionMock = new Mock <IUserSession>(); var serviceMock = new Mock <ICarService>(); var sut = new ListCommand(sessionMock.Object, serviceMock.Object); var args = new string[1] { "invalid" }; //Act && Assert Assert.ThrowsException <ArgumentException>(() => sut.Execute(args)); }
public void Test() { var input = new ListInput() { PointFlag = @"..{0}..{0}..{0}..".ToFormat(Path.DirectorySeparatorChar) }; var cmd = new ListCommand(); cmd.Execute(input); //REVIEW: how do I test the console out put? }
public void Execute_WithEmptyConfig_ShouldPrintConfigEmpty() { // Arrange ListCommand command = new ListCommand(false, "testpath"); testConfigHandler.Setup(m => m.LoadConfig("testpath")).Returns(testConfig.Object); // Act command.Execute(testConsole, testConfigHandler.Object, testFileSystem, testPathResolver); // Assert Assert.IsTrue(testConsole.GetHistory().Contains("empty", StringComparison.OrdinalIgnoreCase)); }
public void Test() { var input = new ListInput() { PointFlag = @"..\..\..\.." }; var cmd = new ListCommand(); cmd.Execute(input); //REVIEW: how do I test the console out put? }
public void TaskList_Execute_ReturnsSuccessMessage() { _providerService.Setup(x => x.GetProviderAdditionalConfigByProviderName(It.IsAny <string>())).ReturnsAsync(new List <ProviderAdditionalConfigDto>()); var command = new ListCommand(_console, LoggerMock.GetLogger <ListCommand>().Object, _projectService.Object, _jobDefinitionService.Object, _providerService.Object) { Project = "Project 1", Job = "Default" }; var resultMessage = command.Execute(); Assert.StartsWith("Found 1 task(s):", resultMessage); }
public void when_no_arguments_have_been_specified_then_the_list_command_help_text_is_displayed() { var stringWriter = new StringWriter(); typeof(ParserSettings).GetProperty("Consumed", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(Parser.Default.Settings, false); Parser.Default.Settings.HelpWriter = stringWriter; var listCommand = new ListCommand(MockSecureConsole.Object, _mockConnectionFactory.Object, _mockVersionRepositoryFactory.Object); listCommand.Execute(new string[] { }); Assert.That(stringWriter, Is.Not.Null.Or.Empty); }
public void ListCommand_CheckLogic_ListWithData() { var chatMembers = new List <ChatMember> { new ChatMember { ChatId = "1", Id = 1, Name = "User1 Name", Team = "Team1" }, new ChatMember { ChatId = "1", Id = 2, Name = "User2 Name", Team = "", }, new ChatMember { ChatId = "1", Id = 3, Name = "User3 Name", Team = null }, new ChatMember { ChatId = "1", Id = 4, Name = "User5 Name", Team = "Team1" }, new ChatMember { ChatId = "1", Id = 5, Name = "User4 Name", Team = "Team2" } }; var dbProviderMock = GetDbProvider(chatMembers); var listCommand = new ListCommand(dbProviderMock); var context = new CommandContext(null, null, null); var result = listCommand.Execute(context); var expectedResult = $"Список:{Environment.NewLine}User1 Name (Team1){Environment.NewLine}User2 Name{Environment.NewLine}User3 Name{Environment.NewLine}User5 Name (Team1){Environment.NewLine}User4 Name (Team2)"; Assert.AreEqual(expectedResult, result); }
public void ProviderList_Execute_ReturnsSuccessMessage() { _providerService.Setup(s => s.GetProviders(It.IsAny <string>())).ReturnsAsync(new List <TaskProviderDto> { new TaskProviderDto { Id = 1, Name = "AProvider01" } }); var command = new ListCommand(_providerService.Object, _console, LoggerMock.GetLogger <ListCommand>().Object); var message = command.Execute(); Assert.StartsWith("Found 1 task provider(s):", message); }
public void Execute_WithConfigLinks_ShouldPrintAllCases() { // Arrange ListCommand command = new ListCommand(false, "testpath"); testLinks.Add(new ConfigLink("source", "target", ConfigLink.LinkType.Default)); testLinks.Add(new ConfigLink("testing is fun", "not really", ConfigLink.LinkType.Hard)); testConfigHandler.Setup(m => m.LoadConfig("testpath")).Returns(testConfig.Object); // Act command.Execute(testConsole, testConfigHandler.Object, testFileSystem, testPathResolver); // Assert testLinks.ForEach(link => Assert.IsTrue(testConsole.GetHistory().Contains(link.ToString(), StringComparison.OrdinalIgnoreCase))); }
public void Execute_WithVariables_ShouldPrintAllCases() { // Arrange ListCommand command = new ListCommand(true, "testpath"); testVariables.Add(new Variable("var", "value")); testVariables.Add(new Variable("othervar", "othervalue")); testConfigHandler.Setup(m => m.LoadConfig("testpath")).Returns(testConfig.Object); // Act command.Execute(testConsole, testConfigHandler.Object, testFileSystem, testPathResolver); // Assert testVariables.ForEach(variable => Assert.IsTrue(testConsole.GetHistory().Contains(variable.ToString(), StringComparison.OrdinalIgnoreCase))); }
public void when_database_contains_versions_then_they_are_listed_to_the_screen() { _mockVersionRepository.Setup(m => m.GetAllVersions(It.IsAny<string>())) .Returns(new List<DatabaseVersion> { new DatabaseVersion(1, "some script"), new DatabaseVersion(2, "some other script") }); var listCommand = new ListCommand(MockSecureConsole.Object, _mockConnectionFactory.Object, _mockVersionRepositoryFactory.Object); using (var stringWriter = new StringWriter()) { Console.SetOut(stringWriter); listCommand.Execute(_requiredListCommandArguments); Assert.That(stringWriter.ToString().Contains(" 1\t\tsome script")); Assert.That(stringWriter.ToString().Contains(" 2\t\tsome other script")); } }