From bb6fa653620ef7ec87da565b3021fe995e08c070 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 15 Jan 2017 18:59:14 +0100 Subject: [PATCH] ImageSharp.Tests (.NET Core!) test profiling is now possible from R# context menu --- tests/ImageSharp.Sandbox46/README.md | 11 +++++----- tests/ImageSharp.Tests/TestFile.cs | 30 ++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/tests/ImageSharp.Sandbox46/README.md b/tests/ImageSharp.Sandbox46/README.md index b93cc0dda..b05afb853 100644 --- a/tests/ImageSharp.Sandbox46/README.md +++ b/tests/ImageSharp.Sandbox46/README.md @@ -1,7 +1,7 @@ ## Purpose This project aims to workaround certain .NET Core tooling issues in Visual Studio based developer workflow at the time of it's creation (January 2017): - .NET Core Performance profiling is not possible neither with Visual Studio nor with JetBrains profilers -- JetBrains Unit Test explorer does not work with .NET Core projects +- ~~JetBrains Unit Test explorer does not work with .NET Core projects~~ ## How does it work? - By referencing .NET 4.5 dll-s created by net45 target's of ImageSharp projects. NOTE: These are not project references! @@ -16,10 +16,9 @@ This project aims to workaround certain .NET Core tooling issues in Visual Studi - Use the [context menu in Test Explorer](https://adamprescott.net/2012/12/12/performance-profiling-for-unit-tests/) NOTE: -There was no *Profile test* option in my VS Professional. Maybe things were messed by VS2017 RC installation. [This post suggests](http://stackoverflow.com/questions/32034375/profiling-tests-in-visual-studio-community-2015) it's necessary to won Premium or Ultimate edition of Visual Studio to profile tests. +There was no *Profile test* option in my VS Professional. Maybe things were messed by VS2017 RC installation. [This post suggests](http://stackoverflow.com/questions/32034375/profiling-tests-in-visual-studio-community-2015) it's necessary to own Premium or Ultimate edition of Visual Studio to profile tests. #### 2. With JetBrains ReSharper Ultimate -- Use the [context menu](https://www.jetbrains.com/resharper/features/unit_testing.html) from your test class -![Context Menu](https://www.jetbrains.com/resharper/features/screenshots/100/unit_testing_profiling.png) -- Or Unit Test Exporer or Unit Test Sessions -- When working with test classes, make sure you open them from the `ImageSharp.Sandbox46` project! +- The `Sandbox46` project is no longer needed here. The classic `ImageSharp.Tests` project can be discovered by Unit Test Explorer. +- You can use [context menus](https://www.jetbrains.com/resharper/features/unit_testing.html) from your test class, or from unit Test Exporer/Unit Test Sessions windows. +![Context Menu](https://www.jetbrains.com/resharper/features/screenshots/100/unit_testing_profiling.png) \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index 144a19f4e..cfc88ad67 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/tests/ImageSharp.Tests/TestFile.cs @@ -5,9 +5,12 @@ namespace ImageSharp.Tests { + using System; using System.Collections.Concurrent; + using System.Collections.Generic; using System.IO; using System.Linq; + using System.Reflection; /// /// A test image file. @@ -130,14 +133,19 @@ namespace ImageSharp.Tests /// private static string GetFormatsDirectory() { - var directories = new[] { + List directories = new List< string > { "TestImages/Formats/", // Here for code coverage tests. "tests/ImageSharp.Tests/TestImages/Formats/", // from travis/build script "../../../ImageSharp.Tests/TestImages/Formats/", // from Sandbox46 "../../../../TestImages/Formats/" }; - directories= directories.Select(x => Path.GetFullPath(x)).ToArray(); + directories = directories.SelectMany(x => new[] + { + Path.GetFullPath(x) + }).ToList(); + + AddFormatsDirectoryFromTestAssebmlyPath(directories); var directory = directories.FirstOrDefault(x => Directory.Exists(x)); @@ -148,5 +156,23 @@ namespace ImageSharp.Tests throw new System.Exception($"Unable to find Formats directory at any of these locations [{string.Join(", ", directories)}]"); } + + /// + /// The path returned by Path.GetFullPath(x) can be relative to dotnet framework directory + /// in certain scenarios like dotTrace test profiling. + /// + /// The directories list + private static void AddFormatsDirectoryFromTestAssebmlyPath(List directories) + { + string assemblyLocation = typeof(TestFile).GetTypeInfo().Assembly.Location; + assemblyLocation = Path.GetDirectoryName(assemblyLocation); + + if (assemblyLocation != null) + { + string dirFromAssemblyLocation = Path.Combine(assemblyLocation, "../../../TestImages/Formats/"); + dirFromAssemblyLocation = Path.GetFullPath(dirFromAssemblyLocation); + directories.Add(dirFromAssemblyLocation); + } + } } }