coffeycathal_cp 17年前
コミット
8f6aaf811a

+ 0
- 78
CustomPropertyTestApp/Program.cs ファイルの表示

@@ -1,78 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Novacode;
namespace CustomPropertyTestApp
{
// This class represents a user
class User
{
public string forname, username, freeGift, HomeAddress;
public DateTime joined;
public bool RecieveFurtherMail;
public User()
{ }
}
class Program
{
static void Main(string[] args)
{
// A list which contains three new users
List<User> newUsers = new List<User>
{
new User
{
forname = "John", username = "John87",
freeGift = "toaster", joined = DateTime.Now,
HomeAddress = "21 Hillview, Naas, Co. Kildare",
RecieveFurtherMail = true
},
new User
{
forname = "James", username = "KingJames",
freeGift = "kitchen knife", joined = DateTime.Now,
HomeAddress = "37 Mill Lane, Maynooth, Co. Meath",
RecieveFurtherMail = false
},
new User
{
forname = "Mary", username = "McNamara1",
freeGift = "microwave", joined = DateTime.Now,
HomeAddress = "110 Cherry Orchard Drive, Navan, Co. Roscommon", RecieveFurtherMail= true
}
};
// Foreach of the three new user create a welcome document based on template.docx
foreach (User newUser in newUsers)
{
// Copy template.docx so that we can customize it for this user
string filename = string.Format(@"{0}.docx", newUser.username);
File.Copy(@"Template.docx", filename, true);
/*
* Load the document to be manipulated and set the custom properties to this
* users specific data
*/
DocX doc = DocX.Load(filename);
doc.SetCustomProperty("Forname", CustomPropertyType.Text, newUser.forname);
doc.SetCustomProperty("Username", CustomPropertyType.Text, newUser.username);
doc.SetCustomProperty("FreeGift", CustomPropertyType.Text, newUser.freeGift);
doc.SetCustomProperty("HomeAddress", CustomPropertyType.Text, newUser.HomeAddress);
doc.SetCustomProperty("PleaseWaitNDays", CustomPropertyType.NumberInteger, 4);
doc.SetCustomProperty("GiftArrivalDate", CustomPropertyType.Date, newUser.joined.AddDays(4).ToUniversalTime());
doc.SetCustomProperty("RecieveFurtherMail", CustomPropertyType.YesOrNo, newUser.RecieveFurtherMail);
// File will be saved to \CustomPropertyTestApp\bin\Debug
doc.Save();
}
}
}
}

+ 0
- 36
CustomPropertyTestApp/Properties/AssemblyInfo.cs ファイルの表示

@@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CustomPropertyTestApp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft IT")]
[assembly: AssemblyProduct("CustomPropertyTestApp")]
[assembly: AssemblyCopyright("Copyright © Microsoft IT 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("54e1d528-31a1-4718-a659-472cbaf1a551")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

+ 7
- 20
DocX.sln ファイルの表示

@@ -4,34 +4,21 @@ Microsoft Visual Studio Solution File, Format Version 10.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocX", "DocX\DocX.csproj", "{E863D072-AA8B-4108-B5F1-785241B37F67}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DF41F5CE-8BCB-40CC-835F-54A3DB7D802F}"
ProjectSection(SolutionItems) = preProject
DocX.vsmdi = DocX.vsmdi
LocalTestRun.testrunconfig = LocalTestRun.testrunconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Examples\Examples.csproj", "{EF2E13CC-B36B-4B5A-AE73-78F5DDCA094E}"
EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 5
SccNumberOfProjects = 3
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://tfs08.codeplex.com/
SccLocalPath0 = .
SccProjectUniqueName1 = CustomPropertyTestApp\\CustomPropertyTestApp.csproj
SccProjectName1 = CustomPropertyTestApp
SccLocalPath1 = CustomPropertyTestApp
SccProjectUniqueName2 = DocX\\DocX.csproj
SccProjectName2 = DocX
SccLocalPath2 = DocX
SccProjectUniqueName3 = StringReplaceTestApp\\StringReplaceTestApp.csproj
SccProjectName3 = StringReplaceTestApp
SccLocalPath3 = StringReplaceTestApp
SccProjectUniqueName4 = UnitTests\\UnitTests.csproj
SccProjectName4 = UnitTests
SccLocalPath4 = UnitTests
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = DocX.vsmdi
SccProjectUniqueName1 = DocX\\DocX.csproj
SccProjectName1 = DocX
SccLocalPath1 = DocX
SccProjectUniqueName2 = Examples\\Examples.csproj
SccProjectName2 = Examples
SccLocalPath2 = Examples
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

+ 0
- 6
DocX.vsmdi ファイルの表示

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2006">
<TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
<RunConfiguration id="6869d4b0-c7c0-449b-a3b2-541bd9ae1155" name="Local Test Run" storage="localtestrun.testrunconfig" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, PublicKeyToken=b03f5f7f11d50a3a" />
</TestList>
</TestLists>

+ 2
- 2
DocX/Properties/AssemblyInfo.cs ファイルの表示

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
[assembly: AssemblyVersion("1.0.0.2")]
[assembly: AssemblyFileVersion("1.0.0.2")]

CustomPropertyTestApp/CustomPropertyTestApp.csproj → Examples/Examples.csproj ファイルの表示

@@ -5,11 +5,11 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9EABCAA8-175C-4FA2-9829-59E9D9E275D3}</ProjectGuid>
<ProjectGuid>{EF2E13CC-B36B-4B5A-AE73-78F5DDCA094E}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CustomPropertyTestApp</RootNamespace>
<AssemblyName>CustomPropertyTestApp</AssemblyName>
<RootNamespace>Examples</RootNamespace>
<AssemblyName>Examples</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
@@ -39,6 +39,7 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
@@ -53,9 +54,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Template.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Input\Image.docx" />
<None Include="Input\Template.docx" />
<None Include="Input\StringReplace.docx" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DocX\DocX.csproj">
@@ -63,6 +64,12 @@
<Name>DocX</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Input\Donkey.JPG" />
</ItemGroup>
<ItemGroup>
<Folder Include="Output\" />
</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.

