-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathSampleTests.cs
182 lines (143 loc) · 6.08 KB
/
SampleTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
#if (ACAD2006 || ACAD2007 || ACAD2008 || ACAD2009|| ACAD2010|| ACAD2011 || ACAD2012)
using Autodesk.AutoCAD.ApplicationServices;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;
#else
using Autodesk.AutoCAD.ApplicationServices.Core;
using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
#endif
using Autodesk.AutoCAD.Geometry;
using CADtest.Helpers;
using NUnit.Framework;
using CADTestRunner;
using System.IO;
using System.Reflection;
namespace NUnitAutoCADTestRunner
{
[TestFixture, Apartment(ApartmentState.STA)]
public class TestClass1 : BaseTests
{
[Test]
public void Test_method_should_pass()
{
Assert.Pass("Test that should pass did not pass");
}
[Test]
public void Test_method_should_fail()
{
Assert.Fail("This test was supposed to fail.");
}
[Test]
public void Test_method_existing_drawing()
{
//Use existing drawing
string drawingPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Drawings", "DrawingTest.dwg");
long lineId = 526;
Action<Database, Transaction> action1 = (db, trans) =>
{
ObjectId objectId;
if (!db.TryGetObjectId(new Handle(lineId), out objectId))
{
Assert.Fail("ObjectID doesn't exist");
}
Line line = trans.GetObject(objectId, OpenMode.ForWrite) as Line;
Assert.IsNotNull(line, "Line didn't found");
line.Erase();
};
Action<Database, Transaction> action2 = (db, trans) =>
{
//Check in another transaction if the line was erased
ObjectId objectId;
if (db.TryGetObjectId(new Handle(lineId), out objectId))
{
Assert.IsTrue(objectId.IsErased, "Line didn't erased");
}
};
ExecuteActionDWG(drawingPath, action1, action2);
}
[Test]
public void Test_method_new_drawing()
{
//Use a new drawing
long lineId = 0;
Action<Database, Transaction> action1 = (db, trans) =>
{
Line line = new Line(new Point3d(0, 0, 0), new Point3d(100, 100, 100));
var blockTable = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
var modelSpace = (BlockTableRecord)trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
var objectId = modelSpace.AppendEntity(line);
trans.AddNewlyCreatedDBObject(line, true);
lineId = objectId.Handle.Value;
};
Action<Database, Transaction> action2 = (db, trans) =>
{
//Check in another transaction if the line was created
ObjectId objectId;
if (!db.TryGetObjectId(new Handle(lineId), out objectId))
{
Assert.Fail("Line didn't created");
}
};
ExecuteActionDWG(null, action1, action2);
}
[Test]
public void Test_method_name()
{
Action<Database, Transaction> action1 = (db, trans) =>
{
DBText dbText = new DBText { TextString = "cat" };
string testMe;
ObjectId dbTextObjectId = DbEntity.AddToModelSpace(dbText, db);
dbText.TextString = "dog";
DBText testText = trans.GetObject(dbTextObjectId, OpenMode.ForRead) as DBText;
testMe = testText != null ? testText.TextString : string.Empty;
// Assert
StringAssert.AreEqualIgnoringCase("dog", testMe, "DBText string was not changed to \"dog\".");
StringAssert.AreNotEqualIgnoringCase("cat", testMe, "DBText string was not changed.");
};
ExecuteActionDWG(null, action1);
}
[Test]
public void Old_Test_That_Used_to_Crash_2016_and_not_2013_but_I_fixed_it()
{
// Arrange
Database db = HostApplicationServices.WorkingDatabase;
Document doc = Application.DocumentManager.GetDocument(db);
string testMe;
// Act
using (doc.LockDocument())
{
using (var tx = db.TransactionManager.StartTransaction())
{
using (DBText dbText = new DBText { TextString = "cat" })
{
ObjectId dbTextObjectId = DbEntity.AddToModelSpace(dbText, db);
dbText.TextString = "dog";
var testText = dbTextObjectId.Open(OpenMode.ForRead, false) as DBText;
testMe = testText != null
? testText.TextString
: string.Empty;
}
tx.Commit();
}
}
// Assert
StringAssert.AreEqualIgnoringCase("dog", testMe, "DBText string was not changed to \"dog\".");
StringAssert.AreNotEqualIgnoringCase("cat", testMe, "DBText string was not changed.");
}
[Test, TestCaseSource(typeof(SampleTestsData), "ParametersTest")]
public void Test_method_TestCaseSource(Point3d pPoint1, Point3d pPoint2, Point3d pPointResult)
{
List<Point3d> listPoints = new List<Point3d> (){pPoint1, pPoint2};
Point3d centerPoint = new Point3d(listPoints.Average(p => p.X), listPoints.Average(p => p.Y), listPoints.Average(p => p.Z));
Assert.IsTrue(centerPoint.DistanceTo(pPointResult) < 1E-5);
}
}
}