Index: Core/Common/src/Core.Common.Utils/Core.Common.Utils.csproj =================================================================== diff -u -r10b304d4b5cb2283801cdb16204baf2a42ab5967 -rf42e31958888a2a09de2686d2805cb48595ba6e0 --- Core/Common/src/Core.Common.Utils/Core.Common.Utils.csproj (.../Core.Common.Utils.csproj) (revision 10b304d4b5cb2283801cdb16204baf2a42ab5967) +++ Core/Common/src/Core.Common.Utils/Core.Common.Utils.csproj (.../Core.Common.Utils.csproj) (revision f42e31958888a2a09de2686d2805cb48595ba6e0) @@ -123,7 +123,6 @@ - @@ -136,7 +135,6 @@ - Fisheye: Tag f42e31958888a2a09de2686d2805cb48595ba6e0 refers to a dead (removed) revision in file `Core/Common/src/Core.Common.Utils/IO/FileUtils.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f42e31958888a2a09de2686d2805cb48595ba6e0 refers to a dead (removed) revision in file `Core/Common/src/Core.Common.Utils/IO/FileWatcher.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/test/Core.Common.TestUtil/TestHelper.cs =================================================================== diff -u -rd6e6eadf4a2521df75b6d371bacbb181a43058a3 -rf42e31958888a2a09de2686d2805cb48595ba6e0 --- Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision d6e6eadf4a2521df75b6d371bacbb181a43058a3) +++ Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision f42e31958888a2a09de2686d2805cb48595ba6e0) @@ -8,11 +8,13 @@ using System.Linq; using System.Reflection; using System.Windows.Forms; -using Core.Common.Utils.IO; + using log4net.Appender; using log4net.Config; using log4net.Core; + using Newtonsoft.Json; + using NUnit.Framework; namespace Core.Common.TestUtil @@ -69,7 +71,7 @@ /// public static string GetTestDataPath(TestDataPath testDataPath, string path) { - return Path.Combine(Path.Combine(TestDataDirectory, testDataPath.Path),"test-data", path); + return Path.Combine(Path.Combine(TestDataDirectory, testDataPath.Path), "test-data", path); } public static string GetTestProjectDirectory() @@ -159,8 +161,8 @@ stopwatch.Stop(); actualMillisecond = Math.Abs(actualMillisecond - default(double)) > 1e-5 - ? Math.Min(stopwatch.ElapsedMilliseconds, actualMillisecond) - : stopwatch.ElapsedMilliseconds; + ? Math.Min(stopwatch.ElapsedMilliseconds, actualMillisecond) + : stopwatch.ElapsedMilliseconds; stopwatch.Reset(); @@ -182,14 +184,14 @@ float machineHddPerformanceRank = GetMachineHddPerformanceRank(); var reportDirectory = GetSolutionRoot() + Path.DirectorySeparatorChar + "target/"; - FileUtils.CreateDirectoryIfNotExists(reportDirectory); + CreateDirectoryIfNotExists(reportDirectory); var path = reportDirectory + "performance-times.html"; - WriteTimesToLogFile(maxMilliseconds, (int) actualMillisecond, machinePerformanceRank, + WriteTimesToLogFile(maxMilliseconds, (int)actualMillisecond, machinePerformanceRank, machineHddPerformanceRank, rankHddAccess, testName, false, path); path = reportDirectory + "performance-times-charts.html"; - WriteTimesToLogFile(maxMilliseconds, (int) actualMillisecond, machinePerformanceRank, + WriteTimesToLogFile(maxMilliseconds, (int)actualMillisecond, machinePerformanceRank, machineHddPerformanceRank, rankHddAccess, testName, true, path); float rank = machineHddPerformanceRank; @@ -202,10 +204,10 @@ var userMessage = String.IsNullOrEmpty(message) ? "" : message + ". "; if (rank != 1.0f) { - Assert.IsTrue(rank*actualMillisecond < maxMilliseconds, userMessage + "Maximum of {0} milliseconds exceeded. Actual was {1}, machine performance weighted actual was {2}", - maxMilliseconds, actualMillisecond, actualMillisecond*rank); + Assert.IsTrue(rank * actualMillisecond < maxMilliseconds, userMessage + "Maximum of {0} milliseconds exceeded. Actual was {1}, machine performance weighted actual was {2}", + maxMilliseconds, actualMillisecond, actualMillisecond * rank); Console.WriteLine(userMessage + String.Format("Test took {1} milliseconds (machine performance weighted {2}). Maximum was {0}", - maxMilliseconds, actualMillisecond, actualMillisecond*rank)); + maxMilliseconds, actualMillisecond, actualMillisecond * rank)); } else { @@ -247,7 +249,7 @@ AssertExpectedMessagesInRenderedMessages(messages, renderedMessages); if (expectedLogMessageCount != null) { - Assert.AreEqual((int) expectedLogMessageCount, renderedMessages.Count()); + Assert.AreEqual((int)expectedLogMessageCount, renderedMessages.Count()); } } @@ -290,7 +292,7 @@ return; } Assert.IsNotNull(actualImage); - + Assert.AreEqual(expectedImage.Size, actualImage.Size); IEnumerable expectedImageBytes = GetImageAsByteArray(expectedImage); IEnumerable actualImageBytes = GetImageAsByteArray(actualImage); @@ -323,6 +325,31 @@ AssertImagesAreEqual(icon, item.Image); } + /// + /// Create dir if not exists. + /// + /// File path to a directory. + /// When: + /// The directory specified by is read-only + /// + /// When: The caller does not have the required permission. + /// + /// is a zero-length string, contains only white space, or contains one or more invalid characters as defined by . -or- + /// is prefixed with, or contains only a colon character (:). + /// is null. + /// + /// The specified path, file name, or both exceed the system-defined maximum length. + /// For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters. + /// The specified path is invalid (for example, it is on an unmapped drive). + /// contains a colon character (:) that is not part of a drive label ("C:\"). + private static void CreateDirectoryIfNotExists(string path) + { + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + } + private static string GetCurrentTestClassMethodName() { var stackTrace = new StackTrace(false); @@ -405,7 +432,7 @@ string contents; - float rank = machineRank*(useHddAccessRank ? machineHddRank : 1.0f); + float rank = machineRank * (useHddAccessRank ? machineHddRank : 1.0f); var chartContent = includeCharts ? String.Format("", testName) : ""; @@ -414,19 +441,19 @@ { contents = String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3:G5}{4:G5}{5:G5}", - DateTime.Now, testName, chartContent, maxMilliseconds, actualMilliseconds, actualMilliseconds*rank); - fraction = (maxMilliseconds - actualMilliseconds*rank)/maxMilliseconds; + DateTime.Now, testName, chartContent, maxMilliseconds, actualMilliseconds, actualMilliseconds * rank); + fraction = (maxMilliseconds - actualMilliseconds * rank) / maxMilliseconds; } else { contents = String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3:G5}{4:G5}", DateTime.Now, testName, chartContent, maxMilliseconds, actualMilliseconds); - fraction = (maxMilliseconds - actualMilliseconds)/maxMilliseconds; + fraction = (maxMilliseconds - actualMilliseconds) / maxMilliseconds; } string color = ColorTranslator.ToHtml(GetPerformanceColor(fraction)); - contents += String.Format(CultureInfo.InvariantCulture, "{1:G5}%", color, (100 - fraction*100)); + contents += String.Format(CultureInfo.InvariantCulture, "{1:G5}%", color, (100 - fraction * 100)); contents += "\n"; File.AppendAllText(path, contents); @@ -443,7 +470,7 @@ // generate JSON files locally string testHistoryDirectoryPath = GetSolutionRoot() + "/target/performace-test-reports"; - FileUtils.CreateDirectoryIfNotExists(testHistoryDirectoryPath); + CreateDirectoryIfNotExists(testHistoryDirectoryPath); string testHistoryFilePath = testHistoryDirectoryPath + Path.DirectorySeparatorChar + testName + ".json"; @@ -490,7 +517,7 @@ TestName = testName, Actual = actualMilliseconds, ActualWeighted = - (int) (actualMilliseconds*machineRank*(useHddAccessRank ? machineHddRank : 1.0)), + (int)(actualMilliseconds * machineRank * (useHddAccessRank ? machineHddRank : 1.0)), Max = maxMilliseconds, MachineHddRank = machineHddRank, MachineRank = machineRank, @@ -560,9 +587,9 @@ } // 25% is the best result GREEN, less or greater than goes to yellow - var localValue = fraction >= 0.25 ? Math.Min(1, (fraction - 0.25)/0.75) : Math.Max(0, (0.25 - fraction)/0.25); + var localValue = fraction >= 0.25 ? Math.Min(1, (fraction - 0.25) / 0.75) : Math.Max(0, (0.25 - fraction) / 0.25); - return colors[(int) (localValue*100.0)]; + return colors[(int)(localValue * 100.0)]; } /// @@ -610,6 +637,18 @@ return renderedMessages; } + private static IEnumerable GetImageAsByteArray(Image expectedImage) + { + using (var stream = new MemoryStream()) + { + expectedImage.Save(stream, expectedImage.RawFormat); + var length = stream.Length; + var imageBytes = new byte[length]; + stream.Read(imageBytes, 0, (int)length); + return imageBytes; + } + } + #region Nested type: TestRunInfo internal class TestRunInfo @@ -626,17 +665,5 @@ } #endregion - - private static IEnumerable GetImageAsByteArray(Image expectedImage) - { - using (var stream = new MemoryStream()) - { - expectedImage.Save(stream, expectedImage.RawFormat); - var length = stream.Length; - var imageBytes = new byte[length]; - stream.Read(imageBytes, 0, (int)length); - return imageBytes; - } - } } } \ No newline at end of file Index: Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj =================================================================== diff -u -r10b304d4b5cb2283801cdb16204baf2a42ab5967 -rf42e31958888a2a09de2686d2805cb48595ba6e0 --- Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision 10b304d4b5cb2283801cdb16204baf2a42ab5967) +++ Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision f42e31958888a2a09de2686d2805cb48595ba6e0) @@ -91,8 +91,6 @@ - - Fisheye: Tag f42e31958888a2a09de2686d2805cb48595ba6e0 refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Utils.Test/IO/FileUtilsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f42e31958888a2a09de2686d2805cb48595ba6e0 refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Utils.Test/IO/FileWatcherTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/test/Core.Common.Utils.Test/TestHelperTests.cs =================================================================== diff -u -rd6e6eadf4a2521df75b6d371bacbb181a43058a3 -rf42e31958888a2a09de2686d2805cb48595ba6e0 --- Core/Common/test/Core.Common.Utils.Test/TestHelperTests.cs (.../TestHelperTests.cs) (revision d6e6eadf4a2521df75b6d371bacbb181a43058a3) +++ Core/Common/test/Core.Common.Utils.Test/TestHelperTests.cs (.../TestHelperTests.cs) (revision f42e31958888a2a09de2686d2805cb48595ba6e0) @@ -1,10 +1,10 @@ using System.Drawing; using System.Globalization; using System.IO; +using System.Linq; using System.Reflection; using System.Windows.Forms; using Core.Common.TestUtil; -using Core.Common.Utils.IO; using Core.Common.Utils.Test.Properties; using log4net; using NUnit.Framework; @@ -92,7 +92,7 @@ // dump all colors to html file for visual test const string path = "GetPerformanceColors.html"; - FileUtils.DeleteIfExists(path); + DeleteIfExists(path); var contents = ""; for (var i = -0.05; i <= 1.1; i += 0.05) { @@ -108,6 +108,36 @@ File.AppendAllText(path, contents); } + private static void DeleteIfExists(string path) + { + if (!File.Exists(path) & !Directory.Exists(path)) + { + return; + } + + var attributes = File.GetAttributes(path); + + // if file is readonly - make it non-readonly + if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) + { + File.SetAttributes(path, attributes ^ FileAttributes.ReadOnly); + } + + // now delete everything + if (File.Exists(path)) + { + File.Delete(path); + } + else if (Directory.Exists(path)) + { + foreach (var path2 in Directory.GetDirectories(path).Union(Directory.GetFiles(path))) + { + DeleteIfExists(path2); + } + Directory.Delete(path); + } + } + [Test] public void TestAssertLogMessagesCount() {