CustomPropertyTestApp/CustomPropertyTestApp.csproj.vspscc → Examples/Examples.csproj.vspscc ファイルの表示


バイナリ
Examples/Input/Donkey.JPG ファイルの表示


バイナリ
Examples/Input/Image.docx ファイルの表示


StringReplaceTestApp/Test.docx → Examples/Input/StringReplace.docx ファイルの表示


CustomPropertyTestApp/Template.docx → Examples/Input/Template.docx ファイルの表示


+ 219
- 0
Examples/Program.cs ファイルの表示

@@ -0,0 +1,219 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Novacode;
using System.Text.RegularExpressions;
using System.Drawing;
namespace Examples
{
class Program
{
static void Main(string[] args)
{
StringReplaceExample();
CustomPropertiesExample();
CreateDocumentOnTheFly();
ImageExample1();
//ImageExample2();
}
private static void StringReplaceExample()
{
File.Copy(@"..\..\Input\StringReplace.docx", @"..\..\Output\StringReplace.docx", true);
// Load the document that you want to manipulate
DocX document = DocX.Load(@"..\..\Output\StringReplace.docx");
// Loop through the paragraphs in the document
foreach (Paragraph p in document.Paragraphs)
{
/*
* Replace each instance of the string pear with the string banana.
* Specifying true as the third argument informs DocX to track the
* changes made by this replace. The fourth argument tells DocX to
* ignore case when matching the string pear.
*/
p.Replace("pear", "banana", true, RegexOptions.IgnoreCase);
}
// File will be saved to ..\..\Output\
document.Save();
}
private static void CustomPropertiesExample()
{
// A list which contains three new users
List<User> newUsers = new List<User>
{
new User
{
forname = "John", username = "John87",
freeGift = "toaster", joined = DateTime.Now,
HomeAddress = "21 Hillview, Naas, Co. Kildare",
RecieveFurtherMail = true
},
new User
{
forname = "James", username = "KingJames",
freeGift = "kitchen knife", joined = DateTime.Now,
HomeAddress = "37 Mill Lane, Maynooth, Co. Meath",
RecieveFurtherMail = false
},
new User
{
forname = "Mary", username = "McNamara1",
freeGift = "microwave", joined = DateTime.Now,
HomeAddress = "110 Cherry Orchard Drive, Navan, Co. Roscommon", RecieveFurtherMail= true
}
};
// Foreach of the three new user create a welcome document based on template.docx
foreach (User newUser in newUsers)
{
// Copy template.docx so that we can customize it for this user
string filename = string.Format(@"..\..\Output\{0}.docx", newUser.username);
File.Copy(@"..\..\Input\Template.docx", filename, true);
/*
* Load the document to be manipulated and set the custom properties to this
* users specific data
*/
DocX doc = DocX.Load(filename);
doc.SetCustomProperty("Forname", CustomPropertyType.Text, newUser.forname);
doc.SetCustomProperty("Username", CustomPropertyType.Text, newUser.username);
doc.SetCustomProperty("FreeGift", CustomPropertyType.Text, newUser.freeGift);
doc.SetCustomProperty("HomeAddress", CustomPropertyType.Text, newUser.HomeAddress);
doc.SetCustomProperty("PleaseWaitNDays", CustomPropertyType.NumberInteger, 4);
doc.SetCustomProperty("GiftArrivalDate", CustomPropertyType.Date, newUser.joined.AddDays(4).ToUniversalTime());
doc.SetCustomProperty("RecieveFurtherMail", CustomPropertyType.YesOrNo, newUser.RecieveFurtherMail);
// File will be saved to ..\..\Output\
doc.Save();
doc.Dispose();
}
}
private static void CreateDocumentOnTheFly()
{
// Create a new .docx file
DocX d = DocX.Create(@"..\..\Output\Hello.docx");
// Add a new paragraph to this document
Paragraph one = d.AddParagraph();
one.Alignment = Alignment.both;
// Create a text formatting called f1
Formatting f1 = new Formatting();
f1.FontFamily = new FontFamily("Agency FB");
f1.Size = 28;
f1.Bold = true;
f1.FontColor = Color.RoyalBlue;
f1.UnderlineStyle = UnderlineStyle.doubleLine;
f1.UnderlineColor = Color.Red;
// Insert some new text, into the new paragraph, using the created formatting f1
one.Insert(0, "I've got style!", f1, false);
// Create a text formatting called f2
Formatting f2 = new Formatting();
f2.FontFamily = new FontFamily("Colonna MT");
f2.Size = 36.5;
f2.Italic = true;
f2.FontColor = Color.SeaGreen;
// Insert some new text, into the new paragraph, using the created formatting f2
one.Insert(one.Value.Length, " I have a different style.", f2, false);
// Save the document
d.Save();
d.Dispose();
}
private static void ImageExample1()
{
File.Copy(@"..\..\Input\Image.docx", @"..\..\Output\Image.docx", true);
// Load a .docx file
DocX document = DocX.Load(@"..\..\Output\Image.docx");
// Add an image to the docx file
Novacode.Image img = document.AddImage(@"..\..\Input\Donkey.jpg");
// Decide which paragraph to add the image to
Paragraph p = document.Paragraphs.Last();
#region pic1
// Create a picture, a picture is a customized view of an image
Picture pic1 = new Picture(img.Id, "Donkey", "Taken on Omey island");
// Set the pictures shape
pic1.SetPictureShape(BasicShapes.cube);
// Rotate the picture clockwise by 30 degrees
pic1.Rotation = 30;
// Insert the picture at the end of this paragraph
p.InsertPicture(pic1, p.Value.Length);
#endregion
#region pic2
// Create a picture, a picture is a customized view of an image
Picture pic2 = new Picture(img.Id, "Donkey", "Taken on Omey island");
// Set the pictures shape
pic2.SetPictureShape(CalloutShapes.cloudCallout);
// Flip the picture horizontal
pic2.FlipHorizontal = true;
// Insert the picture at the end of this paragraph
p.InsertPicture(pic2, p.Value.Length);
#endregion
// Save the docx file
document.Save();
document.Dispose();
}
private static void ImageExample2()
{
// Load the document that you want to manipulate
DocX document = DocX.Load(@"..\..\Output\Image.docx");
foreach (Paragraph p in document.Paragraphs)
{
foreach (Picture pi in p.Pictures)
{
pi.Rotation = 30;
}
}
// File will be saved to ..\..\Output\
document.Save();
document.Dispose();
}
}
// This class is used in the CustomPropertiesExample()
class User
{
public string forname, username, freeGift, HomeAddress;
public DateTime joined;
public bool RecieveFurtherMail;
public User()
{ }
}
}

