Skip to content

Commit 3f3886a

Browse files
committed
New XUnit tests
1 parent aee5c6b commit 3f3886a

File tree

212 files changed

+160861
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+160861
-95
lines changed

DocumentFormat.OpenXml.Tests/BaseFixture.cs

+6-13
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,7 @@
3030
using DocumentFormat.OpenXml.Packaging;
3131
using Xunit;
3232

33-
// to run the X64 tests:
34-
// packages\xunit.runner.console.2.0.0\tools\xunit.console DocumentFormat.OpenXml.Tests.64\bin\Debug\DocumentFormat.OpenXml.Tests.dll
35-
36-
#if X64
37-
namespace DocumentFormat.OpenXml.Tests.X64
38-
#else
3933
namespace DocumentFormat.OpenXml.Tests
40-
#endif
4134
{
4235
[SuppressMessage("ReSharper", "UnusedMember.Global")]
4336
[SuppressMessage("ReSharper", "VirtualMemberNeverOverriden.Global")]
@@ -165,12 +158,12 @@ protected static void PrepareWordprocessingDocument(string path)
165158
}
166159
}
167160

168-
protected static void RemoveFiles(string path, string searchPattern)
169-
{
170-
var directory = new DirectoryInfo(path);
171-
foreach (var file in directory.GetFiles(searchPattern))
172-
file.Delete();
173-
}
161+
//protected static void RemoveFiles(string path, string searchPattern)
162+
//{
163+
// var directory = new DirectoryInfo(path);
164+
// foreach (var file in directory.GetFiles(searchPattern))
165+
// file.Delete();
166+
//}
174167

175168
public void Dispose()
176169
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Runtime.CompilerServices;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace DocumentFormat.OpenXml.Tests
10+
{
11+
public class TestContext
12+
{
13+
public TestContext(string currentTest)
14+
{
15+
this.TestName = currentTest;
16+
this.FullyQualifiedTestClassName = currentTest;
17+
}
18+
19+
public string TestName
20+
{
21+
get;
22+
set;
23+
}
24+
25+
public string FullyQualifiedTestClassName
26+
{
27+
get;
28+
set;
29+
}
30+
31+
[MethodImpl(MethodImplOptions.NoInlining)]
32+
public static string GetCurrentMethod()
33+
{
34+
StackTrace st = new StackTrace();
35+
StackFrame sf = st.GetFrame(1);
36+
37+
return sf.GetMethod().Name;
38+
}
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace DocumentFormat.OpenXml.Tests.ChartTrackingRefBased
7+
{
8+
using Xunit;
9+
using DocumentFormat.OpenXml.Tests.TaskLibraries;
10+
using DocumentFormat.OpenXml.Tests.ChartTrackingRefBasedClass;
11+
12+
public class ChartTrackingRefBasedTest : OpenXmlTestBase
13+
{
14+
private readonly string generateDocumentFile = "TestChartTrackingRefBasedBase.pptx";
15+
private readonly string editDocumentFile = "EditedChartTrackingRefBased.pptx";
16+
private readonly string deleteDocumentFile = "DeletedChartTrackingRefBased.pptx";
17+
private readonly string addDocumentFile = "AddedChartTrackingRefBased.pptx";
18+
19+
private TestEntities testEntities = null;
20+
21+
#region Constructor
22+
/// <summary>
23+
/// Constructor
24+
/// </summary>
25+
public ChartTrackingRefBasedTest()
26+
{
27+
// Set the flag to notify MSTest of Ots Log failure
28+
this.OtsLogFailureToFailTest = true;
29+
}
30+
#endregion
31+
32+
#region Initialize
33+
/// <summary>
34+
/// Creates a base Power Point file for the tests
35+
/// </summary>
36+
/// <param name="createFilePath">Create Power Point file path</param>
37+
private void Initialize(string createFilePath)
38+
{
39+
try
40+
{
41+
GeneratedDocument generatedDocument = new GeneratedDocument();
42+
generatedDocument.CreatePackage(createFilePath);
43+
44+
this.testEntities = new TestEntities(createFilePath);
45+
}
46+
catch (Exception e)
47+
{
48+
this.Log.Fail(string.Format(e.Message + ". :File path={0}", createFilePath));
49+
}
50+
}
51+
#endregion
52+
53+
#region Test Methods
54+
/// <summary>
55+
/// Creates a base Power Point file for the tests
56+
/// </summary>
57+
protected override void TestInitializeOnce()
58+
{
59+
string generatDocumentFilePath = this.GetTestFilePath(this.generateDocumentFile);
60+
61+
Initialize(generatDocumentFilePath);
62+
}
63+
64+
/// <summary>
65+
/// Element editing test of ChartTrackingRefBased
66+
/// </summary>
67+
[Fact]
68+
public void ChartTrackingRefBasedTest01()
69+
{
70+
this.MyTestInitialize(TestContext.GetCurrentMethod());
71+
try
72+
{
73+
string originalFilepath = this.GetTestFilePath(this.generateDocumentFile);
74+
string editFilePath = this.GetTestFilePath(this.editDocumentFile);
75+
76+
System.IO.File.Copy(originalFilepath, editFilePath, true);
77+
78+
this.testEntities.EditElements(editFilePath, this.Log);
79+
this.testEntities.VerifyElements(editFilePath, this.Log);
80+
}
81+
catch (Exception e)
82+
{
83+
this.Log.Fail(e.Message);
84+
}
85+
}
86+
87+
/// <summary>
88+
/// Element deleting test of ChartTrackingRefBased
89+
/// </summary>
90+
[Fact]
91+
public void ChartTrackingRefBasedTest03DeleteElement()
92+
{
93+
this.MyTestInitialize(TestContext.GetCurrentMethod());
94+
try
95+
{
96+
string originalFilepath = this.GetTestFilePath(this.generateDocumentFile);
97+
string deleteFilePath = this.GetTestFilePath(this.deleteDocumentFile);
98+
string addFilePath = this.GetTestFilePath(this.addDocumentFile);
99+
100+
System.IO.File.Copy(originalFilepath, deleteFilePath, true);
101+
this.Log.Comment("File copy [{0}] to [{1}]", originalFilepath, deleteFilePath);
102+
103+
this.testEntities.DeleteElements(deleteFilePath, this.Log);
104+
this.testEntities.VerifyDeleteElements(deleteFilePath, this.Log);
105+
106+
System.IO.File.Copy(deleteFilePath, addFilePath, true);
107+
this.Log.Comment("File copy [{0}] to [{1}]", originalFilepath, deleteFilePath);
108+
109+
this.testEntities.AddElements(addFilePath, this.Log);
110+
this.testEntities.VerifyAddElements(addFilePath, this.Log);
111+
112+
this.Log.Pass("Element deletion is complete.");
113+
}
114+
catch (Exception e)
115+
{
116+
this.Log.Fail(e.Message);
117+
}
118+
}
119+
120+
#endregion
121+
}
122+
}

0 commit comments

Comments
 (0)