From 1eff271acf48e1705f3da4af0bbe6f423986ed29 Mon Sep 17 00:00:00 2001 From: whistyun Date: Sat, 5 Nov 2022 16:37:05 +0900 Subject: [PATCH 1/4] rRlease stream when markdown is drawwn. --- MdXaml.sln | 18 ++- MdXaml/ImageLoaderManager.cs | 33 ++--- MdXaml/MarkdownScrollViewer.cs | 4 +- ...ages2_generatesExpectedResult.approved.txt | 8 +- ...ages2_generatesExpectedResult.approved.txt | 8 +- ...ages2_generatesExpectedResult.approved.txt | 8 +- ...ages2_generatesExpectedResult.approved.txt | 8 +- ...ages2_generatesExpectedResult.approved.txt | 8 +- ...ages2_generatesExpectedResult.approved.txt | 8 +- tests/VisualTest/Assets/Markdown.txt | 7 ++ tests/VisualTest/Assets/image1.bmp | Bin 0 -> 6174 bytes tests/VisualTest/Assets/image2.png | Bin 0 -> 6174 bytes tests/VisualTest/Assets/image3.jpg | Bin 0 -> 1564 bytes tests/VisualTest/Assets/image4.svg | 61 ++++++++++ tests/VisualTest/Assets/image5.txt | 0 tests/VisualTest/Class1.cs | 114 ++++++++++++++++++ tests/VisualTest/Utils.cs | 24 ++++ tests/VisualTest/VisualTest.csproj | 29 +++++ tests/VisualTestApp/App.xaml | 9 ++ tests/VisualTestApp/App.xaml.cs | 17 +++ tests/VisualTestApp/AssemblyInfo.cs | 10 ++ tests/VisualTestApp/MainWIndowViewModel.cs | 35 ++++++ tests/VisualTestApp/MainWindow.xaml | 63 ++++++++++ tests/VisualTestApp/MainWindow.xaml.cs | 28 +++++ tests/VisualTestApp/VisualTestApp.csproj | 15 +++ 25 files changed, 473 insertions(+), 42 deletions(-) create mode 100644 tests/VisualTest/Assets/Markdown.txt create mode 100644 tests/VisualTest/Assets/image1.bmp create mode 100644 tests/VisualTest/Assets/image2.png create mode 100644 tests/VisualTest/Assets/image3.jpg create mode 100644 tests/VisualTest/Assets/image4.svg create mode 100644 tests/VisualTest/Assets/image5.txt create mode 100644 tests/VisualTest/Class1.cs create mode 100644 tests/VisualTest/Utils.cs create mode 100644 tests/VisualTest/VisualTest.csproj create mode 100644 tests/VisualTestApp/App.xaml create mode 100644 tests/VisualTestApp/App.xaml.cs create mode 100644 tests/VisualTestApp/AssemblyInfo.cs create mode 100644 tests/VisualTestApp/MainWIndowViewModel.cs create mode 100644 tests/VisualTestApp/MainWindow.xaml create mode 100644 tests/VisualTestApp/MainWindow.xaml.cs create mode 100644 tests/VisualTestApp/VisualTestApp.csproj diff --git a/MdXaml.sln b/MdXaml.sln index d4cfc30..8f815a5 100644 --- a/MdXaml.sln +++ b/MdXaml.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29519.181 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32922.545 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MdXaml", "MdXaml\MdXaml.csproj", "{3B285B6B-C6C9-4FF5-AD2B-04808862D81E}" EndProject @@ -40,6 +40,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MdXaml.Html.Test", "tests\M EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MdXaml.Plugins", "MdXaml.Plugins\MdXaml.Plugins.csproj", "{823DB5D5-17C0-4418-895C-A28DD7D04CE9}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualTest", "tests\VisualTest\VisualTest.csproj", "{F07D55AE-63CB-4098-9C85-8A6255A7ED54}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisualTestApp", "tests\VisualTestApp\VisualTestApp.csproj", "{9BF2BC76-8D51-4595-B9EE-6DAF296BEC58}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -102,6 +106,14 @@ Global {823DB5D5-17C0-4418-895C-A28DD7D04CE9}.Debug|Any CPU.Build.0 = Debug|Any CPU {823DB5D5-17C0-4418-895C-A28DD7D04CE9}.Release|Any CPU.ActiveCfg = Release|Any CPU {823DB5D5-17C0-4418-895C-A28DD7D04CE9}.Release|Any CPU.Build.0 = Release|Any CPU + {F07D55AE-63CB-4098-9C85-8A6255A7ED54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F07D55AE-63CB-4098-9C85-8A6255A7ED54}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F07D55AE-63CB-4098-9C85-8A6255A7ED54}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F07D55AE-63CB-4098-9C85-8A6255A7ED54}.Release|Any CPU.Build.0 = Release|Any CPU + {9BF2BC76-8D51-4595-B9EE-6DAF296BEC58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9BF2BC76-8D51-4595-B9EE-6DAF296BEC58}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9BF2BC76-8D51-4595-B9EE-6DAF296BEC58}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9BF2BC76-8D51-4595-B9EE-6DAF296BEC58}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -116,6 +128,8 @@ Global {C539C7B4-BBF2-4AC2-A732-0C47E125CCD2} = {435867FA-EE25-4708-9BBA-8509ABC7E389} {C45A1400-B4E9-4638-BF1F-4BB38CEC5E93} = {09BEAB2A-F47E-4D2B-AE81-8DC1BBB52638} {CEF2B49F-90AF-4B65-AA0C-A12AB1C0A18F} = {09BEAB2A-F47E-4D2B-AE81-8DC1BBB52638} + {F07D55AE-63CB-4098-9C85-8A6255A7ED54} = {09BEAB2A-F47E-4D2B-AE81-8DC1BBB52638} + {9BF2BC76-8D51-4595-B9EE-6DAF296BEC58} = {09BEAB2A-F47E-4D2B-AE81-8DC1BBB52638} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {23DF7019-3B25-4B82-8955-25F1DDD72D84} diff --git a/MdXaml/ImageLoaderManager.cs b/MdXaml/ImageLoaderManager.cs index 57bb92e..1737cc9 100644 --- a/MdXaml/ImageLoaderManager.cs +++ b/MdXaml/ImageLoaderManager.cs @@ -134,9 +134,13 @@ public async Task> LoadImageAsync(IEnumerable resourceU { var imgSource = new BitmapImage(); imgSource.BeginInit(); + // close the stream after the BitmapImage is created + imgSource.CacheOption = BitmapCacheOption.OnLoad; imgSource.StreamSource = stream; imgSource.EndInit(); + stream.Close(); + return imgSource; } catch { } @@ -156,6 +160,7 @@ public async Task> LoadImageAsync(IEnumerable resourceU catch { } } + stream.Close(); return null; } @@ -202,25 +207,25 @@ private static async Task> OpenStreamAsync(Uri resourceUrl) } return new Result("unsupport scheme"); - } - private static async Task CheckSupportSeek(Stream stream) - { - if (stream.CanSeek) - return stream; - return await AsMemoryStream(stream); - } + static async Task CheckSupportSeek(Stream stream) + { + if (stream.CanSeek) + return stream; - private static async Task AsMemoryStream(Stream stream) - { - var ms = new MemoryStream(); - await stream.CopyToAsync(ms); - stream.Close(); + return await AsMemoryStream(stream); + } - return ms; - } + static async Task AsMemoryStream(Stream stream) + { + var ms = new MemoryStream(); + await stream.CopyToAsync(ms); + stream.Close(); + return ms; + } + } public class Result where T : class { diff --git a/MdXaml/MarkdownScrollViewer.cs b/MdXaml/MarkdownScrollViewer.cs index c528bf1..b229597 100644 --- a/MdXaml/MarkdownScrollViewer.cs +++ b/MdXaml/MarkdownScrollViewer.cs @@ -349,7 +349,7 @@ bool TryOpen(Uri path) throw new ArgumentException($"unsupport schema {path.Scheme}"); } - var assetPathRoot = path.Scheme == "file" ? path.LocalPath : path.AbsoluteUri; + var assetPathRoot = path.Scheme == "file" ? Path.GetDirectoryName(path.LocalPath) : path.AbsoluteUri; Engine.AssetPathRoot = assetPathRoot; @@ -384,7 +384,7 @@ bool TryOpen(Uri path) } else { - var assetPath = Path.Combine(AssetPathRoot, source.LocalPath); + var assetPath = Path.Combine(AssetPathRoot, source.ToString()); TryOpen(new Uri(assetPath)); } } diff --git a/tests/MdXaml.Test/Out/core/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt b/tests/MdXaml.Test/Out/core/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt index bdfd19c..3a2f03c 100644 --- a/tests/MdXaml.Test/Out/core/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt +++ b/tests/MdXaml.Test/Out/core/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt @@ -1,13 +1,13 @@ - A remote . - Images side by side + A remote . + Images side by side - + - A resource image . A local image . + A resource image . A local image . diff --git a/tests/MdXaml.Test/Out/dotnet/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt b/tests/MdXaml.Test/Out/dotnet/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt index bdfd19c..3a2f03c 100644 --- a/tests/MdXaml.Test/Out/dotnet/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt +++ b/tests/MdXaml.Test/Out/dotnet/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt @@ -1,13 +1,13 @@ - A remote . - Images side by side + A remote . + Images side by side - + - A resource image . A local image . + A resource image . A local image . diff --git a/tests/MdXaml.Test/Out/framework/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt b/tests/MdXaml.Test/Out/framework/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt index 54e2427..a7f3f90 100644 --- a/tests/MdXaml.Test/Out/framework/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt +++ b/tests/MdXaml.Test/Out/framework/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt @@ -1,13 +1,13 @@ - A remote . - Images side by side + A remote . + Images side by side - + - A resource image . A local image . + A resource image . A local image . diff --git a/tests/MdXaml.Test/OutMF/core/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt b/tests/MdXaml.Test/OutMF/core/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt index bdfd19c..3a2f03c 100644 --- a/tests/MdXaml.Test/OutMF/core/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt +++ b/tests/MdXaml.Test/OutMF/core/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt @@ -1,13 +1,13 @@ - A remote . - Images side by side + A remote . + Images side by side - + - A resource image . A local image . + A resource image . A local image . diff --git a/tests/MdXaml.Test/OutMF/dotnet/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt b/tests/MdXaml.Test/OutMF/dotnet/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt index bdfd19c..3a2f03c 100644 --- a/tests/MdXaml.Test/OutMF/dotnet/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt +++ b/tests/MdXaml.Test/OutMF/dotnet/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt @@ -1,13 +1,13 @@ - A remote . - Images side by side + A remote . + Images side by side - + - A resource image . A local image . + A resource image . A local image . diff --git a/tests/MdXaml.Test/OutMF/framework/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt b/tests/MdXaml.Test/OutMF/framework/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt index 54e2427..a7f3f90 100644 --- a/tests/MdXaml.Test/OutMF/framework/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt +++ b/tests/MdXaml.Test/OutMF/framework/Tests.Transform_givenImages2_generatesExpectedResult.approved.txt @@ -1,13 +1,13 @@ - A remote . - Images side by side + A remote . + Images side by side - + - A resource image . A local image . + A resource image . A local image . diff --git a/tests/VisualTest/Assets/Markdown.txt b/tests/VisualTest/Assets/Markdown.txt new file mode 100644 index 0000000..4438271 --- /dev/null +++ b/tests/VisualTest/Assets/Markdown.txt @@ -0,0 +1,7 @@ +# Markdown Resource + +![image1.bmp](image1.bmp) +![image2.png](image2.png) +![image3.jpg](image3.jpg) +![image4.svg](image4.svg) +![image5.txt](image5.txt) \ No newline at end of file diff --git a/tests/VisualTest/Assets/image1.bmp b/tests/VisualTest/Assets/image1.bmp new file mode 100644 index 0000000000000000000000000000000000000000..36d8d40c140e684dd10eddf9a4932e4b6fbc2d74 GIT binary patch literal 6174 zcmeH~K@NgI3`Ox2x^nHttp{-L{jcCHurN?sGqk^C7KkOmblT4E<1;4ud|fZycs=Oz zM)!TXPhBaz&tqAA^!vEFePHxI!cksf6VFJ>(6MS|n>@0$LEj(m`Nt>7~B%$ z;E}A(0hcJ?Bn2{W#Au%-A;-?K(O)gK;iyW7lF6a%I+h>!_d>g{tQz=1V#%>MIz;J5 z`k@`rt2`g+hju`(@_eKp+5x@F^YM3ngkE{5Sz9@+tlx#WI^J1@prpeA4glNMARLae z4Vi)T7!VN0(B%DHb{lMn0Ea!vuDTE?M-if7YxCCf2*D(dw^HXw@_n?c$&l=z9NtjI f&L^e`#1;PY$#Net_M1fN@@rx;;`f;|F9_Kpio%x-pOTBLu%y9s1C_;G>2r#RLUGB%g>t@ Z4g{lQyw0g9!_GmKQJw!BONqMC;|2e5PksOZ literal 0 HcmV?d00001 diff --git a/tests/VisualTest/Assets/image3.jpg b/tests/VisualTest/Assets/image3.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8ad75bb11c19a205f4dbe3be6046a534962f9aa0 GIT binary patch literal 1564 zcmbV}c~Db#5XWEg5?&6jKm>u>a2BdEQAh#hP=i1aEh^;@IYbUQ3YjR#6-Yr2g;E6s zB`C@fuobZo4o%evA)ruA5h@4@gjfr-U=S)%h_5eg$IkSxw%_0G%+CCFcfOxlcm$pV zw0F6Cx&tT_3OIy303HKe0W=DwioXP6L6y`n7!V7oL69nOcp@H$Bj6y2pg|xI)e%8> zO)U*|O;xR0q8e9CA)$_gaH@{~CipHu!U5KRHHb0=&?FQ{Lc!et1prW3#I4HkUqYcl z3|0-XL?9v!ZQ6)^5JV$pu^0@}oq_xV7!p>;Wb+O+-F;z@DT{2ARa}iTqc?Z1**_pR zw>^9`8&A;FUu$4!@sXv~$LndI*x5U5+3LE}&E13Hxy$D>UqAnV1A*ZYkx@sYV`7gb zCLK>sNliPElbe@+@>D@d>DjXKbLT6#HMMoT`i3iCf78NmZENqiaZ}JG>K6C(-n-xT zXmIGq$HOB}Mx|4-=Rdvpd3t7c;nm{OZ?BgXZ{Di7PyqNR)_bylaFGx$G;#wBq~b!M zlaT~T7_7-=HJu&%pfHxMsZAD+OfRl(?!=qf?w7AQd~|@IXHJt^EU3`_Ap3V<+5d~| zJ=ot|qkuYyLXHQLfNg+s^}3d#bR}7lE($eB66W1emrK5Mp|TnBYrOi}DT-za-ONKU5Dk}1qQSMSdNb#UAxKvMGWQs#5 z!ht0iAO%47fmpG)^^7=O@4gwwMn9?e_`Q6qO?|0`6k?{{^fv4&K3po)7=eK!Gg~?5 z?-kL`>3VN$q49&fX^oF0ESki;MY7=*-)mzDV}Abo?M|F`MrKn~rD5_M3In3eAV-8c)<%zv_)=IoaEN9#Q1>ppj2E zkIK53V9H&qq~8gJf$X!Kt_^Y+2vFb`)~~!HDcI>!N`XK#S870AE#oe)WX{l>KYeIA zQn6S+5gdH7I!QTS$=sODn0vMsoF!P*e4$Dg)u!^yr|;G)ziQ>+XU28p!u;n$PAnyl zsF3x%Jv(YIdYO-qwmsA6>A2!XuBW=p9*j2b=njoZPSox0Opa#bkQJP#DID3{^&V>B zJC`9BTXw*scxvKHt?{6ky)j#%tht1ysFHxCcspB@juOU)#MFc)%bS97$4DQCBChQc zROn>MQ!IB0%5$4$xS4G=aegHuv4$B+LD1;LSYNJ1Ucd!%iM@Md#35Jo4vZm!t=Jpl zsI1^jCCOj*2(?{|Q#iXotgPiYUrk64f6b`c zP-(1n*{X>n-6pn%WT(3%>WZv_4vI=SKX9S_w9H%UzVs6D%`a0%{gpgE4CEX>nBo^#nXzk2yJr}S zX{1&~%5-ad8 zw)KXd%tsXQ3i~U#J4Zxu&0*P|*SBBRs)T{b^W(q`g^xT=Jicyl6}rN9Rxsma!9M#G ysSUAqn_`Arrny + +Created by potrace 1.12, written by Peter Selinger 2001-2015 + + + + + + \ No newline at end of file diff --git a/tests/VisualTest/Assets/image5.txt b/tests/VisualTest/Assets/image5.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/VisualTest/Class1.cs b/tests/VisualTest/Class1.cs new file mode 100644 index 0000000..b0d3992 --- /dev/null +++ b/tests/VisualTest/Class1.cs @@ -0,0 +1,114 @@ +using NUnit.Framework; +using System; +using System.Diagnostics; +using System.Drawing.Text; +using System.IO; +using System.Reflection; +using System.Threading; +using System.Windows.Automation; +using System.Windows.Threading; + +namespace VisualTest +{ + public class Class1 + { + private string _assemblyDirectory; + private string _projectDirectory; + private string _exeFilePath; + + private string _assetPath; + + private Process _process; + private IntPtr _hwnd; + + public Class1() + { + var assemblyLocation = Assembly.GetCallingAssembly().Location; + _assemblyDirectory = Path.GetDirectoryName(assemblyLocation); + _projectDirectory = Path.GetDirectoryName(Path.GetDirectoryName(_assemblyDirectory)); + + + var relPath = _assemblyDirectory.Substring(_projectDirectory.Length + 1); + + _assetPath = Path.Combine(_projectDirectory, relPath, "Assets"); + _exeFilePath = Path.Combine(_projectDirectory.Replace("VisualTest", "VisualTestApp"), relPath, "VisualTestApp.exe"); + } + + + [SetUp] + public void Setup() + { + _process = Process.Start(_exeFilePath); + + while (_hwnd == IntPtr.Zero) + { + Thread.Sleep(1000); + _hwnd = _process.MainWindowHandle; + } + } + + + [Test] + public void CheckFileRemove() + { + var mainWindow = AutomationElement.FromHandle(_hwnd); + + var assetPathValPtn = mainWindow.FindPatternById("AssetPathRootTextBox"); + assetPathValPtn.SetValue(_assetPath); + + var markdownValPtn = mainWindow.FindPatternById("MarkdownPathTextBlox"); + markdownValPtn.SetValue("Markdown.txt"); + + // wait for viewing markdown + var markdownView = mainWindow.FindPatternById("MarkdownScrollViewer"); + while (markdownView.DocumentRange.GetChildren().Length < 4) + { + Thread.Sleep(1000); + } + + Thread.Sleep(1000); + + foreach (var file in Directory.GetFiles(_assetPath)) + { + try + { + TryRemove(file, 1000); + } + catch (Exception e) + { + Assert.Fail($"remove failed: {Path.GetFileName(file)}: {e.Message}"); + } + } + } + + private void TryRemove(string path, long waitTime) + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + for (; ; ) + { + try + { + File.Delete(path); + return; + } + catch + { + if (stopwatch.ElapsedMilliseconds < waitTime) + { + Thread.Sleep(100); + } + else throw; + } + } + } + + + [TearDown] + public void Closing() + { + _process.Kill(); + } + } +} diff --git a/tests/VisualTest/Utils.cs b/tests/VisualTest/Utils.cs new file mode 100644 index 0000000..45b4441 --- /dev/null +++ b/tests/VisualTest/Utils.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; +using System.Windows.Automation; + +namespace VisualTest +{ + internal static class Utils + { + public static AutomationElement FindById(this AutomationElement root, string automationId) + => root.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, automationId)); + + public static T FindPatternById(this AutomationElement root, string automationId) + where T : BasePattern + { + var element = FindById(root, automationId); + var pattern = (AutomationPattern)typeof(T).GetField("Pattern").GetValue(null); + + return (T)element.GetCurrentPattern(pattern); + } + + } +} diff --git a/tests/VisualTest/VisualTest.csproj b/tests/VisualTest/VisualTest.csproj new file mode 100644 index 0000000..bbc9d05 --- /dev/null +++ b/tests/VisualTest/VisualTest.csproj @@ -0,0 +1,29 @@ + + + + netcoreapp3.0;net462;net5.0-windows + true + false + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + diff --git a/tests/VisualTestApp/App.xaml b/tests/VisualTestApp/App.xaml new file mode 100644 index 0000000..5290478 --- /dev/null +++ b/tests/VisualTestApp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/tests/VisualTestApp/App.xaml.cs b/tests/VisualTestApp/App.xaml.cs new file mode 100644 index 0000000..383b0a3 --- /dev/null +++ b/tests/VisualTestApp/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace VisualTestApp +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/tests/VisualTestApp/AssemblyInfo.cs b/tests/VisualTestApp/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/tests/VisualTestApp/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/tests/VisualTestApp/MainWIndowViewModel.cs b/tests/VisualTestApp/MainWIndowViewModel.cs new file mode 100644 index 0000000..1561f49 --- /dev/null +++ b/tests/VisualTestApp/MainWIndowViewModel.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; + +namespace VisualTestApp +{ + internal class MainWIndowViewModel : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + + private string _assetPathRoot; + public string AssetPathRoot + { + get => _assetPathRoot; + set + { + _assetPathRoot = value; + var e = new PropertyChangedEventArgs(nameof(AssetPathRoot)); + PropertyChanged?.Invoke(this, e); + } + } + + private string _markdownPath; + public string MarkdownPath { + get => _markdownPath; + set + { + _markdownPath = value; + var e = new PropertyChangedEventArgs(nameof(MarkdownPath)); + PropertyChanged?.Invoke(this, e); + } + } + } +} diff --git a/tests/VisualTestApp/MainWindow.xaml b/tests/VisualTestApp/MainWindow.xaml new file mode 100644 index 0000000..feb5637 --- /dev/null +++ b/tests/VisualTestApp/MainWindow.xaml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/VisualTestApp/MainWindow.xaml.cs b/tests/VisualTestApp/MainWindow.xaml.cs new file mode 100644 index 0000000..4ebd4e7 --- /dev/null +++ b/tests/VisualTestApp/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace VisualTestApp +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/tests/VisualTestApp/VisualTestApp.csproj b/tests/VisualTestApp/VisualTestApp.csproj new file mode 100644 index 0000000..c0d0807 --- /dev/null +++ b/tests/VisualTestApp/VisualTestApp.csproj @@ -0,0 +1,15 @@ + + + + WinExe + netcoreapp3.0;net462;net5.0-windows + enable + 9 + true + + + + + + + From 04a2abe127ae658cb336461c193e4f514a07f29f Mon Sep 17 00:00:00 2001 From: whistyun Date: Sat, 5 Nov 2022 17:53:08 +0900 Subject: [PATCH 2/4] Disable an uitest on GitHub Action. --- .github/workflows/build.yml | 2 ++ Directory.Build.props | 4 ++++ MdXaml.Html/MdXaml.Html.csproj | 2 +- MdXaml.Plugins/MdXaml.Plugins.csproj | 2 +- MdXaml.Svg/MdXaml.Svg.csproj | 2 +- MdXaml/MdXaml.csproj | 2 +- MdXaml/MdXamlMigfree.csproj | 2 +- tests/VisualTest/Class1.cs | 17 +++++++++++++++-- tests/VisualTest/VisualTest.csproj | 3 +++ 9 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6504da6..9367294 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,3 +42,5 @@ jobs: run: dotnet build --no-restore - name: Test run: dotnet test --no-build --verbosity normal + env: + RUNON_GITHUB: yes diff --git a/Directory.Build.props b/Directory.Build.props index faa0ff0..7e68cc9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,4 +9,8 @@ $(ArtifactsDir)bin\$(MSBuildProjectName)\ $(ArtifactsDir)nuget\$(Configuration)\ + + + 1.16.2 + \ No newline at end of file diff --git a/MdXaml.Html/MdXaml.Html.csproj b/MdXaml.Html/MdXaml.Html.csproj index 8fe17ef..80c0dc6 100644 --- a/MdXaml.Html/MdXaml.Html.csproj +++ b/MdXaml.Html/MdXaml.Html.csproj @@ -2,7 +2,7 @@ netcoreapp3.0;net45;net5.0-windows MdXaml.Html - 1.16.1 + $(PackageVersion) whistyun Markdown XAML processor diff --git a/MdXaml.Plugins/MdXaml.Plugins.csproj b/MdXaml.Plugins/MdXaml.Plugins.csproj index 45b8818..7f71b07 100644 --- a/MdXaml.Plugins/MdXaml.Plugins.csproj +++ b/MdXaml.Plugins/MdXaml.Plugins.csproj @@ -3,7 +3,7 @@ netcoreapp3.0;net45;net5.0-windows MdXaml.Plugins - 1.16.1 + $(PackageVersion) whistyun Markdown XAML processor diff --git a/MdXaml.Svg/MdXaml.Svg.csproj b/MdXaml.Svg/MdXaml.Svg.csproj index 7338017..a837930 100644 --- a/MdXaml.Svg/MdXaml.Svg.csproj +++ b/MdXaml.Svg/MdXaml.Svg.csproj @@ -3,7 +3,7 @@ netcoreapp3.0;net45;net5.0-windows MdXaml.Svg - 1.16.1 + $(PackageVersion) whistyun Markdown XAML processor diff --git a/MdXaml/MdXaml.csproj b/MdXaml/MdXaml.csproj index faeb9b7..478f237 100644 --- a/MdXaml/MdXaml.csproj +++ b/MdXaml/MdXaml.csproj @@ -4,7 +4,7 @@ netcoreapp3.0;net45;net5.0-windows true MdXaml - 1.16.1 + $(PackageVersion) Bevan Arps(original); whistyun Markdown XAML processor diff --git a/MdXaml/MdXamlMigfree.csproj b/MdXaml/MdXamlMigfree.csproj index 07587f3..878cbed 100644 --- a/MdXaml/MdXamlMigfree.csproj +++ b/MdXaml/MdXamlMigfree.csproj @@ -4,7 +4,7 @@ netcoreapp3.0;net45;net5.0-windows true MdXaml_migfree - 1.16.1 + $(PackageVersion) Bevan Arps(original); whistyun Markdown XAML processor diff --git a/tests/VisualTest/Class1.cs b/tests/VisualTest/Class1.cs index b0d3992..3b8a011 100644 --- a/tests/VisualTest/Class1.cs +++ b/tests/VisualTest/Class1.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +#if !OnGitHubAction +using NUnit.Framework; using System; using System.Diagnostics; using System.Drawing.Text; @@ -34,16 +35,21 @@ public Class1() _exeFilePath = Path.Combine(_projectDirectory.Replace("VisualTest", "VisualTestApp"), relPath, "VisualTestApp.exe"); } - [SetUp] public void Setup() { _process = Process.Start(_exeFilePath); + var stopwatch = new Stopwatch(); + stopwatch.Start(); + while (_hwnd == IntPtr.Zero) { Thread.Sleep(1000); _hwnd = _process.MainWindowHandle; + + if (stopwatch.ElapsedMilliseconds > 5000) + throw new InvalidOperationException("Application startup timeout"); } } @@ -60,10 +66,16 @@ public void CheckFileRemove() markdownValPtn.SetValue("Markdown.txt"); // wait for viewing markdown + var stopwatch = new Stopwatch(); + stopwatch.Start(); + var markdownView = mainWindow.FindPatternById("MarkdownScrollViewer"); while (markdownView.DocumentRange.GetChildren().Length < 4) { Thread.Sleep(1000); + + if (stopwatch.ElapsedMilliseconds > 5000) + throw new InvalidOperationException("Markdown drawing timeout"); } Thread.Sleep(1000); @@ -112,3 +124,4 @@ public void Closing() } } } +#endif diff --git a/tests/VisualTest/VisualTest.csproj b/tests/VisualTest/VisualTest.csproj index bbc9d05..52d120d 100644 --- a/tests/VisualTest/VisualTest.csproj +++ b/tests/VisualTest/VisualTest.csproj @@ -25,5 +25,8 @@ + + OnGitHubAction + From 3526d2a396e5fea17bc7c2311ed88be3569d29f6 Mon Sep 17 00:00:00 2001 From: whistyun Date: Sat, 5 Nov 2022 18:43:38 +0900 Subject: [PATCH 3/4] enable uitest and remove core3 uitest. --- .github/workflows/build.yml | 2 -- tests/VisualTest/Class1.cs | 6 ++---- tests/VisualTest/VisualTest.csproj | 6 +----- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9367294..6504da6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,5 +42,3 @@ jobs: run: dotnet build --no-restore - name: Test run: dotnet test --no-build --verbosity normal - env: - RUNON_GITHUB: yes diff --git a/tests/VisualTest/Class1.cs b/tests/VisualTest/Class1.cs index 3b8a011..0642846 100644 --- a/tests/VisualTest/Class1.cs +++ b/tests/VisualTest/Class1.cs @@ -1,5 +1,4 @@ -#if !OnGitHubAction -using NUnit.Framework; +using NUnit.Framework; using System; using System.Diagnostics; using System.Drawing.Text; @@ -123,5 +122,4 @@ public void Closing() _process.Kill(); } } -} -#endif +} \ No newline at end of file diff --git a/tests/VisualTest/VisualTest.csproj b/tests/VisualTest/VisualTest.csproj index 52d120d..8fd9075 100644 --- a/tests/VisualTest/VisualTest.csproj +++ b/tests/VisualTest/VisualTest.csproj @@ -1,7 +1,7 @@  - netcoreapp3.0;net462;net5.0-windows + net462;net5.0-windows true false @@ -25,8 +25,4 @@ - - OnGitHubAction - - From fc7799be1632edf5f266f530b721f10ff04e4456 Mon Sep 17 00:00:00 2001 From: whistyun Date: Sat, 5 Nov 2022 19:49:15 +0900 Subject: [PATCH 4/4] retry --- .github/workflows/build.yml | 2 ++ tests/VisualTest/Class1.cs | 6 ++++-- tests/VisualTest/VisualTest.csproj | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6504da6..a44dfbd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,3 +42,5 @@ jobs: run: dotnet build --no-restore - name: Test run: dotnet test --no-build --verbosity normal + env: + RUNON_GITHUB: y diff --git a/tests/VisualTest/Class1.cs b/tests/VisualTest/Class1.cs index 0642846..59dd721 100644 --- a/tests/VisualTest/Class1.cs +++ b/tests/VisualTest/Class1.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +#if !OnGitHubAction +using NUnit.Framework; using System; using System.Diagnostics; using System.Drawing.Text; @@ -122,4 +123,5 @@ public void Closing() _process.Kill(); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/tests/VisualTest/VisualTest.csproj b/tests/VisualTest/VisualTest.csproj index 8fd9075..52d120d 100644 --- a/tests/VisualTest/VisualTest.csproj +++ b/tests/VisualTest/VisualTest.csproj @@ -1,7 +1,7 @@  - net462;net5.0-windows + netcoreapp3.0;net462;net5.0-windows true false @@ -25,4 +25,8 @@ + + OnGitHubAction + +