StringReplaceTestApp/Properties/AssemblyInfo.cs → Examples/Properties/AssemblyInfo.cs ファイルの表示

@@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("StringReplaceTestApp")]
[assembly: AssemblyTitle("Examples")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft IT")]
[assembly: AssemblyProduct("StringReplaceTestApp")]
[assembly: AssemblyProduct("Examples")]
[assembly: AssemblyCopyright("Copyright © Microsoft IT 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3ec6b0e8-aceb-402b-ab0d-03201cc62865")]
[assembly: Guid("6ffd1827-4c08-4b2f-89fb-8ade88ac71f0")]
// Version information for an assembly consists of the following four values:
//

+ 0
- 17
LocalTestRun.testrunconfig ファイルの表示

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestRunConfiguration name="Local Test Run" id="6869d4b0-c7c0-449b-a3b2-541bd9ae1155" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2006">
<Description>This is a default test run configuration for a local test run.</Description>
<TestTypeSpecific>
<WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207">
<Browser name="Internet Explorer 7.0">
<Headers>
<Header name="User-Agent" value="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" />
<Header name="Accept" value="*/*" />
<Header name="Accept-Language" value="{{$IEAcceptLanguage}}" />
<Header name="Accept-Encoding" value="GZIP" />
</Headers>
</Browser>
<Network Name="LAN" BandwidthInKbps="0" />
</WebTestRunConfiguration>
</TestTypeSpecific>
</TestRunConfiguration>

+ 0
- 38
StringReplaceTestApp/Program.cs ファイルの表示

@@ -1,38 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Novacode;
using System.Text.RegularExpressions;
using System.IO;
using System.Xml.Linq;
namespace StringReplaceTestApp
{
class Program
{
static void Main(string[] args)
{
File.Copy(@"Test.docx", "Manipulated.docx", true);
// Load the document that you want to manipulate
DocX document = DocX.Load(@"Manipulated.docx");
// Loop through the paragraphs in the document
foreach (Paragraph p in document.Paragraphs)
{
/*
* Replace each instance of the string pear with the string banana.
* Specifying true as the third argument informs DocX to track the
* changes made by this replace. The fourth argument tells DocX to
* ignore case when matching the string pear.
*/
p.Replace("pear", "banana", true, RegexOptions.IgnoreCase);
}
// File will be saved to \StringReplaceTestApp\bin\Debug
document.Save();
}
}
}

+ 0
- 74
StringReplaceTestApp/StringReplaceTestApp.csproj ファイルの表示

@@ -1,74 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{EA960F96-7CA4-4AA1-BB43-0478E3407C5C}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>StringReplaceTestApp</RootNamespace>
<AssemblyName>StringReplaceTestApp</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</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">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Test.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DocX\DocX.csproj">
<Project>{E863D072-AA8B-4108-B5F1-785241B37F67}</Project>
<Name>DocX</Name>
</ProjectReference>
</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>

+ 0
- 10
StringReplaceTestApp/StringReplaceTestApp.csproj.vspscc ファイルの表示

@@ -1,10 +0,0 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}

+ 0
- 136
UnitTests/AuthoringTests.txt ファイルの表示

