forked from MVCAppDesignAndDevelop/MVC5Book
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ASP.NET MVC 5 網站開發美學 - 第十四章 自動測試完整攻略範例
- Loading branch information
Showing
155 changed files
with
55,539 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
Ch14-AutoTesting/14-1 first unit test/CalculatorSample/CalculatorSample.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2013 | ||
VisualStudioVersion = 12.0.21005.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CalculatorSample", "CalculatorSample\CalculatorSample.csproj", "{E60B0A96-4D19-4CB6-8CB2-A1BB05BF92E8}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CalculatorSampleTests", "CalculatorSampleTests\CalculatorSampleTests.csproj", "{3EB16709-B6FB-4326-A8D0-3CB2CD2E48BD}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{E60B0A96-4D19-4CB6-8CB2-A1BB05BF92E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E60B0A96-4D19-4CB6-8CB2-A1BB05BF92E8}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E60B0A96-4D19-4CB6-8CB2-A1BB05BF92E8}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E60B0A96-4D19-4CB6-8CB2-A1BB05BF92E8}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{3EB16709-B6FB-4326-A8D0-3CB2CD2E48BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{3EB16709-B6FB-4326-A8D0-3CB2CD2E48BD}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{3EB16709-B6FB-4326-A8D0-3CB2CD2E48BD}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{3EB16709-B6FB-4326-A8D0-3CB2CD2E48BD}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
16 changes: 16 additions & 0 deletions
16
Ch14-AutoTesting/14-1 first unit test/CalculatorSample/CalculatorSample/Calculator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
namespace CalculatorSample | ||
{ | ||
public class Calculator | ||
{ | ||
public int Add(int firstNumber, int secondNumber) | ||
{ | ||
if (firstNumber == 0) | ||
{ | ||
throw new ArgumentOutOfRangeException("firstNumber"); | ||
} | ||
|
||
return firstNumber + secondNumber; | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...utoTesting/14-1 first unit test/CalculatorSample/CalculatorSample/CalculatorSample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{E60B0A96-4D19-4CB6-8CB2-A1BB05BF92E8}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>CalculatorSample</RootNamespace> | ||
<AssemblyName>CalculatorSample</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Calculator.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
36 changes: 36 additions & 0 deletions
36
...Testing/14-1 first unit test/CalculatorSample/CalculatorSample/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// 組件的一般資訊是由下列的屬性集控制。 | ||
// 變更這些屬性的值即可修改組件的相關 | ||
// 資訊。 | ||
[assembly: AssemblyTitle("CalculatorSample")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Microsoft")] | ||
[assembly: AssemblyProduct("CalculatorSample")] | ||
[assembly: AssemblyCopyright("Copyright © Microsoft 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// 將 ComVisible 設定為 false 會使得這個組件中的類型 | ||
// 對 COM 元件而言為不可見。如果您需要從 COM 存取這個組件中 | ||
// 的類型,請在該類型上將 ComVisible 屬性設定為 true。 | ||
[assembly: ComVisible(false)] | ||
|
||
// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID | ||
[assembly: Guid("40ca132a-9d6e-4b04-bfb7-f44561a61a6b")] | ||
|
||
// 組件的版本資訊是由下列四項值構成: | ||
// | ||
// 主要版本 | ||
// 次要版本 | ||
// 組建編號 | ||
// 修訂編號 | ||
// | ||
// 您可以指定所有的值,也可以依照以下的方式,使用 '*' 將組建和修訂編號 | ||
// 指定為預設值: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
90 changes: 90 additions & 0 deletions
90
.../14-1 first unit test/CalculatorSample/CalculatorSampleTests/CalculatorSampleTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{3EB16709-B6FB-4326-A8D0-3CB2CD2E48BD}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>CalculatorSampleTests</RootNamespace> | ||
<AssemblyName>CalculatorSampleTests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> | ||
<IsCodedUITest>False</IsCodedUITest> | ||
<TestProjectType>UnitTest</TestProjectType> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
</ItemGroup> | ||
<Choose> | ||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'"> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | ||
</ItemGroup> | ||
</When> | ||
<Otherwise> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" /> | ||
</ItemGroup> | ||
</Otherwise> | ||
</Choose> | ||
<ItemGroup> | ||
<Compile Include="CalculatorTests.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\CalculatorSample\CalculatorSample.csproj"> | ||
<Project>{E60B0A96-4D19-4CB6-8CB2-A1BB05BF92E8}</Project> | ||
<Name>CalculatorSample</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Choose> | ||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<Private>False</Private> | ||
</Reference> | ||
</ItemGroup> | ||
</When> | ||
</Choose> | ||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
31 changes: 31 additions & 0 deletions
31
...utoTesting/14-1 first unit test/CalculatorSample/CalculatorSampleTests/CalculatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using CalculatorSample; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
namespace CalculatorSample.Tests | ||
{ | ||
[TestClass()] | ||
public class CalculatorTests | ||
{ | ||
[TestMethod()] | ||
public void AddTest_first為1_second為2_result應為3() | ||
{ | ||
//arrange | ||
var target = new Calculator(); | ||
|
||
var first = 1; | ||
var second = 2; | ||
|
||
var expected =3; | ||
|
||
//act | ||
var actual = target.Add(first, second); | ||
|
||
//assert | ||
Assert.AreEqual(expected, actual); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ng/14-1 first unit test/CalculatorSample/CalculatorSampleTests/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// 組件的一般資訊是由下列的屬性集控制。 | ||
// 變更這些屬性的值即可修改組件的相關 | ||
// 資訊。 | ||
[assembly: AssemblyTitle("CalculatorSampleTests")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Microsoft")] | ||
[assembly: AssemblyProduct("CalculatorSampleTests")] | ||
[assembly: AssemblyCopyright("Copyright © Microsoft 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// 將 ComVisible 設定為 false 會使得這個組件中的類型 | ||
// 對 COM 元件而言為不可見。如果您需要從 COM 存取此組件中 | ||
// 的類型,請在該類型上將 ComVisible 屬性設定為 true。 | ||
[assembly: ComVisible(false)] | ||
|
||
// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID | ||
[assembly: Guid("361e5355-f6f8-4959-a925-8497cb5a5709")] | ||
|
||
// 組件的版本資訊是由下列四項值構成: | ||
// | ||
// 主要版本 | ||
// 次要版本 | ||
// 組建編號 | ||
// 修訂編號 | ||
// | ||
// 您可以指定所有的值,也可以依照以下的方式,使用 '*' 將組建和修訂編號 | ||
// 指定為預設值: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
6 changes: 6 additions & 0 deletions
6
Ch14-AutoTesting/14-2 Stub and Mock Sample/StubAndMockSample/.nuget/NuGet.Config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<solution> | ||
<add key="disableSourceControlIntegration" value="true" /> | ||
</solution> | ||
</configuration> |
Oops, something went wrong.