public void SuccessfulDotNetRunnerExecution_ReturnsDependencyGraph() { var mockFileSystem = new MockFileSystem(new Dictionary <string, MockFileData>()); // Arrange var dotNetRunner = new Mock <IDotNetRunner>(); dotNetRunner.Setup(runner => runner.Run(It.IsAny <string>(), It.IsAny <string[]>())) .Returns(new RunStatus(string.Empty, string.Empty, 0)) .Callback((string directory, string[] arguments) => { // Grab the temp filename that was passed... string tempFileName = arguments[3].Replace("/p:RestoreGraphOutputPath=", string.Empty).Trim('"'); // ... and stuff it with our dummy dependency graph mockFileSystem.AddFileFromEmbeddedResource(tempFileName, GetType().Assembly, "DotNetOutdated.Tests.TestData.test.dg"); }); var graphService = new DependencyGraphService(dotNetRunner.Object, mockFileSystem); // Act var dependencyGraph = graphService.GenerateDependencyGraph(Path); // Assert Assert.NotNull(dependencyGraph); }
public void EmptySolution_ReturnsEmptyDependencyGraph() { var mockFileSystem = new MockFileSystem(new Dictionary <string, MockFileData>()); // Arrange var dotNetRunner = new Mock <IDotNetRunner>(); dotNetRunner.Setup(runner => runner.Run(It.IsAny <string>(), It.Is <string[]>(a => a[0] == "msbuild" && a[2] == "/t:Restore,GenerateRestoreGraphFile"))) .Returns(new RunStatus(string.Empty, string.Empty, 0)) .Callback((string directory, string[] arguments) => { // Grab the temp filename that was passed... string tempFileName = arguments[3].Replace("/p:RestoreGraphOutputPath=", string.Empty).Trim('"'); // ... and stuff it with our dummy dependency graph mockFileSystem.AddFileFromEmbeddedResource(tempFileName, GetType().Assembly, "DotNetOutdated.Tests.TestData.empty.dg"); });; var graphService = new DependencyGraphService(dotNetRunner.Object, mockFileSystem); // Act var dependencyGraph = graphService.GenerateDependencyGraph(_solutionPath); // Assert Assert.NotNull(dependencyGraph); Assert.Equal(0, dependencyGraph.Projects.Count); dotNetRunner.Verify(runner => runner.Run(_path, It.Is <string[]>(a => a[0] == "msbuild" && a[1] == '\"' + _solutionPath + '\"' && a[2] == "/t:Restore,GenerateRestoreGraphFile"))); }
public void MockFileSystem_AddFileFromEmbeddedResource_ShouldAddTheFile() { var fileSystem = new MockFileSystem(); fileSystem.AddFileFromEmbeddedResource(XFS.Path(@"C:\TestFile.txt"), Assembly.GetExecutingAssembly(), "System.IO.Abstractions.TestingHelpers.Tests.TestFiles.TestFile.txt"); var result = fileSystem.GetFile(XFS.Path(@"C:\TestFile.txt")); Assert.AreEqual(new UTF8Encoding().GetBytes("This is a test file."), result.Contents); }
public void SolutionPath_ReturnsDependencyGraphForAllProjects() { var mockFileSystem = new MockFileSystem(new Dictionary <string, MockFileData>()); // Arrange var dotNetRunner = new Mock <IDotNetRunner>(); string solutionProjects = string.Join(Environment.NewLine, "Project(s)", "-----------", _project1Path, _project2Path); dotNetRunner.Setup(runner => runner.Run(It.IsAny <string>(), It.Is <string[]>(a => a[0] == "sln"))) .Returns(new RunStatus(solutionProjects, string.Empty, 0)); dotNetRunner.Setup(runner => runner.Run(It.IsAny <string>(), It.Is <string[]>(a => a[0] == "msbuild"))) .Returns(new RunStatus(string.Empty, string.Empty, 0)) .Callback((string directory, string[] arguments) => { // Grab the temp filename that was passed... string tempFileName = arguments[3].Replace("/p:RestoreGraphOutputPath=", string.Empty).Trim('"'); // ... and stuff it with our dummy dependency graph string dependencyGraphFile = arguments[1] == '\"' + _project1Path + '\"' ? "test.dg" : "empty.dg"; mockFileSystem.AddFileFromEmbeddedResource(tempFileName, GetType().Assembly, "DotNetOutdated.Tests.TestData." + dependencyGraphFile); }); mockFileSystem.AddFileFromEmbeddedResource(_project1Path, GetType().Assembly, "DotNetOutdated.Tests.TestData.MicrosoftSdk.xml"); mockFileSystem.AddFileFromEmbeddedResource(_project2Path, GetType().Assembly, "DotNetOutdated.Tests.TestData.MicrosoftSdk.xml"); var graphService = new DependencyGraphService(dotNetRunner.Object, mockFileSystem); // Act var dependencyGraph = graphService.GenerateDependencyGraph(_solutionPath); // Assert Assert.NotNull(dependencyGraph); Assert.Equal(4, dependencyGraph.Projects.Count); dotNetRunner.Verify(runner => runner.Run(_path, It.Is <string[]>(a => a[0] == "sln" && a[2] == "list" && a[1] == '\"' + _solutionPath + '\"'))); dotNetRunner.Verify(runner => runner.Run(XFS.Path(@"c:\path\proj1"), It.Is <string[]>(a => a[0] == "msbuild" && a[1] == '\"' + _project1Path + '\"'))); dotNetRunner.Verify(runner => runner.Run(XFS.Path(@"c:\path\proj2"), It.Is <string[]>(a => a[0] == "msbuild" && a[1] == '\"' + _project2Path + '\"'))); }
public void CanLoadImage() { Logger.Debug("CanLoadImage"); using (var autoSub = new AutoSubstitute()) { var mockFileSystem = new MockFileSystem(); autoSub.Provide <IFileSystem>(mockFileSystem); var resourceAssembly = Assembly.GetAssembly(typeof(ImageLoadingServiceTests)); var filePath = Path.Combine(Faker.System.DirectoryPathWindows(), Faker.System.FileName("jpg")); mockFileSystem.AddFileFromEmbeddedResource(filePath, resourceAssembly, "SonOfPicasso.UI.Tests.Resources.DSC04085.JPG"); var autoResetEvent = new AutoResetEvent(false); IBitmap bitmap = null; var testSchedulerProvider = new TestSchedulerProvider(); autoSub.Provide <ISchedulerProvider>(testSchedulerProvider); var imageLoadingService = autoSub.Resolve <ImageLoadingService>(); imageLoadingService.LoadImageFromPath(filePath).Subscribe(b => { bitmap = b; autoResetEvent.Set(); }); testSchedulerProvider.TaskPool.AdvanceBy(1); autoResetEvent.WaitOne(); bitmap.Should().NotBeNull(); bitmap.Height.Should().BeApproximately(1000.6f, 0.01f); bitmap.Width.Should().BeApproximately(1334.12f, 0.01f); } }
public void AddResourceFile(string path, string resourceName) { MockFileSystem.AddFileFromEmbeddedResource(path, Assembly.GetExecutingAssembly(), $"PhotoFolder.Application.IntegrationTests.Resources.{resourceName}"); }
private void AFileThatExists(string templatePbit) { _fileSystem.AddFileFromEmbeddedResource("Template.pbit", Assembly.GetExecutingAssembly(), "PowerBi.Tests.Files.Template.pbit"); }