@@ -1,136 +0,0 @@
==========================================================================
Visual Studio Team System: Overview of Authoring and Running Tests
==========================================================================
This overview describes the features for authoring and running tests in
Visual Studio Team System and Visual Studio Team Edition for Software Testers.
Opening Tests
-------------
To open a test, open a test project or a test metadata file (a file with
extension .vsmdi) that contains the definition of the test. You can find
test projects and metadata files in Solution Explorer.
Viewing Tests
-------------
To see which tests are available to you, open the Test View window. Or,
if you have installed Team Edition for Software Testers, you can also open
the Test List Editor window to view tests.
To open the Test View window, click the Test menu, point to Windows, and
then click Test View. To open the Test List Editor window (if you have
installed Team Edition for Software Testers), click Test, point to Windows,
and then click Test List Editor.
Running Tests
-------------
You can run tests from the Test View window and the Test List Editor window.
See Viewing Tests to learn how to open these windows. To run one or more
tests displayed in the Test View window, first select the tests in that
window; to select multiple tests, hold either the Shift or CTRL key while
clicking tests. Then click the Run Tests button in the Test View window
toolbar.
If you have installed Visual Studio Team Edition for Software Testers, you can
also use the Test List Editor window to run tests. To run tests in Test List Editor,
select the check box next to each test that you want to run. Then click the
Run Tests button in the Test List Editor window toolbar.
Viewing Test Results
--------------------
When you run a test or a series of tests, the results of the test run will be
shown in the Test Results window. Each individual test in the run is shown on
a separate line so that you can see its status. The window contains an
embedded status bar in the top half of the window that provides you with
summary details of the complete test run.
To see more detailed results for a particular test result, double-click it in
the Test Results window. This opens a window that provides more information
about the particular test result, such as any specific error messages returned
by the test.
Changing the way that tests are run
-----------------------------------
Each time you run one or more tests, a collection of settings is used to
determine how those tests are run. These settings are contained in a “test
run configuration” file.
Here is a partial list of the changes you can make with a test run
configuration file:
- Change the naming scheme for each test run.
- Change the test controller that the tests are run on so that you can run
tests remotely.
- Gather code coverage data for the code being tested so that you can see
which lines of code are covered by your tests.
- Enable and disable test deployment.
- Specify additional files to deploy before tests are run.
- Select a different host, ASP.NET, for running ASP.NET unit tests.
- Select a different host, the smart device test host, for running smart device unit tests.
- Set various properties for the test agents that run your tests.
- Run custom scripts at the start and end of each test run so that you can
set up the test environment exactly as required each time tests are run.
- Set time limits for tests and test runs.
- Set the browser mix and the number of times to repeat Web tests in the
test run.
By default, a test run configuration file is created whenever you create a
new test project. You make changes to this file by double-clicking it in
Solution Explorer and then changing its settings. (Test run configuration
files have the extension .testrunconfig.)
A solution can contain multiple test run configuration files. Only one of
those files, known as the “Active” test run configuration file, is used to
determine the settings that are currently used for test runs. You select
the active test run configuration by clicking Select Active Test Run
Configuration on the Test menu.
-------------------------------------------------------------------------------
Test Types
----------
Using Visual Studio Team Edition for Software Testers, you can create a number
of different test types:
Unit test: Use a unit test to create a programmatic test in C++, Visual C# or
Visual Basic that exercises source code. A unit test calls the methods of a
class, passing suitable parameters, and verifies that the returned value is
what you expect.
There are three specialized variants of unit tests:
- Data-driven unit tests are created when you configure a unit test to be
called repeatedly for each row of a data source. The data from each row
is used by the unit test as input data.
- ASP.NET unit tests are unit tests that exercise code in an ASP.NET Web
application.
- Smart device unit tests are unit tests that are deployed to a smart device
or emulator and then executed by the smart device test host.
Web Test: Web tests consist of an ordered series of HTTP requests that you
record in a browser session using Microsoft Internet Explorer. You can have
the test report specific details about the pages or sites it requests, such
as whether a particular page contains a specified string.
Load Test: You use a load test to encapsulate non-manual tests, such as
unit, Web, and generic tests, and then run them simultaneously by using
virtual users. Running these tests under load generates test results,
including performance and other counters, in tables and in graphs.
Generic test: A generic test is an existing program wrapped to function as a
test in Visual Studio. The following are examples of tests or programs that
you can turn into generic tests:
- An existing test that uses process exit codes to communicate whether the
test passed or failed. 0 indicates passing and any other value indicates
a failure.
- A general program to obtain specific functionality during a test scenario.
- A test or program that uses a special XML file (called a “summary results
file”), to communicate detailed results.
Manual test: The manual test type is used when the test tasks are to be
completed by a test engineer as opposed to an automated script.
Ordered test: Use an ordered test to execute a set of tests in an order you
specify.
-------------------------------------------------------------------------------

+ 0
- 155
UnitTests/PreserveSpaceCheckTests.cs ファイルの表示

