public void RuntimeControllerReturnsNodeVersions() { // Arrange var nodeDir = new Mock<DirectoryInfoBase>(); nodeDir.Setup(d => d.Exists).Returns(true); nodeDir.Setup(d => d.GetDirectories()).Returns(new[] { CreateDirectory("0.8.19", CreateFile("npm.txt", "1.2.8")), CreateDirectory("0.10.5", CreateFile("npm.txt", "1.3.11")), CreateDirectory("0.10.18"), CreateDirectory("node_modules"), CreateDirectory("docs") }); var directoryInfo = new Mock<IDirectoryInfoFactory>(); directoryInfo.Setup(d => d.FromDirectoryName(_nodeDir)).Returns(nodeDir.Object); var fileSystem = new Mock<IFileSystem>(); fileSystem.Setup(f => f.DirectoryInfo).Returns(directoryInfo.Object); FileSystemHelpers.Instance = fileSystem.Object; var controller = new RuntimeController(Mock.Of<ITracer>()); // Act var nodeVersions = controller.GetRuntimeVersions().NodeVersions.ToList(); // Assert Assert.Equal(new[] { "0.8.19", "0.10.5", "0.10.18" }, nodeVersions.Select(v => v["version"])); Assert.Equal(new[] { "1.2.8", "1.3.11", null }, nodeVersions.Select(v => v["npm"])); }
public void RuntimeControllerReturnsEmptyListIfDirectoryDoesNotExist() { // Arrange var nodeDir = new Mock<DirectoryInfoBase>(); nodeDir.Setup(d => d.Exists).Returns(false); var directory = new Mock<IDirectoryInfoFactory>(); directory.Setup(d => d.FromDirectoryName(_nodeDir)).Returns(nodeDir.Object); var fileSystem = new Mock<IFileSystem>(); fileSystem.Setup(f => f.DirectoryInfo).Returns(directory.Object); FileSystemHelpers.Instance = fileSystem.Object; var controller = new RuntimeController(Mock.Of<ITracer>()); // Act var runtimeInfo = controller.GetRuntimeVersions(); // Assert Assert.Empty(runtimeInfo.NodeVersions); }