瀏覽代碼

单元测试

懒得勤快 7 年之前
父節點
當前提交
d19305581a

+ 0 - 25
Masuit.Tools.UnitTest/HtmlHelperTest.cs

@@ -1,25 +0,0 @@
-using Masuit.Tools.Html;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Masuit.Tools.UnitTest
-{
-    [TestClass]
-    public class HtmlHelperTest
-    {
-        [TestMethod]
-        public void MatchRandomImgSrc_NormalHtml_ReturnAImgUrl()
-        {
-            string html = "<p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxefem7juyj30ld037q35\"/></p><p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxeffei83dj30l90nbgr8\"/></p><p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxeffz9u1kj30lc0n90y1\"/></p><p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxefgh6xxoj30lc09aq4q\"/></p>";
-            string src = html.MatchRandomImgSrc();
-            Assert.IsTrue(src.StartsWith("http"));
-        }
-
-        [TestMethod]
-        public void MatchRandomImgSrc_NoImgHtml_ReturnNull()
-        {
-            string html = "<p>如果你是通过某宝、或是其他论坛等渠道,通过任何付费的方式获取到本资源,请直接退款并在相应的平台举报,如果是论坛的,请将本页链接分享到你购买源的评论区,告诫他人谨防上当,或者直接将本页链接转发分享给有需要的人,感谢您的支持和监督。</p>";
-            string src = html.MatchRandomImgSrc();
-            Assert.IsTrue(string.IsNullOrEmpty(src));
-        }
-    }
-}

+ 25 - 0
Masuit.Tools.UnitTest/HtmlToolsTest.cs

@@ -0,0 +1,25 @@
+using Masuit.Tools.Html;
+using Xunit;
+
+namespace Masuit.Tools.UnitTest
+{
+    public class HtmlToolsTest
+    {
+        [Theory]
+        [InlineData("<p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxefem7juyj30ld037q35\"/></p><p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxeffei83dj30l90nbgr8\"/></p><p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxeffz9u1kj30lc0n90y1\"/></p><p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxefgh6xxoj30lc09aq4q\"/></p>")]
+        [InlineData("<p><img title=\"title\" src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxefem7juyj30ld037q35\"/></p><p><img title=\"title\" src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxeffei83dj30l90nbgr8\"/></p><p><img src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxeffz9u1kj30lc0n90y1\"/></p><p><img title=\"title\" src=\"https://ww1.sinaimg.cn/large/007iUjdily1fxefgh6xxoj30lc09aq4q\"/></p>")]
+        public void MatchRandomImgSrc_NormalHtml_ReturnAImgUrl(string html)
+        {
+            string src = html.MatchRandomImgSrc();
+            Assert.True(src.StartsWith("http"));
+        }
+
+        [Fact]
+        public void MatchRandomImgSrc_NoImgHtml_ReturnNull()
+        {
+            string html = "<p>如果你是通过某宝、或是其他论坛等渠道,通过任何付费的方式获取到本资源,请直接退款并在相应的平台举报,如果是论坛的,请将本页链接分享到你购买源的评论区,告诫他人谨防上当,或者直接将本页链接转发分享给有需要的人,感谢您的支持和监督。</p>";
+            string src = html.MatchRandomImgSrc();
+            Assert.True(string.IsNullOrEmpty(src));
+        }
+    }
+}

+ 20 - 1
Masuit.Tools.UnitTest/Masuit.Tools.UnitTest.csproj

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" />
   <Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
   <PropertyGroup>
@@ -48,10 +49,22 @@
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Net.Http" />
+    <Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
+      <HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
+    </Reference>
+    <Reference Include="xunit.assert, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
+      <HintPath>..\packages\xunit.assert.2.4.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
+    </Reference>
+    <Reference Include="xunit.core, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
+      <HintPath>..\packages\xunit.extensibility.core.2.4.1\lib\net452\xunit.core.dll</HintPath>
+    </Reference>
+    <Reference Include="xunit.execution.desktop, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
+      <HintPath>..\packages\xunit.extensibility.execution.2.4.1\lib\net452\xunit.execution.desktop.dll</HintPath>
+    </Reference>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="ExtensionMethodsTest.cs" />
-    <Compile Include="HtmlHelperTest.cs" />
+    <Compile Include="HtmlToolsTest.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="TemplateTest.cs" />
   </ItemGroup>
@@ -64,6 +77,9 @@
       <Name>Masuit.Tools</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
+  </ItemGroup>
   <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
@@ -72,6 +88,9 @@
     </PropertyGroup>
     <Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
     <Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
+    <Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.props'))" />
+    <Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.targets'))" />
   </Target>
   <Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
+  <Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" />
 </Project>

+ 7 - 0
Masuit.Tools.UnitTest/packages.config

@@ -2,4 +2,11 @@
 <packages>
   <package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net461" />
   <package id="MSTest.TestFramework" version="1.3.2" targetFramework="net461" />
+  <package id="xunit" version="2.4.1" targetFramework="net461" />
+  <package id="xunit.abstractions" version="2.0.3" targetFramework="net461" />
+  <package id="xunit.analyzers" version="0.10.0" targetFramework="net461" />
+  <package id="xunit.assert" version="2.4.1" targetFramework="net461" />
+  <package id="xunit.core" version="2.4.1" targetFramework="net461" />
+  <package id="xunit.extensibility.core" version="2.4.1" targetFramework="net461" />
+  <package id="xunit.extensibility.execution" version="2.4.1" targetFramework="net461" />
 </packages>