@@ -1,155 +0,0 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Novacode;
using System.Xml.Linq;
namespace UnitTests
{
/// <summary>
/// Summary description for PreserveSpaceCheckTests
/// </summary>
[TestClass]
public class PreserveSpaceTests
{
public PreserveSpaceTests()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void TestPreserveSpace_NoChangeRequired()
{
XElement t_origional, t_afterPreserveSpace;
#region Doesn't start or end with a space
// The test text element to check
t_origional = new XElement(DocX.w + "t", "Hello I am a string");
t_afterPreserveSpace = t_origional;
Text.PreserveSpace(t_afterPreserveSpace);
Assert.AreEqual(t_origional.ToString(), t_afterPreserveSpace.ToString());
#endregion
#region Starts with a space, doesn't end with a space
// The test text element to check
t_origional = new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), " Hello I am a string");
t_afterPreserveSpace = t_origional;
Text.PreserveSpace(t_afterPreserveSpace);
Assert.AreEqual(t_origional.ToString(), t_afterPreserveSpace.ToString());
#endregion
#region Ends with a space, doesn't start with a space
// The test text element to check
t_origional = new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), "Hello I am a string ");
t_afterPreserveSpace = t_origional;
Text.PreserveSpace(t_afterPreserveSpace);
Assert.AreEqual(t_origional.ToString(), t_afterPreserveSpace.ToString());
#endregion
#region Starts and ends with a space
// The test text element to check
t_origional = new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), " Hello I am a string ");
t_afterPreserveSpace = t_origional;
Text.PreserveSpace(t_afterPreserveSpace);
Assert.AreEqual(t_origional.ToString(), t_afterPreserveSpace.ToString());
#endregion
}
[TestMethod]
public void TestPreserveSpace_ChangeRequired()
{
XElement t_origional, t_afterPreserveSpace;
#region Doesn't start or end with a space, but has a space preserve attribute
// The test text element to check
t_origional = new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), "Hello I am a string");
t_afterPreserveSpace = t_origional;
Text.PreserveSpace(t_afterPreserveSpace);
Assert.AreEqual((new XElement(DocX.w + "t", "Hello I am a string")).ToString(), t_afterPreserveSpace.ToString());
#endregion
#region Start with a space, but has no space preserve attribute
// The test text element to check
t_origional = new XElement(DocX.w + "t", " Hello I am a string");
t_afterPreserveSpace = t_origional;
Text.PreserveSpace(t_afterPreserveSpace);
Assert.AreEqual((new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), " Hello I am a string")).ToString(), t_afterPreserveSpace.ToString());
#endregion
#region Ends with a space, but has no space preserve attribute
// The test text element to check
t_origional = new XElement(DocX.w + "t", "Hello I am a string ");
t_afterPreserveSpace = t_origional;
Text.PreserveSpace(t_afterPreserveSpace);
Assert.AreEqual((new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), "Hello I am a string ")).ToString(), t_afterPreserveSpace.ToString());
#endregion
#region Starts and ends with a space, but has no space preserve attribute
// The test text element to check
t_origional = new XElement(DocX.w + "t", " Hello I am a string ");
t_afterPreserveSpace = t_origional;
Text.PreserveSpace(t_afterPreserveSpace);
Assert.AreEqual((new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), " Hello I am a string ")).ToString(), t_afterPreserveSpace.ToString());
#endregion
}
[TestMethod, ExpectedException(typeof(ArgumentException))]
public void TestPreserveSpace_NotTOrDelTextElement()
{
XElement e = new XElement("NotTOrDelText");
Text.PreserveSpace(e);
}
}
}

+ 0
- 35
UnitTests/Properties/AssemblyInfo.cs ファイルの表示

