Skip to content

Commit 1a4bd3b

Browse files
committed
Fixed a couple bugs, added a couple new config parameters
1 parent 441817e commit 1a4bd3b

11 files changed

Lines changed: 169 additions & 94 deletions

File tree

DotNetTestGenerationTools.sln

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
4-
VisualStudioVersion = 17.14.36121.58 d17.14
4+
VisualStudioVersion = 17.14.36121.58
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "DotNetTestGenerator", "UnitTestGen\DotNetTestGenerator.vbproj", "{C8DBB491-9393-4322-A324-E8B12235B164}"
77
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHub", "GitHub", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
9+
ProjectSection(SolutionItems) = preProject
10+
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
11+
EndProjectSection
12+
EndProject
13+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Info", "Info", "{A83B6719-E05A-44AD-A67E-F2AC49583B36}"
14+
ProjectSection(SolutionItems) = preProject
15+
LICENSE = LICENSE
16+
README.md = README.md
17+
EndProjectSection
18+
EndProject
19+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Git", "Git", "{BEF18182-34AC-4CEA-AB73-DA0C5BD2F31E}"
20+
ProjectSection(SolutionItems) = preProject
21+
.gitattributes = .gitattributes
22+
.gitignore = .gitignore
23+
EndProjectSection
24+
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestDotNetTestGeneratorCS", "TestDotNetTestGeneratorCS\TestDotNetTestGeneratorCS.csproj", "{F18B99DD-96A3-3E8A-63D3-F7BBEE0BF1BF}"
26+
EndProject
827
Global
928
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1029
Debug|Any CPU = Debug|Any CPU
@@ -15,8 +34,15 @@ Global
1534
{C8DBB491-9393-4322-A324-E8B12235B164}.Debug|Any CPU.Build.0 = Debug|Any CPU
1635
{C8DBB491-9393-4322-A324-E8B12235B164}.Release|Any CPU.ActiveCfg = Release|Any CPU
1736
{C8DBB491-9393-4322-A324-E8B12235B164}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{F18B99DD-96A3-3E8A-63D3-F7BBEE0BF1BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{F18B99DD-96A3-3E8A-63D3-F7BBEE0BF1BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{F18B99DD-96A3-3E8A-63D3-F7BBEE0BF1BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{F18B99DD-96A3-3E8A-63D3-F7BBEE0BF1BF}.Release|Any CPU.Build.0 = Release|Any CPU
1841
EndGlobalSection
1942
GlobalSection(SolutionProperties) = preSolution
2043
HideSolutionNode = FALSE
2144
EndGlobalSection
45+
GlobalSection(ExtensibilityGlobals) = postSolution
46+
SolutionGuid = {DD5C8F64-8989-4DFB-8B20-C5DACD232C5B}
47+
EndGlobalSection
2248
EndGlobal

UnitTestGen/Configuration/UnitTestGen/general.xml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<UnitTestGen>
4+
<ProjectOutputAssemblyExtension>.dll</ProjectOutputAssemblyExtension>
5+
46
<ShowAllHiddenItems>false</ShowAllHiddenItems>
57

68
<ShowHiddenMethods>false</ShowHiddenMethods>
@@ -10,6 +12,18 @@
1012
<HiddenMethod>_Lambda$__6-0</HiddenMethod>
1113
<HiddenMethod>_Lambda$__5-0</HiddenMethod>
1214
<HiddenMethod>_Lambda$__2-0</HiddenMethod>
15+
<HiddenMethod>_Lambda$__26-0</HiddenMethod>
16+
<HiddenMethod>_Lambda$__30-0</HiddenMethod>
17+
<HiddenMethod>_Lambda$__30-2</HiddenMethod>
18+
<HiddenMethod>_Lambda$__30-3</HiddenMethod>
19+
<HiddenMethod>_Lambda$__31-1</HiddenMethod>
20+
<HiddenMethod>_Lambda$__31-2</HiddenMethod>
21+
<HiddenMethod>_Lambda$__35-0</HiddenMethod>
22+
<HiddenMethod>_Lambda$__8-10</HiddenMethod>
23+
<HiddenMethod>_Lambda$__8-12</HiddenMethod>
24+
<HiddenMethod>_Lambda$__8-14</HiddenMethod>
25+
<HiddenMethod>_Lambda$__112-0</HiddenMethod>
26+
<HiddenMethod>_Lambda$__130-0</HiddenMethod>
1327
<HiddenMethod>_Lambda$__45-0</HiddenMethod>
1428
<HiddenMethod>Finalize</HiddenMethod>
1529
</HiddenMethods>
@@ -33,11 +47,12 @@
3347
<SkipObsolete>true</SkipObsolete>
3448

3549
<DefaultOutputDirectory>C:\Tests</DefaultOutputDirectory>
50+
<OmitContainerDirectory>false</OmitContainerDirectory>
3651
<SetOutputDirectoryToDefaultOnStartup>false</SetOutputDirectoryToDefaultOnStartup>
3752

3853
<EnableAllTestGenerationOptions>true</EnableAllTestGenerationOptions>
39-
<UseFullNamespace>false</UseFullNamespace>
40-
<RelativeNamespacePrepend>Common.</RelativeNamespacePrepend>
54+
<UseFullNamespace>true</UseFullNamespace>
55+
<RelativeNamespacePrepend></RelativeNamespacePrepend>
4156
<RelativeNamespaceAppend></RelativeNamespaceAppend>
4257
<GenerateScaffolding>true</GenerateScaffolding>
4358
<GenerateExampleUserTestCase>true</GenerateExampleUserTestCase>

UnitTestGen/Controllers/TestGenGeneratorController.vb

Lines changed: 82 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
Imports System.Drawing
12
Imports System.IO
3+
Imports System.ServiceModel.Channels
24
Imports System.Text.RegularExpressions
35
Imports System.Windows.Forms
46
Imports System.Xml
@@ -15,9 +17,9 @@ Imports Org.Hsf.Tooling.CodeGen.Views.GenTree
1517
Imports Org.Hsf.Utility.Core.Configuration
1618
Imports Org.Hsf.Utility.Core.Logging
1719
Imports Org.Hsf.Utility.Core.Memory
20+
Imports Org.Hsf.Utility.Visuals.Core
1821

1922
Namespace Controllers
20-
2123
Public Class TestGenGeneratorController
2224
Implements IDisposable
2325

@@ -90,7 +92,7 @@ Namespace Controllers
9092
''' </summary>
9193
''' <param name="view"></param>
9294
''' <param name="project">The project file that is driving this </param>
93-
Protected Friend Sub New(view As TreeView, project As FileInfo)
95+
Sub New(view As TreeView, project As FileInfo)
9496
_config = ConfigSelector.GetLoadedConfig(Of UnitTestGen)(
9597
"UnitTestGen"
9698
)
@@ -99,22 +101,54 @@ Namespace Controllers
99101
_projectFile = project
100102
End Sub
101103

104+
Private Sub CreateProgressDialog()
105+
Dim pLoc As Point = _trvNodesContainer.Parent.Location
106+
Dim pSize As Size = _trvNodesContainer.Parent.Size
107+
_progressDialog = New GenerationProgressDialogView() With {
108+
.StartPosition = FormStartPosition.Manual,
109+
.Location = New Point(
110+
CType(Math.Floor((pLoc.X + (pSize.Width / 2)) - (.Size.Width / 2)), Integer),
111+
CType(Math.Floor((pLoc.Y + (pSize.Height / 2)) - (.Size.Height / 2)), Integer)
112+
)
113+
}
114+
End Sub
115+
116+
Friend Shared Sub ProgressWriteGenAction(pd As GenerationProgressDialogView, message As String)
117+
pd.Invoke(Sub()
118+
pd.lblGenAction.Text = message
119+
pd.Refresh()
120+
End Sub)
121+
End Sub
122+
123+
Friend Shared Sub ProgressWriteCurGenItm(pd As GenerationProgressDialogView, message As String)
124+
pd.Invoke(Sub()
125+
pd.lblCurrentlyGeneratingItem.Text = message
126+
pd.Refresh()
127+
End Sub)
128+
End Sub
129+
102130
''' <summary>
103131
'''
104132
''' </summary>
105133
''' <param name="outputDir"></param>
106134
Protected Friend Sub GenerateForAllItems(outputDir As String, lang As String)
107135
_language = lang
108-
_progressDialog = New GenerationProgressDialogView()
109-
'FIXME TreeViewUtils.CheckAllCheckboxesInSubTree(_trvNodesContainer.TopNode)
136+
137+
CreateProgressDialog()
138+
139+
_trvNodesContainer.Invoke(Sub() TreeViewUtils.CheckAllCheckboxesInSubTree(_trvNodesContainer.TopNode))
110140

111141
Task.Run(
112142
Sub()
113-
Dim items As List(Of TypeTreeNode) = _trvNodesContainer.Nodes.OfType(Of AssemblyTreeNode)().
114-
SelectMany(FlattenSelector).
115-
Where(_typeNodeTypeFilter).
116-
OfType(Of TypeTreeNode)().
117-
ToList()
143+
Dim items As List(Of TypeTreeNode) = _trvNodesContainer.Invoke(
144+
Function()
145+
Return _trvNodesContainer.Nodes.OfType(Of AssemblyTreeNode)().
146+
SelectMany(FlattenSelector).
147+
Where(_typeNodeTypeFilter).
148+
OfType(Of TypeTreeNode)().
149+
ToList()
150+
End Function
151+
)
118152

119153
GenerateForItems(outputDir, items)
120154

@@ -133,16 +167,21 @@ Namespace Controllers
133167

134168
Friend Sub GenerateForCheckedItems(outputDir As String, lang As String)
135169
_language = lang
136-
_progressDialog = New GenerationProgressDialogView()
170+
171+
CreateProgressDialog()
137172

138173
Task.Run(
139174
Sub()
140-
Dim items As List(Of TypeTreeNode) = _trvNodesContainer.Nodes.OfType(Of AssemblyTreeNode)().
141-
SelectMany(FlattenSelector).
142-
Where(_typeNodeTypeFilter).
143-
Where(_selectedFilter).
144-
OfType(Of TypeTreeNode)().
145-
ToList()
175+
Dim items As List(Of TypeTreeNode) = _trvNodesContainer.Invoke(
176+
Function()
177+
Return _trvNodesContainer.Nodes.OfType(Of AssemblyTreeNode)().
178+
SelectMany(FlattenSelector).
179+
Where(_typeNodeTypeFilter).
180+
Where(_selectedFilter).
181+
OfType(Of TypeTreeNode)().
182+
ToList()
183+
End Function
184+
)
146185

147186
GenerateForItems(outputDir, items)
148187

@@ -167,22 +206,15 @@ Namespace Controllers
167206
Sub GenerateForItems(outputDir As String, items As List(Of TypeTreeNode))
168207
generator = SyntaxGenerator.GetGenerator(genWorkspace, _language)
169208

170-
_progressDialog.Invoke(Sub() _progressDialog.lblGenAction.Text =
171-
"Generating namespace and assembly structure in output directory " &
172-
outputDir)
173-
174-
GenAssemblyDirectories(outputDir)
175-
176209
Dim compilationUnits As New Dictionary(Of Type, SyntaxNode)()
177210

178-
Dim TEST_GEN_PREFIX As String = "Generating tests"
179-
_progressDialog.Invoke(Sub() _progressDialog.lblGenAction.Text = TEST_GEN_PREFIX)
180-
_progressDialog.Invoke(Sub() _progressDialog.lblCurrentlyGeneratingItem.Text = "Loading...")
211+
ProgressWriteGenAction(_progressDialog, "Generating tests")
212+
ProgressWriteCurGenItm(_progressDialog, "Loading...")
213+
181214
_trvNodesContainer.Invoke(
182215
Sub()
183216
For Each typeNode As TypeTreeNode In items
184-
_progressDialog.Invoke(Sub() _progressDialog.lblGenAction.Text = TEST_GEN_PREFIX &
185-
$" for class under test: {typeNode.codeGenType.FullName}")
217+
ProgressWriteGenAction(_progressDialog, $"Generating tests for type under test: {typeNode.codeGenType.FullName}")
186218

187219
logger.Info($"Generating tests for type {typeNode.codeGenType.FullName}")
188220
compilationUnits.Add(typeNode.codeGenType, GenerateCodeForType(typeNode))
@@ -194,8 +226,17 @@ Namespace Controllers
194226
End Sub
195227

196228
Sub WriteCompilationUnits(outputDir As String, compilationUnits As Dictionary(Of Type, SyntaxNode))
197-
Dim asmOut As String = $"{outputDir}{Path.DirectorySeparatorChar}{_projectFile.Name.Replace(_projectFile.Extension, "")}"
198-
Dim asmOutDir As DirectoryInfo = Directory.CreateDirectory(asmOut)
229+
Dim asmOut As String
230+
Dim asmOutDir As DirectoryInfo
231+
232+
If Not _config.OmitContainerDirectory Then
233+
asmOut = $"{outputDir}{Path.DirectorySeparatorChar}{_projectFile.Name.Replace(_projectFile.Extension, "")}"
234+
asmOutDir = Directory.CreateDirectory(asmOut)
235+
236+
Else
237+
asmOut = outputDir
238+
asmOutDir = New DirectoryInfo(asmOut)
239+
End If
199240

200241
If Not asmOutDir.Exists Then
201242
Throw New DirectoryNotFoundException($"Could not create directory {asmOut}!")
@@ -208,9 +249,7 @@ Namespace Controllers
208249
Continue For
209250
End If
210251

211-
_progressDialog.Invoke(Sub() _progressDialog.lblGenAction.Text =
212-
"Generating namespace and assembly structure in output directory " &
213-
outputDir)
252+
ProgressWriteGenAction(_progressDialog, $"Generating namespace and assembly structure in output directory {outputDir}")
214253

215254
Dim cuRawTypeName As String = compilationUnit.Key.Name
216255
Dim cuTypeName As String = Regex.Replace(
@@ -239,21 +278,19 @@ Namespace Controllers
239278
Dim cuNamespace As String = compilationUnit.Key.Namespace.Replace($"{rootNs}.", "")
240279
Dim cuSubdir As String = cuNamespace.Replace("."c, Path.DirectorySeparatorChar)
241280

242-
_progressDialog.Invoke(Sub() _progressDialog.lblCurrentlyGeneratingItem.Text =
243-
$"Creating directory {asmOut}{Path.DirectorySeparatorChar}{cuSubdir}" &
244-
$" for generated test unit {fileName}")
281+
ProgressWriteCurGenItm(_progressDialog, $"Creating directory {asmOut}{Path.DirectorySeparatorChar}{cuSubdir}" &
282+
$" for generated test unit {fileName}")
245283

246284
Dim cuOutDir As DirectoryInfo = asmOutDir.CreateSubdirectory(cuSubdir)
247285
Dim cuFullPath As String = Path.Combine(cuOutDir.FullName, fileName)
248286

249287
Using cuWriter As New StreamWriter(cuFullPath)
250-
251-
_progressDialog.Invoke(Sub() _progressDialog.lblGenAction.Text =
252-
$"Writing generated test compilation unit")
253-
_progressDialog.Invoke(Sub() _progressDialog.lblCurrentlyGeneratingItem.Text =
254-
cuFullPath)
288+
ProgressWriteGenAction(_progressDialog, "Writing generated test compilation unit")
289+
ProgressWriteCurGenItm(_progressDialog, cuFullPath)
255290

256291
compilationUnit.Value.WriteTo(cuWriter)
292+
293+
ProgressWriteGenAction(_progressDialog, "Wrote generated test compilation unit")
257294
End Using
258295
Next
259296
End Sub
@@ -271,41 +308,27 @@ Namespace Controllers
271308

272309
Dim cuNodes As List(Of SyntaxNode)
273310
If genTypeUnderTest.IsClass Then
311+
ProgressWriteCurGenItm(_progressDialog, $"Generating tests for class {genTypeUnderTest.FullName}")
274312
cuNodes = codeGenerator.GenerateCodeForClass(selectedTestGenItem, genTypeUnderTest)
313+
ProgressWriteCurGenItm(_progressDialog, $"Done generating tests for class {genTypeUnderTest.FullName}")
275314

276315
ElseIf genTypeUnderTest.IsEnum Then
316+
ProgressWriteCurGenItm(_progressDialog, $"Generating tests for enum {genTypeUnderTest.FullName}")
277317
cuNodes = codeGenerator.GenerateCodeForEnum(selectedTestGenItem, genTypeUnderTest)
318+
ProgressWriteCurGenItm(_progressDialog, $"Done generating tests for enum {genTypeUnderTest.FullName}")
278319

279320
ElseIf genTypeUnderTest.IsValueType Then
280321
logger.Warn($"Skipping value type {genTypeUnderTest.FullName};" &
281322
" please manually implement one-or-more tests for this type!")
282323
Return Nothing
324+
283325
Else
284326
Throw New NotSupportedException($"The type of {genTypeUnderTest.FullName} is not supported!")
285327
End If
286328

287329
Return generator.CompilationUnit(cuNodes).NormalizeWhitespace()
288330
End Function
289331

290-
Sub GenAssemblyDirectories(outputDir As String)
291-
Dim asmNodes As IEnumerable(Of CodeGenTreeNode) = _trvNodesContainer.Nodes.OfType(Of CodeGenTreeNode)().
292-
SelectMany(FlattenSelector).
293-
Where(_asmNodeTypeFilter)
294-
295-
For Each asmNode As CodeGenTreeNode In asmNodes
296-
Dim asmSimpleName As String = asmNode.Text.Split(separator, StringSplitOptions.RemoveEmptyEntries)(0)
297-
Dim asmOutDirStr As String = $"{outputDir}{Path.DirectorySeparatorChar}{asmSimpleName}"
298-
299-
_progressDialog.Invoke(Sub() _progressDialog.lblCurrentlyGeneratingItem.Text =
300-
$"Creating directory {asmOutDirStr} for assembly {asmSimpleName}")
301-
302-
Dim asmOutDir As DirectoryInfo = Directory.CreateDirectory(asmOutDirStr)
303-
If Not asmOutDir.Exists Then
304-
Throw New InvalidOperationException($"Failed to create Assembly-based test output directory {asmOutDirStr}")
305-
End If
306-
Next
307-
End Sub
308-
309332
Private Property disposed As Boolean
310333

311334
Public Sub Dispose() Implements IDisposable.Dispose

UnitTestGen/Controllers/TestGenInitController.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Namespace Controllers
8888
),
8989
New KeyValuePair(Of String(), String)(
9090
{"-A", "--set-output-directory-automatically-on-start"},
91-
"The output directory to use for generated artifacts."
91+
"Whether to automatically set an output directory for you."
9292
)
9393
),
9494
Nothing

UnitTestGen/Controllers/TestGenTreeController.vb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ Namespace Controllers
106106
Dim lProjectDirectory As DirectoryInfo
107107

108108
Dim projectSearchQuery As String = $"{project}"
109+
If Not String.IsNullOrWhiteSpace(_config.ProjectOutputAssemblyExtension) Then
110+
projectSearchQuery = $"{projectSearchQuery}{_config.ProjectOutputAssemblyExtension}"
111+
End If
109112

110113
If String.CompareOrdinal(_buildConfiguration, "*") = 0 Then
111114
lProjectDirectory = projectDirectory

0 commit comments

Comments
 (0)