@@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("UnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft IT")]
[assembly: AssemblyProduct("UnitTests")]
[assembly: AssemblyCopyright("Copyright © Microsoft IT 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM componenets. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ccefa1fd-d3c3-4130-b7ff-a6962dfc1a98")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

+ 0
- 192
UnitTests/SplitEditTests.cs ファイルの表示

@@ -1,192 +0,0 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml.Linq;
using Novacode;
namespace UnitTests
{
/// <summary>
/// Summary description for SplitEditTests
/// </summary>
[TestClass]
public class SplitEditTests
{
public SplitEditTests()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void TestSplitEdit()
{
// The test text element to split
XElement run1 = new XElement(DocX.w + "r", new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", "Hello"));
XElement run2 = new XElement(DocX.w + "r", new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), " world"));
XElement edit = new XElement(DocX.w + "ins", new XAttribute(DocX.w + "id", "0"), new XAttribute(DocX.w + "author", "t-cathco"), new XAttribute(DocX.w + "date", "2009-02-17T21:09:00Z"), run1, run2);
Paragraph p = new Paragraph(edit);
#region Split at index 0
XElement[] splitEdit = p.SplitEdit(edit, 0, EditType.del);
Assert.IsNull(splitEdit[0]);
Assert.AreEqual(edit.ToString(), splitEdit[1].ToString());
#endregion
#region Split at index 1
/*
* Split the text at index 5.
* This will cause the left side of the split to end with a space and the right to start with a space.
*/
XElement[] splitEdit_indexOne = p.SplitEdit(edit, 1, EditType.del);
// The result I expect to get from splitRun_nearMiddle
XElement splitEdit_indexOne_left = new XElement(DocX.w + "ins", new XAttribute(DocX.w + "id", "0"), new XAttribute(DocX.w + "author", "t-cathco"), new XAttribute(DocX.w + "date", "2009-02-17T21:09:00Z"), new XElement(DocX.w + "r", new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", "H")));
XElement splitEdit_indexOne_right = new XElement(DocX.w + "ins", new XAttribute(DocX.w + "id", "0"), new XAttribute(DocX.w + "author", "t-cathco"), new XAttribute(DocX.w + "date", "2009-02-17T21:09:00Z"), new XElement(DocX.w + "r",new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", "ello")), new XElement(DocX.w + "r", new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), " world")));
// Check if my expectations have been met
Assert.AreEqual(splitEdit_indexOne_left.ToString(), splitEdit_indexOne[0].ToString());
Assert.AreEqual(splitEdit_indexOne_right.ToString(), splitEdit_indexOne[1].ToString());
#endregion
#region Split near the middle
/*
* Split the text at index 5.
* This will cause the left side of the split to end with a space and the right to start with a space.
*/
XElement[] splitEdit_nearMiddle = p.SplitEdit(edit, 5, EditType.del);
// The result I expect to get from splitRun_nearMiddle
XElement splitEdit_nearMiddle_left = new XElement(DocX.w + "ins", new XAttribute(DocX.w + "id", "0"), new XAttribute(DocX.w + "author", "t-cathco"), new XAttribute(DocX.w + "date", "2009-02-17T21:09:00Z"), new XElement(DocX.w + "r", new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", "Hello")));
XElement splitEdit_nearMiddle_right = new XElement(DocX.w + "ins", new XAttribute(DocX.w + "id", "0"), new XAttribute(DocX.w + "author", "t-cathco"), new XAttribute(DocX.w + "date", "2009-02-17T21:09:00Z"), new XElement(DocX.w + "r", new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), " world")));
// Check if my expectations have been met
Assert.AreEqual(splitEdit_nearMiddle_left.ToString(), splitEdit_nearMiddle[0].ToString());
Assert.AreEqual(splitEdit_nearMiddle_right.ToString(), splitEdit_nearMiddle[1].ToString());
#endregion
#region Split at index Length - 1
/*
* Split the text at index 5.
* This will cause the left side of the split to end with a space and the right to start with a space.
*/
XElement[] splitEdit_indexOneFromLength = p.SplitEdit(edit, Paragraph.GetElementTextLength(edit) - 1, EditType.del);
// The result I expect to get from splitRun_nearMiddle
XElement splitEdit_OneFromLength_left = new XElement(DocX.w + "ins", new XAttribute(DocX.w + "id", "0"), new XAttribute(DocX.w + "author", "t-cathco"), new XAttribute(DocX.w + "date", "2009-02-17T21:09:00Z"), new XElement(DocX.w + "r", new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", "Hello")), new XElement(DocX.w + "r", new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), " worl")));
XElement splitEdit_OneFromLength_right = new XElement(DocX.w + "ins", new XAttribute(DocX.w + "id", "0"), new XAttribute(DocX.w + "author", "t-cathco"), new XAttribute(DocX.w + "date", "2009-02-17T21:09:00Z"), new XElement(DocX.w + "r", new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", "d")));
// Check if my expectations have been met
Assert.AreEqual(splitEdit_OneFromLength_left.ToString(), splitEdit_indexOneFromLength[0].ToString());
Assert.AreEqual(splitEdit_OneFromLength_right.ToString(), splitEdit_indexOneFromLength[1].ToString());
#endregion
#region Split at index Length
XElement[] splitEdit_indexZero = p.SplitEdit(edit, Paragraph.GetElementTextLength(edit), EditType.del);
Assert.AreEqual(edit.ToString(), splitEdit_indexZero[0].ToString());
Assert.IsNull(splitEdit_indexZero[1]);
#endregion
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestSplitEdit_IndexLessThanTextStartIndex()
{
// The test text element to split
XElement run1 = new XElement(DocX.w + "r", new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", "Hello"));
XElement run2 = new XElement(DocX.w + "r", new XElement(DocX.w + "rPr", new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0"))), new XElement(DocX.w + "t", new XAttribute(XNamespace.Xml + "space", "preserve"), " world"));
XElement edit = new XElement(DocX.w + "ins", new XAttribute(DocX.w + "id", "0"), new XAttribute(DocX.w + "author", "t-cathco"), new XAttribute(DocX.w + "date", "2009-02-17T21:09:00Z"), run1, run2);
Paragraph p = new Paragraph(edit);
/*
* Split r at a negative index.
* This will cause an argument out of range exception to be thrown.
*/
p.SplitEdit(edit, -1, EditType.del);
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestSplitEdit_IndexGreaterThanTextEndIndex()
{
// The test text element to split
XElement run1 = new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "t", "Hello") });
XElement run2 = new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "t", new object[] { new XAttribute(XNamespace.Xml + "space", "preserve"), " world" }) });
XElement edit = new XElement(DocX.w + "ins", new object[] { new XAttribute(DocX.w + "id", "0"), new XAttribute(DocX.w + "author", "t-cathco"), new XAttribute(DocX.w + "date", "2009-02-17T21:09:00Z"), run1, run2 });
Paragraph p = new Paragraph(edit);
/*
* Split r at a negative index.
* This will cause an argument out of range exception to be thrown.
*/
p.SplitEdit(edit, Paragraph.GetElementTextLength(edit) + 1, EditType.del);
}
[TestMethod]
public void TestSplitEditOfLengthOne()
{
XElement edit = new XElement(DocX.w + "ins", new object[] { new XAttribute(DocX.w + "id", "0"), new XAttribute(DocX.w + "author", "t-cathco"), new XAttribute(DocX.w + "date", "2009-02-17T21:09:00Z"), new XElement(DocX.w + "r", new XElement(DocX.w + "tab"))});
Paragraph p = new Paragraph(edit);
XElement[] splitEditOfLengthOne;
#region Split before
splitEditOfLengthOne = p.SplitEdit(edit, 0, EditType.del);
// Check if my expectations have been met
Assert.AreEqual(edit.ToString(), splitEditOfLengthOne[0].ToString());
Assert.IsNull(splitEditOfLengthOne[1]);
#endregion
#region Split after
splitEditOfLengthOne = p.SplitEdit(edit, Paragraph.GetElementTextLength(edit), EditType.del);
// Check if my expectations have been met
Assert.IsNull(splitEditOfLengthOne[0]);
Assert.AreEqual(edit.ToString(), splitEditOfLengthOne[1].ToString());
#endregion
}
}
}

+ 0
- 185
UnitTests/SplitRunTests.cs ファイルの表示

@@ -1,185 +0,0 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Novacode;
using System.Xml.Linq;
namespace UnitTests
{
/// <summary>
/// Summary description for SplitRunTests
/// </summary>
[TestClass]
public class SplitRunTests
{
public SplitRunTests()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void TestSplitRun()
{
// The test text element to split
Run r = new Run(0, new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "t", "Hello world") }));
#region Split at index 0
/*
* Split r at index 0.
* This will cause the left side of the split to be null and the right side to be equal to r.
*/
XElement[] splitRun_indexZero = Run.SplitRun(r, 0);
// Check if my expectations have been met
Assert.IsNull(splitRun_indexZero[0]);
Assert.AreEqual(r.Xml.ToString(), splitRun_indexZero[1].ToString());
#endregion
#region Split at index 1
XElement[] splitRun_indexOne = Run.SplitRun(r, 1);
// The result I expect to get from splitRun_indexOne
XElement splitRun_indexOne_left = new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "t", "H") });
XElement splitRun_indexOne_right = new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "t", "ello world") });
// Check if my expectations have been met
Assert.AreEqual(splitRun_indexOne_left.ToString(), splitRun_indexOne[0].ToString());
Assert.AreEqual(splitRun_indexOne_right.ToString(), splitRun_indexOne[1].ToString());
#endregion
#region Split near the middle
/*
* Split the text at index 11.
* This will cause the left side of the split to end with a space and the right to start with a space.
*/
XElement[] splitRun_nearMiddle = Run.SplitRun(r, 5);
// The result I expect to get from splitRun_nearMiddle
XElement splitRun_nearMiddle_left = new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "t", "Hello") });
XElement splitRun_nearMiddle_right = new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "t", new object[] { new XAttribute(XNamespace.Xml + "space", "preserve"), " world" }) });
// Check if my expectations have been met
Assert.AreEqual(splitRun_nearMiddle_left.ToString(), splitRun_nearMiddle[0].ToString());
Assert.AreEqual(splitRun_nearMiddle_right.ToString(), splitRun_nearMiddle[1].ToString());
#endregion
#region Split at index Length - 1
XElement[] splitRun_indexOneFromLength = Run.SplitRun(r, Paragraph.GetElementTextLength(r.Xml) - 1);
// The result I expect to get from splitRun_indexOne
XElement splitRun_indexOneFromLength_left = new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "t", "Hello worl") });
XElement splitRun_indexOneFromLength_right = new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "t", "d") });
// Check if my expectations have been met
Assert.AreEqual(splitRun_indexOneFromLength_left.ToString(), splitRun_indexOneFromLength[0].ToString());
Assert.AreEqual(splitRun_indexOneFromLength_right.ToString(), splitRun_indexOneFromLength[1].ToString());
#endregion
#region Split at index Length
/*
* Split r at index Length.
* This will cause the left side of the split to equal to r and the right side to be null.
*/
XElement[] splitRun_indexLength = Run.SplitRun(r, Paragraph.GetElementTextLength(r.Xml));
// Check if my expectations have been met
Assert.AreEqual(r.Xml.ToString(), splitRun_indexLength[0].ToString());
Assert.IsNull(splitRun_indexLength[1]);
#endregion
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestSplitRun_IndexLessThanTextStartIndex()
{
// The test text element to split
Run r = new Run(0, new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "t", "Hello world") }));
/*
* Split r at a negative index.
* This will cause an argument out of range exception to be thrown.
*/
Run.SplitRun(r, r.StartIndex - 1);
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestSplitRun_IndexGreaterThanTextEndIndex()
{
// The test text element to split
Run r = new Run(0, new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "t", "Hello world") }));
/*
* Split r at a length + 1.
* This will cause an argument out of range exception to be thrown.
*/
Run.SplitRun(r, r.EndIndex + 1);
}
[TestMethod]
public void TestSplitRunOfLengthOne()
{
// The test text element to split
Run r = new Run(0, new XElement(DocX.w + "r", new object[] { new XElement(DocX.w + "rPr", new object[] { new XElement(DocX.w + "b"), new XElement(DocX.w + "i"), new XElement(DocX.w + "color", new XAttribute(DocX.w + "val", "7030A0")) }), new XElement(DocX.w + "br") }));
XElement[] splitRunOfLengthOne;
#region Split before
splitRunOfLengthOne = Run.SplitRun(r, r.StartIndex);
// Check if my expectations have been met
Assert.AreEqual(r.Xml.ToString(), splitRunOfLengthOne[0].ToString());
Assert.IsNull(splitRunOfLengthOne[1]);
#endregion
#region Split after
splitRunOfLengthOne = Run.SplitRun(r, r.EndIndex);
// Check if my expectations have been met
Assert.IsNull(splitRunOfLengthOne[0]);
Assert.AreEqual(r.Xml.ToString(), splitRunOfLengthOne[1].ToString());
#endregion
}
}
}

+ 0
- 183
UnitTests/SplitTextTests.cs ファイルの表示

@@ -1,183 +0,0 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Novacode;
using System.Xml.Linq;
namespace UnitTests
{
/// <summary>
/// This class tests the SplitText function of Novacode.Paragraph
/// </summary>
[TestClass]
public class SplitTextTests
{
public SplitTextTests()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void TestSplitText()
{
// The test text element to split
Text t = new Text(0, new XElement(DocX.w + "t", "Hello I am a string"));
#region Split at index 0
/*
* Split t at index 0.
* This will cause the left side of the split to be null and the right side to be equal to t.
*/
XElement[] splitText_indexZero = Text.SplitText(t, 0);
// Check if my expectations have been met
Assert.IsNull(splitText_indexZero[0]);
Assert.AreEqual(t.Xml.ToString(), splitText_indexZero[1].ToString());
#endregion
#region Split at index 1
XElement[] splitText_indexOne = Text.SplitText(t, 1);
// The result I expect to get from splitText1
XElement splitText_indexOne_left = new XElement(DocX.w + "t", "H");
XElement splitText_indexOne_right = new XElement(DocX.w + "t", "ello I am a string");
// Check if my expectations have been met
Assert.AreEqual(splitText_indexOne_left.ToString(), splitText_indexOne[0].ToString());
Assert.AreEqual(splitText_indexOne_right.ToString(), splitText_indexOne[1].ToString());
#endregion
#region Split near the middle causing starting and ending spaces
/*
* Split the text at index 11.
* This will cause the left side of the split to end with a space and the right to start with a space.
*/
XElement[] splitText_nearMiddle = Text.SplitText(t, 11);
// The result I expect to get from splitText1
XElement splitText_nearMiddle_left = new XElement(DocX.w + "t", new object[] { new XAttribute(XNamespace.Xml + "space", "preserve"), "Hello I am " });
XElement splitText_nearMiddle_right = new XElement(DocX.w + "t", new object[] { new XAttribute(XNamespace.Xml + "space", "preserve"), " a string" });
// Check if my expectations have been met
Assert.AreEqual(splitText_nearMiddle_left.ToString(), splitText_nearMiddle[0].ToString());
Assert.AreEqual(splitText_nearMiddle_right.ToString(), splitText_nearMiddle[1].ToString());
#endregion
#region Split at text.Value.Length - 1
XElement[] splitText_indexOneFromLength = Text.SplitText(t, t.Value.Length - 1);
// The result I expect to get from splitText1
XElement splitText_indexOneFromLength_left = new XElement(DocX.w + "t", "Hello I am a strin");
XElement splitText_indexOneFromLength_right = new XElement(DocX.w + "t", "g");
// Check if my expectations have been met
Assert.AreEqual(splitText_indexOneFromLength_left.ToString(), splitText_indexOneFromLength[0].ToString());
Assert.AreEqual(splitText_indexOneFromLength_right.ToString(), splitText_indexOneFromLength[1].ToString());
#endregion
#region Split at index text.Value.Length
/*
* Split the text at index text.Value.Length.
* This will cause the left side of the split to be equal to text and the right side to be null.
*/
XElement[] splitText_indexLength = Text.SplitText(t, t.Value.Length);
// Check if my expectations have been met
Assert.AreEqual(t.Xml.ToString(), splitText_indexLength[0].ToString());
Assert.IsNull(splitText_indexLength[1]);
#endregion
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestSplitText_IndexLessThanTextStartIndex()
{
// The test text element to split
Text t = new Text(0, new XElement(DocX.w + "t", "Hello I am a string"));
/*
* Split t at a negative index.
* This will cause an argument out of range exception to be thrown.
*/
Text.SplitText(t, t.StartIndex - 1);
}
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestSplitText_IndexGreaterThanTextEndIndex()
{
// The test text element to split
Text t = new Text(0, new XElement(DocX.w + "t", "Hello I am a string"));
/*
* Split t at an index greater than its text length.
* This will cause an argument out of range exception to be thrown.
*/
Text.SplitText(t, t.EndIndex + 1);
}
[TestMethod]
public void TestSplitTextOfLengthOne()
{
// The test text element to split
Text t = new Text(0, new XElement(DocX.w + "tab"));
XElement[] splitTextOfLengthOne;
#region Split before
splitTextOfLengthOne = Text.SplitText(t, t.StartIndex);
// Check if my expectations have been met
Assert.AreEqual(t.Xml.ToString(), splitTextOfLengthOne[0].ToString());
Assert.IsNull(splitTextOfLengthOne[1]);
#endregion
#region Split after
splitTextOfLengthOne = Text.SplitText(t, t.EndIndex);
// Check if my expectations have been met
Assert.IsNull(splitTextOfLengthOne[0]);
Assert.AreEqual(t.Xml.ToString(), splitTextOfLengthOne[1].ToString());
#endregion
}
}
}

+ 0
- 70
UnitTests/UnitTests.csproj ファイルの表示

@@ -1,70 +0,0 @@
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6E4A2A95-9A9A-4F8C-A68D-4950E3455700}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>UnitTests</RootNamespace>
<AssemblyName>UnitTests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</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="DocX, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\DocX\bin\Debug\DocX.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.XML" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="PreserveSpaceCheckTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SplitEditTests.cs" />
<Compile Include="SplitRunTests.cs" />
<Compile Include="SplitTextTests.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="AuthoringTests.txt" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\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>

+ 0
- 10
UnitTests/UnitTests.csproj.vspscc ファイルの表示

@@ -1,10 +0,0 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}

読み込み中…
キャンセル
保存